Skip to content

Commit 829a3f1

Browse files
authored
[SYCL] Don't generate optional string metadata node for aliasing MD (#20478)
It was added just for LLVM IR readability during inlining, encoding original function name. We don't translate it to SPIR-V anyway. Meanwhile, since SYCL function names can be quite big - appearence of the string MD slightly worsen compilation performance, especially during module split. --------- Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
1 parent fcf67a9 commit 829a3f1

File tree

3 files changed

+157
-9
lines changed

3 files changed

+157
-9
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,19 +1143,31 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap,
11431143
DenseMap<const Argument *, MDNode *> NewScopes;
11441144
MDBuilder MDB(CalledFunc->getContext());
11451145

1146+
// For spir/spirv targets, disable function name encoding
1147+
// in alias metadata to reduce metadata bloat and improve compilation
1148+
// performance.
1149+
const Module *M = CalledFunc->getParent();
1150+
const auto Arch = M->getTargetTriple().getArch();
1151+
const bool IsSPIRModule =
1152+
Arch == Triple::ArchType::spir || Arch == Triple::ArchType::spir64 ||
1153+
Arch == Triple::ArchType::spirv || Arch == Triple::ArchType::spirv64;
1154+
11461155
// Create a new scope domain for this function.
1147-
MDNode *NewDomain =
1148-
MDB.createAnonymousAliasScopeDomain(CalledFunc->getName());
1156+
MDNode *NewDomain = MDB.createAnonymousAliasScopeDomain(
1157+
IsSPIRModule ? StringRef() : CalledFunc->getName());
11491158
for (unsigned i = 0, e = NoAliasArgs.size(); i != e; ++i) {
11501159
const Argument *A = NoAliasArgs[i];
11511160

1152-
std::string Name = std::string(CalledFunc->getName());
1153-
if (A->hasName()) {
1154-
Name += ": %";
1155-
Name += A->getName();
1156-
} else {
1157-
Name += ": argument ";
1158-
Name += utostr(i);
1161+
std::string Name;
1162+
if (!IsSPIRModule) {
1163+
Name = std::string(CalledFunc->getName());
1164+
if (A->hasName()) {
1165+
Name += ": %";
1166+
Name += A->getName();
1167+
} else {
1168+
Name += ": argument ";
1169+
Name += utostr(i);
1170+
}
11591171
}
11601172

11611173
// Note: We always create a new anonymous root here. This is true regardless
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; Test that alias scope metadata does not include function names for SPIR target.
2+
; This reduces metadata bloat and improves compilation performance for SYCL.
3+
;
4+
; RUN: opt -passes=inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s
5+
6+
; Check that optional string metadata node is not generated.
7+
; CHECK-NOT: !"callee: %a"
8+
; CHECK-NOT: !"callee2: %a"
9+
; CHECK-NOT: !"callee2: %b"
10+
11+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
12+
target triple = "spir64-unknown-unknown"
13+
14+
define void @callee(ptr noalias nocapture %a, ptr nocapture readonly %c) #0 {
15+
entry:
16+
%0 = load float, ptr %c, align 4
17+
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
18+
store float %0, ptr %arrayidx, align 4
19+
ret void
20+
}
21+
22+
; Don't check correctness precisely - just check if aliasing info is still
23+
; generated during inlining for SPIR target.
24+
; CHECK-LABEL: caller(
25+
; CHECK: load float
26+
; CHECK-SAME: !noalias ![[#Scope1:]]
27+
; CHECK: store float
28+
; CHECK-SAME: !alias.scope ![[#Scope1]]
29+
30+
define void @caller(ptr nocapture %a, ptr nocapture readonly %c) #0 {
31+
entry:
32+
tail call void @callee(ptr %a, ptr %c)
33+
%0 = load float, ptr %c, align 4
34+
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
35+
store float %0, ptr %arrayidx, align 4
36+
ret void
37+
}
38+
39+
define void @callee2(ptr noalias nocapture %a, ptr noalias nocapture %b, ptr nocapture readonly %c) #0 {
40+
entry:
41+
%0 = load float, ptr %c, align 4
42+
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
43+
store float %0, ptr %arrayidx, align 4
44+
%arrayidx1 = getelementptr inbounds float, ptr %b, i64 8
45+
store float %0, ptr %arrayidx1, align 4
46+
ret void
47+
}
48+
49+
; Don't check correctness precisely - just check if aliasing info is still
50+
; generated during inlining for SPIR target.
51+
; CHECK-LABEL: caller2(
52+
; CHECK: load float
53+
; CHECK-SAME: !noalias ![[#]]
54+
; CHECK: store float
55+
; CHECK-SAME: !alias.scope ![[#Scope3:]], !noalias ![[#Scope4:]]
56+
; CHECK: store float
57+
; CHECK-SAME: !alias.scope ![[#Scope4:]], !noalias ![[#Scope3:]]
58+
59+
define void @caller2(ptr nocapture %a, ptr nocapture %b, ptr nocapture readonly %c) #0 {
60+
entry:
61+
tail call void @callee2(ptr %a, ptr %b, ptr %c)
62+
%0 = load float, ptr %c, align 4
63+
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
64+
store float %0, ptr %arrayidx, align 4
65+
ret void
66+
}
67+
68+
attributes #0 = { nounwind }
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; Test that alias scope metadata does not include function names for SPIR-V target.
2+
; This reduces metadata bloat and improves compilation performance for SYCL.
3+
;
4+
; RUN: opt -passes=inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s
5+
6+
; Check that optional string metadata node is not generated.
7+
; CHECK-NOT: !"callee: %a"
8+
; CHECK-NOT: !"callee2: %a"
9+
; CHECK-NOT: !"callee2: %b"
10+
11+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
12+
target triple = "spirv64-unknown-unknown"
13+
14+
define void @callee(ptr noalias nocapture %a, ptr nocapture readonly %c) #0 {
15+
entry:
16+
%0 = load float, ptr %c, align 4
17+
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
18+
store float %0, ptr %arrayidx, align 4
19+
ret void
20+
}
21+
22+
; Don't check correctness precisely - just check if aliasing info is still
23+
; generated during inlining for SPIR-V target.
24+
; CHECK-LABEL: caller(
25+
; CHECK: load float
26+
; CHECK-SAME: !noalias ![[#Scope1:]]
27+
; CHECK: store float
28+
; CHECK-SAME: !alias.scope ![[#Scope1]]
29+
30+
define void @caller(ptr nocapture %a, ptr nocapture readonly %c) #0 {
31+
entry:
32+
tail call void @callee(ptr %a, ptr %c)
33+
%0 = load float, ptr %c, align 4
34+
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
35+
store float %0, ptr %arrayidx, align 4
36+
ret void
37+
}
38+
39+
define void @callee2(ptr noalias nocapture %a, ptr noalias nocapture %b, ptr nocapture readonly %c) #0 {
40+
entry:
41+
%0 = load float, ptr %c, align 4
42+
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
43+
store float %0, ptr %arrayidx, align 4
44+
%arrayidx1 = getelementptr inbounds float, ptr %b, i64 8
45+
store float %0, ptr %arrayidx1, align 4
46+
ret void
47+
}
48+
49+
; Don't check correctness precisely - just check if aliasing info is still
50+
; generated during inlining for SPIR-V target.
51+
; CHECK-LABEL: caller2(
52+
; CHECK: load float
53+
; CHECK-SAME: !noalias ![[#]]
54+
; CHECK: store float
55+
; CHECK-SAME: !alias.scope ![[#Scope3:]], !noalias ![[#Scope4:]]
56+
; CHECK: store float
57+
; CHECK-SAME: !alias.scope ![[#Scope4:]], !noalias ![[#Scope3:]]
58+
59+
define void @caller2(ptr nocapture %a, ptr nocapture %b, ptr nocapture readonly %c) #0 {
60+
entry:
61+
tail call void @callee2(ptr %a, ptr %b, ptr %c)
62+
%0 = load float, ptr %c, align 4
63+
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
64+
store float %0, ptr %arrayidx, align 4
65+
ret void
66+
}
67+
68+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)