Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,19 +1143,31 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap,
DenseMap<const Argument *, MDNode *> NewScopes;
MDBuilder MDB(CalledFunc->getContext());

// For spir/spirv targets, disable function name encoding
// in alias metadata to reduce metadata bloat and improve compilation
// performance.
const Module *M = CalledFunc->getParent();
const auto Arch = M->getTargetTriple().getArch();
const bool IsSPIRModule =
Arch == Triple::ArchType::spir || Arch == Triple::ArchType::spir64 ||
Arch == Triple::ArchType::spirv || Arch == Triple::ArchType::spirv64;

// Create a new scope domain for this function.
MDNode *NewDomain =
MDB.createAnonymousAliasScopeDomain(CalledFunc->getName());
MDNode *NewDomain = MDB.createAnonymousAliasScopeDomain(
IsSPIRModule ? StringRef() : CalledFunc->getName());
for (unsigned i = 0, e = NoAliasArgs.size(); i != e; ++i) {
const Argument *A = NoAliasArgs[i];

std::string Name = std::string(CalledFunc->getName());
if (A->hasName()) {
Name += ": %";
Name += A->getName();
} else {
Name += ": argument ";
Name += utostr(i);
std::string Name;
if (!IsSPIRModule) {
Name = std::string(CalledFunc->getName());
if (A->hasName()) {
Name += ": %";
Name += A->getName();
} else {
Name += ": argument ";
Name += utostr(i);
}
}

// Note: We always create a new anonymous root here. This is true regardless
Expand Down
68 changes: 68 additions & 0 deletions llvm/test/Transforms/Inline/noalias-spir.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
; Test that alias scope metadata does not include function names for SPIR target.
; This reduces metadata bloat and improves compilation performance for SYCL.
;
; RUN: opt -passes=inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s

; Check that optional string metadata node is not generated.
; CHECK-NOT: !"callee: %a"
; CHECK-NOT: !"callee2: %a"
; CHECK-NOT: !"callee2: %b"

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

define void @callee(ptr noalias nocapture %a, ptr nocapture readonly %c) #0 {
entry:
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
store float %0, ptr %arrayidx, align 4
ret void
}

; Don't check correctness precisely - just check if aliasing info is still
; generated during inlining for SPIR target.
; CHECK-LABEL: caller(
; CHECK: load float
; CHECK-SAME: !noalias ![[#Scope1:]]
; CHECK: store float
; CHECK-SAME: !alias.scope ![[#Scope1]]

define void @caller(ptr nocapture %a, ptr nocapture readonly %c) #0 {
entry:
tail call void @callee(ptr %a, ptr %c)
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
store float %0, ptr %arrayidx, align 4
ret void
}

define void @callee2(ptr noalias nocapture %a, ptr noalias nocapture %b, ptr nocapture readonly %c) #0 {
entry:
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
store float %0, ptr %arrayidx, align 4
%arrayidx1 = getelementptr inbounds float, ptr %b, i64 8
store float %0, ptr %arrayidx1, align 4
ret void
}

; Don't check correctness precisely - just check if aliasing info is still
; generated during inlining for SPIR target.
; CHECK-LABEL: caller2(
; CHECK: load float
; CHECK-SAME: !noalias ![[#]]
; CHECK: store float
; CHECK-SAME: !alias.scope ![[#Scope3:]], !noalias ![[#Scope4:]]
; CHECK: store float
; CHECK-SAME: !alias.scope ![[#Scope4:]], !noalias ![[#Scope3:]]

define void @caller2(ptr nocapture %a, ptr nocapture %b, ptr nocapture readonly %c) #0 {
entry:
tail call void @callee2(ptr %a, ptr %b, ptr %c)
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
store float %0, ptr %arrayidx, align 4
ret void
}

attributes #0 = { nounwind }
68 changes: 68 additions & 0 deletions llvm/test/Transforms/Inline/noalias-spirv.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
; Test that alias scope metadata does not include function names for SPIR-V target.
; This reduces metadata bloat and improves compilation performance for SYCL.
;
; RUN: opt -passes=inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s

; Check that optional string metadata node is not generated.
; CHECK-NOT: !"callee: %a"
; CHECK-NOT: !"callee2: %a"
; CHECK-NOT: !"callee2: %b"

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spirv64-unknown-unknown"

define void @callee(ptr noalias nocapture %a, ptr nocapture readonly %c) #0 {
entry:
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
store float %0, ptr %arrayidx, align 4
ret void
}

; Don't check correctness precisely - just check if aliasing info is still
; generated during inlining for SPIR-V target.
; CHECK-LABEL: caller(
; CHECK: load float
; CHECK-SAME: !noalias ![[#Scope1:]]
; CHECK: store float
; CHECK-SAME: !alias.scope ![[#Scope1]]

define void @caller(ptr nocapture %a, ptr nocapture readonly %c) #0 {
entry:
tail call void @callee(ptr %a, ptr %c)
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
store float %0, ptr %arrayidx, align 4
ret void
}

define void @callee2(ptr noalias nocapture %a, ptr noalias nocapture %b, ptr nocapture readonly %c) #0 {
entry:
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 5
store float %0, ptr %arrayidx, align 4
%arrayidx1 = getelementptr inbounds float, ptr %b, i64 8
store float %0, ptr %arrayidx1, align 4
ret void
}

; Don't check correctness precisely - just check if aliasing info is still
; generated during inlining for SPIR-V target.
; CHECK-LABEL: caller2(
; CHECK: load float
; CHECK-SAME: !noalias ![[#]]
; CHECK: store float
; CHECK-SAME: !alias.scope ![[#Scope3:]], !noalias ![[#Scope4:]]
; CHECK: store float
; CHECK-SAME: !alias.scope ![[#Scope4:]], !noalias ![[#Scope3:]]

define void @caller2(ptr nocapture %a, ptr nocapture %b, ptr nocapture readonly %c) #0 {
entry:
tail call void @callee2(ptr %a, ptr %b, ptr %c)
%0 = load float, ptr %c, align 4
%arrayidx = getelementptr inbounds float, ptr %a, i64 7
store float %0, ptr %arrayidx, align 4
ret void
}

attributes #0 = { nounwind }
Loading