Index: lib/Transforms/Utils/InlineFunction.cpp =================================================================== --- lib/Transforms/Utils/InlineFunction.cpp +++ lib/Transforms/Utils/InlineFunction.cpp @@ -51,6 +51,11 @@ cl::desc("Convert noalias attributes to metadata during inlining.")); static cl::opt +UseNoAliasIntrinsic("use-noalias-intrinsic-during-inlining", cl::Hidden, + cl::init(true), + cl::desc("Use the llvm.noalias intrinsic during inlining.")); + +static cl::opt PreserveAlignmentAssumptions("preserve-alignment-assumptions-during-inlining", cl::init(true), cl::Hidden, cl::desc("Convert align attributes to assumptions during inlining.")); @@ -738,6 +743,13 @@ MD.insert(M); if (const MDNode *M = J.getMetadata(LLVMContext::MD_noalias)) MD.insert(M); + + // We also need to clone the metadata in noalias intrinsics. + if (const IntrinsicInst *II = dyn_cast(&J)) + if (II->getIntrinsicID() == Intrinsic::noalias) + if (const MDNode *M = dyn_cast(cast( + II->getOperand(1))->getMetadata())) + MD.insert(M); } if (MD.empty()) @@ -822,6 +834,101 @@ if (MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_noalias)) NI->setMetadata(LLVMContext::MD_noalias, M); } + + // Update the metadata referenced by a noalias intrinsic + if (IntrinsicInst *II = dyn_cast(NI)) + if (II->getIntrinsicID() == Intrinsic::noalias) + if (MDNode *M = dyn_cast(cast( + II->getOperand(1))->getMetadata())) { + // If the metadata is not in the map, it could be a new intrinsic + // that was just added. + auto MI = MDMap.find(M); + if (MI != MDMap.end()) + II->setOperand(1, MetadataAsValue::get(CalledFunc->getContext(), + MI->second)); + } + } +} + +/// If the inlined function has noalias arguments, +/// then add a new alias scope to instructions that might access memory, and +/// noalias intrinsics corresponding to the noalias arguments. +static void AddNoAliasIntrinsics(CallSite CS, ValueToValueMapTy &VMap, + MDNode *&NewScopeList) { + if (!EnableNoAliasConversion || !UseNoAliasIntrinsic) + return; + + const Function *CalledFunc = CS.getCalledFunction(); + SmallVector NoAliasArgs; + + for (Function::const_arg_iterator I = CalledFunc->arg_begin(), + E = CalledFunc->arg_end(); I != E; ++I) { + if (I->hasNoAliasAttr() && !I->use_empty()) + NoAliasArgs.push_back(&*I); + } + + if (NoAliasArgs.empty()) + return; + + MDBuilder MDB(CalledFunc->getContext()); + // Create a new scope domain for this function. + MDNode *NewDomain = + MDB.createAnonymousAliasScopeDomain(CalledFunc->getName()); + + // Create a new scope for each noalias argument. + SmallVector Scopes; + + // For each noalias argument, add a noalias intrinsic call, and update the + // value map to refer to the new result of the noalias call. + for (const Argument *A : NoAliasArgs) { + std::string Name = CalledFunc->getName(); + if (A->hasName()) { + Name += ": %"; + Name += A->getName(); + } else { + Name += ": argument "; + Name += utostr(A->getArgNo()); + } + + MDNode *AScope = + MDB.createAnonymousAliasScope(NewDomain, Name); + Scopes.push_back(AScope); + + SmallVector AScopeListEntries(1, AScope); + MDNode *AScopeList = + MDNode::get(CalledFunc->getContext(), AScopeListEntries); + + Value *NA = + IRBuilder<>(CS.getInstruction()).CreateNoAliasPointer(VMap[A], + AScopeList); + VMap[A] = NA; + } + + NewScopeList = MDNode::get(CalledFunc->getContext(), Scopes); +} + +static void AddNoAliasIntrinsicsScope(CallSite CS, ValueToValueMapTy &VMap, + MDNode *NewScopeList) { + if (!EnableNoAliasConversion || !UseNoAliasIntrinsic || !NewScopeList) + return; + + // Iterate over all new instructions in the map; for all memory-access + // instructions, add the alias scope metadata. + for (ValueToValueMapTy::iterator VMI = VMap.begin(), VMIE = VMap.end(); + VMI != VMIE; ++VMI) { + if (isa(VMI->first)) { + if (!VMI->second) + continue; + + Instruction *NI = dyn_cast(VMI->second); + if (!NI || !NI->mayReadOrWriteMemory()) + continue; + + NI->setMetadata( + LLVMContext::MD_noalias, + MDNode::concatenate(NI->getMetadata(LLVMContext::MD_noalias), + NewScopeList)); + } } } @@ -831,7 +938,7 @@ /// non-derived loads, stores and memory intrinsics with the new alias scopes. static void AddAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap, const DataLayout &DL, AAResults *CalleeAAR) { - if (!EnableNoAliasConversion) + if (!EnableNoAliasConversion || UseNoAliasIntrinsic) return; const Function *CalledFunc = CS.getCalledFunction(); @@ -1483,6 +1590,7 @@ ValueToValueMapTy VMap; // Keep a list of pair (dst, src) to emit byval initializations. SmallVector, 4> ByValInit; + MDNode *NAScopeList = nullptr; auto &DL = Caller->getParent()->getDataLayout(); @@ -1516,6 +1624,9 @@ // check what will be known at the start of the inlined code. AddAlignmentAssumptions(CS, IFI); + // Add noalias intrinsics corresponding to noalias function arguments. + AddNoAliasIntrinsics(CS, VMap, NAScopeList); + // We want the inliner to prune the code as it copies. We would LOVE to // have no dead or constant instructions leftover after inlining occurs // (which can happen, e.g., because an argument was constant), but we'll be @@ -1602,6 +1713,9 @@ // Propagate llvm.mem.parallel_loop_access if necessary. PropagateParallelLoopAccessMetadata(CS, VMap); + // Add scopes to memory accesses corresponding to added noalias intrinsics. + AddNoAliasIntrinsicsScope(CS, VMap, NAScopeList); + // FIXME: We could register any cloned assumptions instead of clearing the // whole function's cache. if (IFI.ACT) Index: test/Transforms/Inline/noalias-calls.ll =================================================================== --- test/Transforms/Inline/noalias-calls.ll +++ test/Transforms/Inline/noalias-calls.ll @@ -1,9 +1,10 @@ -; RUN: opt -basicaa -inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s +; RUN: opt -basicaa -inline -enable-noalias-to-md-conversion -use-noalias-intrinsic-during-inlining=0 -S < %s | FileCheck %s -check-prefix=MD-SCOPE +; RUN: opt -inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s -check-prefix=INTR-SCOPE target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) #0 -declare void @hey() #0 +declare void @hey() #1 define void @hello(i8* noalias nocapture %a, i8* noalias nocapture readonly %c, i8* nocapture %b) #1 { entry: @@ -16,30 +17,49 @@ ret void } -define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #2 { +define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #1 { entry: tail call void @hello(i8* %a, i8* %c, i8* %b) ret void } -; CHECK: define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #2 { -; CHECK: entry: -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 16, i32 16, i1 false) #1, !noalias !0 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %c, i64 16, i32 16, i1 false) #1, !noalias !3 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %c, i64 16, i32 16, i1 false) #1, !alias.scope !5 -; CHECK: call void @hey() #1, !noalias !5 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %c, i64 16, i32 16, i1 false) #1, !noalias !3 -; CHECK: ret void -; CHECK: } +; MD-SCOPE: define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #1 { +; MD-SCOPE: entry: +; MD-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 16, i32 16, i1 false) #1, !noalias !0 +; MD-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %c, i64 16, i32 16, i1 false) #1, !noalias !3 +; MD-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %c, i64 16, i32 16, i1 false) #1, !alias.scope !5 +; MD-SCOPE: call void @hey() #1, !noalias !5 +; MD-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %c, i64 16, i32 16, i1 false) #1, !noalias !3 +; MD-SCOPE: ret void +; MD-SCOPE: } + +; INTR-SCOPE: define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #1 { +; INTR-SCOPE: entry: +; INTR-SCOPE: %l.i = alloca i8, i32 512, align 1 +; INTR-SCOPE: %0 = call i8* @llvm.noalias.p0i8(i8* %a, metadata !0) +; INTR-SCOPE: %1 = call i8* @llvm.noalias.p0i8(i8* %c, metadata !3) +; INTR-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %b, i64 16, i32 16, i1 false) #1, !noalias !5 +; INTR-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %1, i64 16, i32 16, i1 false) #1, !noalias !5 +; INTR-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %1, i64 16, i32 16, i1 false) #1, !noalias !5 +; INTR-SCOPE: call void @hey() #1, !noalias !5 +; INTR-SCOPE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %l.i, i8* %1, i64 16, i32 16, i1 false) #1, !noalias !5 +; INTR-SCOPE: ret void +; INTR-SCOPE: } attributes #0 = { nounwind argmemonly } attributes #1 = { nounwind } -attributes #2 = { nounwind uwtable } - -; CHECK: !0 = !{!1} -; CHECK: !1 = distinct !{!1, !2, !"hello: %c"} -; CHECK: !2 = distinct !{!2, !"hello"} -; CHECK: !3 = !{!4} -; CHECK: !4 = distinct !{!4, !2, !"hello: %a"} -; CHECK: !5 = !{!4, !1} + +; MD-SCOPE: !0 = !{!1} +; MD-SCOPE: !1 = distinct !{!1, !2, !"hello: %c"} +; MD-SCOPE: !2 = distinct !{!2, !"hello"} +; MD-SCOPE: !3 = !{!4} +; MD-SCOPE: !4 = distinct !{!4, !2, !"hello: %a"} +; MD-SCOPE: !5 = !{!4, !1} + +; INTR-SCOPE: !0 = !{!1} +; INTR-SCOPE: !1 = distinct !{!1, !2, !"hello: %a"} +; INTR-SCOPE: !2 = distinct !{!2, !"hello"} +; INTR-SCOPE: !3 = !{!4} +; INTR-SCOPE: !4 = distinct !{!4, !2, !"hello: %c"} +; INTR-SCOPE: !5 = !{!1, !4} Index: test/Transforms/Inline/noalias.ll =================================================================== --- test/Transforms/Inline/noalias.ll +++ test/Transforms/Inline/noalias.ll @@ -1,4 +1,5 @@ -; RUN: opt -inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s +; RUN: opt -inline -enable-noalias-to-md-conversion -use-noalias-intrinsic-during-inlining=0 -S < %s | FileCheck %s -check-prefix=MD-SCOPE +; RUN: opt -inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s -check-prefix=INTR-SCOPE target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -19,16 +20,28 @@ ret void } -; CHECK: define void @foo(float* nocapture %a, float* nocapture readonly %c) #0 { -; CHECK: entry: -; CHECK: %0 = load float, float* %c, align 4, !noalias !0 -; CHECK: %arrayidx.i = getelementptr inbounds float, float* %a, i64 5 -; CHECK: store float %0, float* %arrayidx.i, align 4, !alias.scope !0 -; CHECK: %1 = load float, float* %c, align 4 -; CHECK: %arrayidx = getelementptr inbounds float, float* %a, i64 7 -; CHECK: store float %1, float* %arrayidx, align 4 -; CHECK: ret void -; CHECK: } +; MD-SCOPE: define void @foo(float* nocapture %a, float* nocapture readonly %c) #0 { +; MD-SCOPE: entry: +; MD-SCOPE: %0 = load float, float* %c, align 4, !noalias !0 +; MD-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %a, i64 5 +; MD-SCOPE: store float %0, float* %arrayidx.i, align 4, !alias.scope !0 +; MD-SCOPE: %1 = load float, float* %c, align 4 +; MD-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; MD-SCOPE: store float %1, float* %arrayidx, align 4 +; MD-SCOPE: ret void +; MD-SCOPE: } + +; INTR-SCOPE: define void @foo(float* nocapture %a, float* nocapture readonly %c) #0 { +; INTR-SCOPE: entry: +; INTR-SCOPE: %0 = call float* @llvm.noalias.p0f32(float* %a, metadata !0) +; INTR-SCOPE: %1 = load float, float* %c, align 4, !noalias !0 +; INTR-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %0, i64 5 +; INTR-SCOPE: store float %1, float* %arrayidx.i, align 4, !noalias !0 +; INTR-SCOPE: %2 = load float, float* %c, align 4 +; INTR-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; INTR-SCOPE: store float %2, float* %arrayidx, align 4 +; INTR-SCOPE: ret void +; INTR-SCOPE: } define void @hello2(float* noalias nocapture %a, float* noalias nocapture %b, float* nocapture readonly %c) #0 { entry: @@ -49,28 +62,54 @@ ret void } -; CHECK: define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { -; CHECK: entry: -; CHECK: %0 = load float, float* %c, align 4, !noalias !3 -; CHECK: %arrayidx.i = getelementptr inbounds float, float* %a, i64 5 -; CHECK: store float %0, float* %arrayidx.i, align 4, !alias.scope !7, !noalias !8 -; CHECK: %arrayidx1.i = getelementptr inbounds float, float* %b, i64 8 -; CHECK: store float %0, float* %arrayidx1.i, align 4, !alias.scope !8, !noalias !7 -; CHECK: %1 = load float, float* %c, align 4 -; CHECK: %arrayidx = getelementptr inbounds float, float* %a, i64 7 -; CHECK: store float %1, float* %arrayidx, align 4 -; CHECK: ret void -; CHECK: } +; MD-SCOPE: define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { +; MD-SCOPE: entry: +; MD-SCOPE: %0 = load float, float* %c, align 4, !noalias !3 +; MD-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %a, i64 5 +; MD-SCOPE: store float %0, float* %arrayidx.i, align 4, !alias.scope !7, !noalias !8 +; MD-SCOPE: %arrayidx1.i = getelementptr inbounds float, float* %b, i64 8 +; MD-SCOPE: store float %0, float* %arrayidx1.i, align 4, !alias.scope !8, !noalias !7 +; MD-SCOPE: %1 = load float, float* %c, align 4 +; MD-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; MD-SCOPE: store float %1, float* %arrayidx, align 4 +; MD-SCOPE: ret void +; MD-SCOPE: } + +; INTR-SCOPE: define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { +; INTR-SCOPE: entry: +; INTR-SCOPE: %0 = call float* @llvm.noalias.p0f32(float* %a, metadata !3) +; INTR-SCOPE: %1 = call float* @llvm.noalias.p0f32(float* %b, metadata !6) +; INTR-SCOPE: %2 = load float, float* %c, align 4, !noalias !8 +; INTR-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %0, i64 5 +; INTR-SCOPE: store float %2, float* %arrayidx.i, align 4, !noalias !8 +; INTR-SCOPE: %arrayidx1.i = getelementptr inbounds float, float* %1, i64 8 +; INTR-SCOPE: store float %2, float* %arrayidx1.i, align 4, !noalias !8 +; INTR-SCOPE: %3 = load float, float* %c, align 4 +; INTR-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; INTR-SCOPE: store float %3, float* %arrayidx, align 4 +; INTR-SCOPE: ret void +; INTR-SCOPE: } attributes #0 = { nounwind uwtable } +attributes #1 = { argmemonly nounwind } + +; MD-SCOPE: !0 = !{!1} +; MD-SCOPE: !1 = distinct !{!1, !2, !"hello: %a"} +; MD-SCOPE: !2 = distinct !{!2, !"hello"} +; MD-SCOPE: !3 = !{!4, !6} +; MD-SCOPE: !4 = distinct !{!4, !5, !"hello2: %a"} +; MD-SCOPE: !5 = distinct !{!5, !"hello2"} +; MD-SCOPE: !6 = distinct !{!6, !5, !"hello2: %b"} +; MD-SCOPE: !7 = !{!4} +; MD-SCOPE: !8 = !{!6} -; CHECK: !0 = !{!1} -; CHECK: !1 = distinct !{!1, !2, !"hello: %a"} -; CHECK: !2 = distinct !{!2, !"hello"} -; CHECK: !3 = !{!4, !6} -; CHECK: !4 = distinct !{!4, !5, !"hello2: %a"} -; CHECK: !5 = distinct !{!5, !"hello2"} -; CHECK: !6 = distinct !{!6, !5, !"hello2: %b"} -; CHECK: !7 = !{!4} -; CHECK: !8 = !{!6} +; INTR-SCOPE: !0 = !{!1} +; INTR-SCOPE: !1 = distinct !{!1, !2, !"hello: %a"} +; INTR-SCOPE: !2 = distinct !{!2, !"hello"} +; INTR-SCOPE: !3 = !{!4} +; INTR-SCOPE: !4 = distinct !{!4, !5, !"hello2: %a"} +; INTR-SCOPE: !5 = distinct !{!5, !"hello2"} +; INTR-SCOPE: !6 = !{!7} +; INTR-SCOPE: !7 = distinct !{!7, !5, !"hello2: %b"} +; INTR-SCOPE: !8 = !{!4, !7} Index: test/Transforms/Inline/noalias2.ll =================================================================== --- test/Transforms/Inline/noalias2.ll +++ test/Transforms/Inline/noalias2.ll @@ -1,4 +1,6 @@ -; RUN: opt -inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s +; RUN: opt -inline -enable-noalias-to-md-conversion -use-noalias-intrinsic-during-inlining=0 -S < %s | FileCheck %s -check-prefix=MD-SCOPE +; RUN: opt -inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s -check-prefix=INTR-SCOPE + target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -19,16 +21,29 @@ ret void } -; CHECK: define void @foo(float* noalias nocapture %a, float* noalias nocapture readonly %c) #0 { -; CHECK: entry: -; CHECK: %0 = load float, float* %c, align 4, !alias.scope !0, !noalias !3 -; CHECK: %arrayidx.i = getelementptr inbounds float, float* %a, i64 5 -; CHECK: store float %0, float* %arrayidx.i, align 4, !alias.scope !3, !noalias !0 -; CHECK: %1 = load float, float* %c, align 4 -; CHECK: %arrayidx = getelementptr inbounds float, float* %a, i64 7 -; CHECK: store float %1, float* %arrayidx, align 4 -; CHECK: ret void -; CHECK: } +; MD-SCOPE: define void @foo(float* noalias nocapture %a, float* noalias nocapture readonly %c) #0 { +; MD-SCOPE: entry: +; MD-SCOPE: %0 = load float, float* %c, align 4, !alias.scope !0, !noalias !3 +; MD-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %a, i64 5 +; MD-SCOPE: store float %0, float* %arrayidx.i, align 4, !alias.scope !3, !noalias !0 +; MD-SCOPE: %1 = load float, float* %c, align 4 +; MD-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; MD-SCOPE: store float %1, float* %arrayidx, align 4 +; MD-SCOPE: ret void +; MD-SCOPE: } + +; INTR-SCOPE: define void @foo(float* noalias nocapture %a, float* noalias nocapture readonly %c) #0 { +; INTR-SCOPE: entry: +; INTR-SCOPE: %0 = call float* @llvm.noalias.p0f32(float* %a, metadata !0) +; INTR-SCOPE: %1 = call float* @llvm.noalias.p0f32(float* %c, metadata !3) +; INTR-SCOPE: %2 = load float, float* %1, align 4, !noalias !5 +; INTR-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %0, i64 5 +; INTR-SCOPE: store float %2, float* %arrayidx.i, align 4, !noalias !5 +; INTR-SCOPE: %3 = load float, float* %c, align 4 +; INTR-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; INTR-SCOPE: store float %3, float* %arrayidx, align 4 +; INTR-SCOPE: ret void +; INTR-SCOPE: } define void @hello2(float* noalias nocapture %a, float* noalias nocapture %b, float* nocapture readonly %c) #0 { entry: @@ -52,46 +67,96 @@ ret void } -; CHECK: define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { -; CHECK: entry: -; CHECK: %0 = load float, float* %c, align 4, !alias.scope !5, !noalias !10 -; CHECK: %arrayidx.i.i = getelementptr inbounds float, float* %a, i64 5 -; CHECK: store float %0, float* %arrayidx.i.i, align 4, !alias.scope !10, !noalias !5 -; CHECK: %1 = load float, float* %c, align 4, !alias.scope !13, !noalias !14 -; CHECK: %arrayidx.i = getelementptr inbounds float, float* %a, i64 7 -; CHECK: store float %1, float* %arrayidx.i, align 4, !alias.scope !14, !noalias !13 -; CHECK: %2 = load float, float* %c, align 4, !noalias !15 -; CHECK: %arrayidx.i1 = getelementptr inbounds float, float* %a, i64 6 -; CHECK: store float %2, float* %arrayidx.i1, align 4, !alias.scope !19, !noalias !20 -; CHECK: %arrayidx1.i = getelementptr inbounds float, float* %b, i64 8 -; CHECK: store float %2, float* %arrayidx1.i, align 4, !alias.scope !20, !noalias !19 -; CHECK: %3 = load float, float* %c, align 4 -; CHECK: %arrayidx = getelementptr inbounds float, float* %a, i64 7 -; CHECK: store float %3, float* %arrayidx, align 4 -; CHECK: ret void -; CHECK: } +; MD-SCOPE: define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { +; MD-SCOPE: entry: +; MD-SCOPE: %0 = load float, float* %c, align 4, !alias.scope !5, !noalias !10 +; MD-SCOPE: %arrayidx.i.i = getelementptr inbounds float, float* %a, i64 5 +; MD-SCOPE: store float %0, float* %arrayidx.i.i, align 4, !alias.scope !10, !noalias !5 +; MD-SCOPE: %1 = load float, float* %c, align 4, !alias.scope !13, !noalias !14 +; MD-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %a, i64 7 +; MD-SCOPE: store float %1, float* %arrayidx.i, align 4, !alias.scope !14, !noalias !13 +; MD-SCOPE: %2 = load float, float* %c, align 4, !noalias !15 +; MD-SCOPE: %arrayidx.i1 = getelementptr inbounds float, float* %a, i64 6 +; MD-SCOPE: store float %2, float* %arrayidx.i1, align 4, !alias.scope !19, !noalias !20 +; MD-SCOPE: %arrayidx1.i = getelementptr inbounds float, float* %b, i64 8 +; MD-SCOPE: store float %2, float* %arrayidx1.i, align 4, !alias.scope !20, !noalias !19 +; MD-SCOPE: %3 = load float, float* %c, align 4 +; MD-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; MD-SCOPE: store float %3, float* %arrayidx, align 4 +; MD-SCOPE: ret void +; MD-SCOPE: } + +; INTR-SCOPE: define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { +; INTR-SCOPE: entry: +; INTR-SCOPE: %0 = call float* @llvm.noalias.p0f32(float* %a, metadata !6) +; INTR-SCOPE: %1 = call float* @llvm.noalias.p0f32(float* %c, metadata !9) +; INTR-SCOPE: %2 = call float* @llvm.noalias.p0f32(float* %0, metadata !11) #2, !noalias !14 +; INTR-SCOPE: %3 = call float* @llvm.noalias.p0f32(float* %1, metadata !15) #2, !noalias !14 +; INTR-SCOPE: %4 = load float, float* %3, align 4, !noalias !17 +; INTR-SCOPE: %arrayidx.i.i = getelementptr inbounds float, float* %2, i64 5 +; INTR-SCOPE: store float %4, float* %arrayidx.i.i, align 4, !noalias !17 +; INTR-SCOPE: %5 = load float, float* %1, align 4, !noalias !14 +; INTR-SCOPE: %arrayidx.i = getelementptr inbounds float, float* %0, i64 7 +; INTR-SCOPE: store float %5, float* %arrayidx.i, align 4, !noalias !14 +; INTR-SCOPE: %6 = call float* @llvm.noalias.p0f32(float* %a, metadata !18) +; INTR-SCOPE: %7 = call float* @llvm.noalias.p0f32(float* %b, metadata !21) +; INTR-SCOPE: %8 = load float, float* %c, align 4, !noalias !23 +; INTR-SCOPE: %arrayidx.i1 = getelementptr inbounds float, float* %6, i64 6 +; INTR-SCOPE: store float %8, float* %arrayidx.i1, align 4, !noalias !23 +; INTR-SCOPE: %arrayidx1.i = getelementptr inbounds float, float* %7, i64 8 +; INTR-SCOPE: store float %8, float* %arrayidx1.i, align 4, !noalias !23 +; INTR-SCOPE: %9 = load float, float* %c, align 4 +; INTR-SCOPE: %arrayidx = getelementptr inbounds float, float* %a, i64 7 +; INTR-SCOPE: store float %9, float* %arrayidx, align 4 +; INTR-SCOPE: ret void +; INTR-SCOPE: } + +; MD-SCOPE: !0 = !{!1} +; MD-SCOPE: !1 = distinct !{!1, !2, !"hello: %c"} +; MD-SCOPE: !2 = distinct !{!2, !"hello"} +; MD-SCOPE: !3 = !{!4} +; MD-SCOPE: !4 = distinct !{!4, !2, !"hello: %a"} +; MD-SCOPE: !5 = !{!6, !8} +; MD-SCOPE: !6 = distinct !{!6, !7, !"hello: %c"} +; MD-SCOPE: !7 = distinct !{!7, !"hello"} +; MD-SCOPE: !8 = distinct !{!8, !9, !"foo: %c"} +; MD-SCOPE: !9 = distinct !{!9, !"foo"} +; MD-SCOPE: !10 = !{!11, !12} +; MD-SCOPE: !11 = distinct !{!11, !7, !"hello: %a"} +; MD-SCOPE: !12 = distinct !{!12, !9, !"foo: %a"} +; MD-SCOPE: !13 = !{!8} +; MD-SCOPE: !14 = !{!12} +; MD-SCOPE: !15 = !{!16, !18} +; MD-SCOPE: !16 = distinct !{!16, !17, !"hello2: %a"} +; MD-SCOPE: !17 = distinct !{!17, !"hello2"} +; MD-SCOPE: !18 = distinct !{!18, !17, !"hello2: %b"} +; MD-SCOPE: !19 = !{!16} +; MD-SCOPE: !20 = !{!18} -; CHECK: !0 = !{!1} -; CHECK: !1 = distinct !{!1, !2, !"hello: %c"} -; CHECK: !2 = distinct !{!2, !"hello"} -; CHECK: !3 = !{!4} -; CHECK: !4 = distinct !{!4, !2, !"hello: %a"} -; CHECK: !5 = !{!6, !8} -; CHECK: !6 = distinct !{!6, !7, !"hello: %c"} -; CHECK: !7 = distinct !{!7, !"hello"} -; CHECK: !8 = distinct !{!8, !9, !"foo: %c"} -; CHECK: !9 = distinct !{!9, !"foo"} -; CHECK: !10 = !{!11, !12} -; CHECK: !11 = distinct !{!11, !7, !"hello: %a"} -; CHECK: !12 = distinct !{!12, !9, !"foo: %a"} -; CHECK: !13 = !{!8} -; CHECK: !14 = !{!12} -; CHECK: !15 = !{!16, !18} -; CHECK: !16 = distinct !{!16, !17, !"hello2: %a"} -; CHECK: !17 = distinct !{!17, !"hello2"} -; CHECK: !18 = distinct !{!18, !17, !"hello2: %b"} -; CHECK: !19 = !{!16} -; CHECK: !20 = !{!18} +; INTR-SCOPE: !0 = !{!1} +; INTR-SCOPE: !1 = distinct !{!1, !2, !"hello: %a"} +; INTR-SCOPE: !2 = distinct !{!2, !"hello"} +; INTR-SCOPE: !3 = !{!4} +; INTR-SCOPE: !4 = distinct !{!4, !2, !"hello: %c"} +; INTR-SCOPE: !5 = !{!1, !4} +; INTR-SCOPE: !6 = !{!7} +; INTR-SCOPE: !7 = distinct !{!7, !8, !"foo: %a"} +; INTR-SCOPE: !8 = distinct !{!8, !"foo"} +; INTR-SCOPE: !9 = !{!10} +; INTR-SCOPE: !10 = distinct !{!10, !8, !"foo: %c"} +; INTR-SCOPE: !11 = !{!12} +; INTR-SCOPE: !12 = distinct !{!12, !13, !"hello: %a"} +; INTR-SCOPE: !13 = distinct !{!13, !"hello"} +; INTR-SCOPE: !14 = !{!7, !10} +; INTR-SCOPE: !15 = !{!16} +; INTR-SCOPE: !16 = distinct !{!16, !13, !"hello: %c"} +; INTR-SCOPE: !17 = !{!12, !16, !7, !10} +; INTR-SCOPE: !18 = !{!19} +; INTR-SCOPE: !19 = distinct !{!19, !20, !"hello2: %a"} +; INTR-SCOPE: !20 = distinct !{!20, !"hello2"} +; INTR-SCOPE: !21 = !{!22} +; INTR-SCOPE: !22 = distinct !{!22, !20, !"hello2: %b"} +; INTR-SCOPE: !23 = !{!19, !22} attributes #0 = { nounwind uwtable }