diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index f49fbf8807bac..bdef0790b911e 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1143,19 +1143,31 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap, DenseMap 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 diff --git a/llvm/test/Transforms/Inline/noalias-spir.ll b/llvm/test/Transforms/Inline/noalias-spir.ll new file mode 100644 index 0000000000000..a88e7ff55fa0a --- /dev/null +++ b/llvm/test/Transforms/Inline/noalias-spir.ll @@ -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 } diff --git a/llvm/test/Transforms/Inline/noalias-spirv.ll b/llvm/test/Transforms/Inline/noalias-spirv.ll new file mode 100644 index 0000000000000..4d7b5d97771c2 --- /dev/null +++ b/llvm/test/Transforms/Inline/noalias-spirv.ll @@ -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 }