Index: llvm/include/llvm/IR/Metadata.h =================================================================== --- llvm/include/llvm/IR/Metadata.h +++ llvm/include/llvm/IR/Metadata.h @@ -1208,6 +1208,12 @@ return nullptr; return dyn_cast_or_null(Node->getOperand(1)); } + StringRef getName() const { + if (Node->getNumOperands() > 2) + if (MDString *N = dyn_cast_or_null(Node->getOperand(2))) + return N->getString(); + return StringRef(); + } }; /// Typed iterator through MDNode operands. Index: llvm/include/llvm/Transforms/Utils/Cloning.h =================================================================== --- llvm/include/llvm/Transforms/Utils/Cloning.h +++ llvm/include/llvm/Transforms/Utils/Cloning.h @@ -17,6 +17,7 @@ #ifndef LLVM_TRANSFORMS_UTILS_CLONING_H #define LLVM_TRANSFORMS_UTILS_CLONING_H +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Twine.h" #include "llvm/Analysis/AssumptionCache.h" @@ -268,6 +269,27 @@ Function *Callee, int64_t entryDelta, const ValueMap *VMap = nullptr); -} // end namespace llvm +/// Utility for cloning !noalias and !alias.scope metadata. When a code region +/// using scoped alias metadata is cloned, the aliasing relationships may not +/// hold between the two clones, in which case it is necessary to clone the +/// metadata using this utility. This comes up with inlining and unrolling. +class ScopedAliasMetadataCloner { + using MetadataMap = DenseMap; + SetVector MD; + MetadataMap Map; + void addRecursiveMetadataUses(); + +public: + ScopedAliasMetadataCloner(ArrayRef Blocks); + ScopedAliasMetadataCloner(const Function *F); + /// Create a new clone of the scoped alias metadata, which will be used by + /// subsequent remap() calls. + void clone(); + + /// Remap instructions in the given VMap from the original to the cloned + /// metadata. + void remap(ValueToValueMapTy &VMap); +}; +} // end namespace llvm #endif // LLVM_TRANSFORMS_UTILS_CLONING_H Index: llvm/lib/Transforms/Utils/CloneFunction.cpp =================================================================== --- llvm/lib/Transforms/Utils/CloneFunction.cpp +++ llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -27,6 +27,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/MDBuilder.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -36,6 +37,8 @@ #include using namespace llvm; +#define DEBUG_TYPE "clone-function" + /// See comments in Cloning.h. BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix, Function *F, @@ -883,3 +886,101 @@ return NewBB; } + +ScopedAliasMetadataCloner::ScopedAliasMetadataCloner( + ArrayRef Blocks) { + for (BasicBlock *BB : Blocks) { + for (const Instruction &I : *BB) { + if (const MDNode *M = I.getMetadata(LLVMContext::MD_alias_scope)) + MD.insert(M); + if (const MDNode *M = I.getMetadata(LLVMContext::MD_noalias)) + MD.insert(M); + } + } + addRecursiveMetadataUses(); +} + +ScopedAliasMetadataCloner::ScopedAliasMetadataCloner(const Function *F) { + for (const BasicBlock &BB : *F) { + for (const Instruction &I : BB) { + if (const MDNode *M = I.getMetadata(LLVMContext::MD_alias_scope)) + MD.insert(M); + if (const MDNode *M = I.getMetadata(LLVMContext::MD_noalias)) + MD.insert(M); + + // We also need to clone the metadata in noalias intrinsics. + if (const auto *II = dyn_cast(&I)) + if (II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl) + if (const auto *M = dyn_cast( + cast( + II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg)) + ->getMetadata())) + MD.insert(M); + } + } + addRecursiveMetadataUses(); +} + +void ScopedAliasMetadataCloner::addRecursiveMetadataUses() { + SmallVector Queue(MD.begin(), MD.end()); + while (!Queue.empty()) { + const MDNode *M = cast(Queue.pop_back_val()); + for (const Metadata *Op : M->operands()) + if (const MDNode *OpMD = dyn_cast(Op)) + if (MD.insert(OpMD)) + Queue.push_back(OpMD); + } +} + +void ScopedAliasMetadataCloner::clone() { + // Discard a previous clone that may exist. + Map.clear(); + + SmallVector DummyNodes; + for (const MDNode *I : MD) { + DummyNodes.push_back(MDTuple::getTemporary(I->getContext(), None)); + Map[I].reset(DummyNodes.back().get()); + } + + // Create new metadata nodes to replace the dummy nodes, replacing old + // metadata references with either a dummy node or an already-created new + // node. + SmallVector NewOps; + for (const MDNode *I : MD) { + for (const Metadata *Op : I->operands()) { + if (const MDNode *M = dyn_cast(Op)) + NewOps.push_back(Map[M]); + else + NewOps.push_back(const_cast(Op)); + } + + MDNode *NewM = MDNode::get(I->getContext(), NewOps); + MDTuple *TempM = cast(Map[I]); + assert(TempM->isTemporary() && "Expected temporary node"); + + TempM->replaceAllUsesWith(NewM); + NewOps.clear(); + } +} + +void ScopedAliasMetadataCloner::remap(ValueToValueMapTy &VMap) { + if (Map.empty()) + return; // Nothing to do. + + for (auto Entry : VMap) { + // Check that key is an instruction, to skip the Argument mapping, which + // points to an instruction in the original function, not the inlined one. + if (!Entry->second || !isa(Entry->first)) + continue; + + Instruction *I = dyn_cast(Entry->second); + if (!I) + continue; + + if (MDNode *M = I->getMetadata(LLVMContext::MD_alias_scope)) + I->setMetadata(LLVMContext::MD_alias_scope, Map[M]); + + if (MDNode *M = I->getMetadata(LLVMContext::MD_noalias)) + I->setMetadata(LLVMContext::MD_noalias, Map[M]); + } +} Index: llvm/lib/Transforms/Utils/InlineFunction.cpp =================================================================== --- llvm/lib/Transforms/Utils/InlineFunction.cpp +++ llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -79,6 +79,11 @@ cl::Hidden, cl::desc("Convert noalias attributes to metadata during inlining.")); +static cl::opt UseNoAliasIntrinsic( + "use-noalias-intrinsic-during-inlining", cl::Hidden, cl::ZeroOrMore, + cl::init(true), + cl::desc("Use the llvm.noalias.decl intrinsic during inlining.")); + // Disabled by default, because the added alignment assumptions may increase // compile-time and block optimizations. This option is not suitable for use // with frontends that emit comprehensive parameter alignment annotations. @@ -821,94 +826,6 @@ } } -/// When inlining a function that contains noalias scope metadata, -/// this metadata needs to be cloned so that the inlined blocks -/// have different "unique scopes" at every call site. Were this not done, then -/// aliasing scopes from a function inlined into a caller multiple times could -/// not be differentiated (and this would lead to miscompiles because the -/// non-aliasing property communicated by the metadata could have -/// call-site-specific control dependencies). -static void CloneAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap) { - const Function *CalledFunc = CB.getCalledFunction(); - SetVector MD; - - // Note: We could only clone the metadata if it is already used in the - // caller. I'm omitting that check here because it might confuse - // inter-procedural alias analysis passes. We can revisit this if it becomes - // an efficiency or overhead problem. - - for (const BasicBlock &I : *CalledFunc) - for (const Instruction &J : I) { - if (const MDNode *M = J.getMetadata(LLVMContext::MD_alias_scope)) - MD.insert(M); - if (const MDNode *M = J.getMetadata(LLVMContext::MD_noalias)) - MD.insert(M); - } - - if (MD.empty()) - return; - - // Walk the existing metadata, adding the complete (perhaps cyclic) chain to - // the set. - SmallVector Queue(MD.begin(), MD.end()); - while (!Queue.empty()) { - const MDNode *M = cast(Queue.pop_back_val()); - for (unsigned i = 0, ie = M->getNumOperands(); i != ie; ++i) - if (const MDNode *M1 = dyn_cast(M->getOperand(i))) - if (MD.insert(M1)) - Queue.push_back(M1); - } - - // Now we have a complete set of all metadata in the chains used to specify - // the noalias scopes and the lists of those scopes. - SmallVector DummyNodes; - DenseMap MDMap; - for (const MDNode *I : MD) { - DummyNodes.push_back(MDTuple::getTemporary(CalledFunc->getContext(), None)); - MDMap[I].reset(DummyNodes.back().get()); - } - - // Create new metadata nodes to replace the dummy nodes, replacing old - // metadata references with either a dummy node or an already-created new - // node. - for (const MDNode *I : MD) { - SmallVector NewOps; - for (unsigned i = 0, ie = I->getNumOperands(); i != ie; ++i) { - const Metadata *V = I->getOperand(i); - if (const MDNode *M = dyn_cast(V)) - NewOps.push_back(MDMap[M]); - else - NewOps.push_back(const_cast(V)); - } - - MDNode *NewM = MDNode::get(CalledFunc->getContext(), NewOps); - MDTuple *TempM = cast(MDMap[I]); - assert(TempM->isTemporary() && "Expected temporary node"); - - TempM->replaceAllUsesWith(NewM); - } - - // Now replace the metadata in the new inlined instructions with the - // repacements from the map. - for (ValueToValueMapTy::iterator VMI = VMap.begin(), VMIE = VMap.end(); - VMI != VMIE; ++VMI) { - // Check that key is an instruction, to skip the Argument mapping, which - // points to an instruction in the original function, not the inlined one. - if (!VMI->second || !isa(VMI->first)) - continue; - - Instruction *NI = dyn_cast(VMI->second); - if (!NI) - continue; - - if (MDNode *M = NI->getMetadata(LLVMContext::MD_alias_scope)) - NI->setMetadata(LLVMContext::MD_alias_scope, MDMap[M]); - - if (MDNode *M = NI->getMetadata(LLVMContext::MD_noalias)) - NI->setMetadata(LLVMContext::MD_noalias, MDMap[M]); - } -} - /// If the inlined function has noalias arguments, /// then add new alias scopes for each noalias argument, tag the mapped noalias /// parameters with noalias metadata specifying the new scope, and tag all @@ -962,6 +879,16 @@ // property of the callee, but also all control dependencies in the caller. MDNode *NewScope = MDB.createAnonymousAliasScope(NewDomain, Name); NewScopes.insert(std::make_pair(A, NewScope)); + + if (UseNoAliasIntrinsic) { + // Introduce a llvm.noalias.decl for the noalias argument. + MDNode *AScopeList = MDNode::get(CalledFunc->getContext(), NewScope); + auto *NoAliasDecl = + IRBuilder<>(&CB).CreateNoAliasScopeDeclaration(AScopeList); + // Ignore the result for now. The result will be used when the + // llvm.noalias intrinsic is introduced. + (void)NoAliasDecl; + } } // Iterate over all new instructions in the map; for all memory-access @@ -1760,6 +1687,14 @@ // Keep a list of pair (dst, src) to emit byval initializations. SmallVector, 4> ByValInit; + // When inlining a function that contains noalias scope metadata, + // this metadata needs to be cloned so that the inlined blocks + // have different "unique scopes" at every call site. + // Track the metadata that must be cloned. Do this before other changes to + // the function, so that we do not get in trouble when inlining caller == + // callee. + ScopedAliasMetadataCloner SAMetadataCloner(CB.getCalledFunction()); + auto &DL = Caller->getParent()->getDataLayout(); // Calculate the vector of arguments to pass into the function cloner, which @@ -1877,8 +1812,15 @@ fixupLineNumbers(Caller, FirstNewBlock, &CB, CalledFunc->getSubprogram() != nullptr); - // Clone existing noalias metadata if necessary. - CloneAliasScopeMetadata(CB, VMap); + // When inlining a function that contains noalias scope metadata, + // this metadata needs to be cloned so that the inlined blocks + // have different "unique scopes" at every call site. Were this not done, + // then aliasing scopes from a function inlined into a caller multiple times + // could not be differentiated (and this would lead to miscompiles because + // the non-aliasing property communicated by the metadata could have + // call-site-specific control dependencies). + SAMetadataCloner.clone(); + SAMetadataCloner.remap(VMap); // Add noalias metadata if necessary. AddAliasScopeMetadata(CB, VMap, DL, CalleeAAR); Index: llvm/test/Transforms/Coroutines/ArgAddr.ll =================================================================== --- llvm/test/Transforms/Coroutines/ArgAddr.ll +++ llvm/test/Transforms/Coroutines/ArgAddr.ll @@ -54,10 +54,12 @@ ; CHECK-NEXT: bitcast i8* %index.addr12.i to i1* ; CHECK-NEXT: store i1 false ; CHECK-NEXT: store i32 3 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: store i32 3 ; CHECK-NEXT: call void @print(i32 3) ; CHECK-NEXT: store i1 false ; CHECK-NEXT: store i32 2 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: store i32 2 ; CHECK-NEXT: call void @print(i32 2) ; CHECK: ret i32 0 Index: llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll =================================================================== --- llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll +++ llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll @@ -1,5 +1,5 @@ -; RUN: opt < %s -enable-coroutines -O2 -S | FileCheck %s -; RUN: opt < %s -enable-coroutines -passes='default' -S | FileCheck %s +; RUN: opt < %s -enable-coroutines -O2 -S | FileCheck %s --check-prefixes=CHECK,OPM +; RUN: opt < %s -enable-coroutines -passes='default' -S | FileCheck %s --check-prefixes=CHECK,NPM define i8* @f(i8* %buffer, i32 %n) { entry: @@ -67,8 +67,28 @@ ; CHECK-NEXT: entry: ; CHECK: [[BUFFER:%.*]] = alloca [8 x i8], align 4 ; CHECK: [[SLOT:%.*]] = bitcast [8 x i8]* [[BUFFER]] to i32* -; CHECK-NEXT: store i32 7, i32* [[SLOT]], align 4 -; CHECK-NEXT: call void @print(i32 7) + +; OPM-NEXT: call void @llvm.experimental.noalias.scope.decl +; OPM-NEXT: call void @llvm.experimental.noalias.scope.decl +; OPM-NEXT: store i32 7, i32* [[SLOT]], align 4 +; OPM-NEXT: call void @llvm.experimental.noalias.scope.decl +; OPM-NEXT: call void @print(i32 7) + +; FIXME: After introduction of llvm.noalias.decl, this is not fully optimzed +; with the new pass manager. +; NPM-NEXT: store i32 1, i32* [[SLOT]], align 4 +; NPM-NEXT: call void @llvm.experimental.noalias.scope.decl +; NPM-NEXT: [[RELOAD0:%.+]] = load i32, i32* [[SLOT]], align 4 +; NPM-NEXT: [[SUM0:%.+]] = add i32 [[RELOAD0]], 2 +; NPM-NEXT: store i32 [[SUM0]], i32* [[SLOT]], align 4 +; NPM-NEXT: call void @llvm.experimental.noalias.scope.decl +; NPM-NEXT: [[RELOAD1:%.+]] = load i32, i32* [[SLOT]], align 4 +; NPM-NEXT: [[SUM2:%.+]] = add i32 [[RELOAD1]], 4 +; NPM-NEXT: store i32 [[SUM2]], i32* [[SLOT]], align 4 +; NPM-NEXT: call void @llvm.experimental.noalias.scope.decl +; NPM-NEXT: [[RELOAD2:%.+]] = load i32, i32* [[SLOT]], align 4 +; NPM-NEXT: call void @print(i32 [[RELOAD2]]) + ; CHECK-NEXT: ret i32 0 declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*) Index: llvm/test/Transforms/Coroutines/coro-retcon-value.ll =================================================================== --- llvm/test/Transforms/Coroutines/coro-retcon-value.ll +++ llvm/test/Transforms/Coroutines/coro-retcon-value.ll @@ -79,14 +79,17 @@ ; CHECK: [[SLOT:%.*]] = bitcast [8 x i8]* [[BUFFER]] to i32* ; CHECK-NEXT: store i32 4, i32* [[SLOT]], align 4 ; CHECK-NEXT: call void @print(i32 4) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[SLOT]], align 4 ; CHECK-NEXT: [[INC:%.*]] = add i32 [[LOAD]], 1 ; CHECK-NEXT: store i32 [[INC]], i32* [[SLOT]], align 4 ; CHECK-NEXT: call void @print(i32 [[INC]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[SLOT]], align 4 ; CHECK-NEXT: [[INC:%.*]] = add i32 [[LOAD]], 1 ; CHECK-NEXT: store i32 [[INC]], i32* [[SLOT]], align 4 ; CHECK-NEXT: call void @print(i32 [[INC]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: ret i32 0 declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*) Index: llvm/test/Transforms/Coroutines/coro-retcon.ll =================================================================== --- llvm/test/Transforms/Coroutines/coro-retcon.ll +++ llvm/test/Transforms/Coroutines/coro-retcon.ll @@ -69,13 +69,16 @@ ; CHECK: [[SLOT:%.*]] = bitcast [8 x i8]* [[BUFFER]] to i32* ; CHECK-NEXT: store i32 4, i32* [[SLOT]], align 4 ; CHECK-NEXT: call void @print(i32 4) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[SLOT]], align 4 ; CHECK-NEXT: [[INC:%.*]] = add i32 [[LOAD]], 1 ; CHECK-NEXT: store i32 [[INC]], i32* [[SLOT]], align 4 ; CHECK-NEXT: call void @print(i32 [[INC]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[SLOT]], align 4 ; CHECK-NEXT: [[INC:%.*]] = add i32 [[LOAD]], 1 ; CHECK-NEXT: call void @print(i32 [[INC]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: ret i32 0 define hidden { i8*, i8* } @g(i8* %buffer, i16* %ptr) { Index: llvm/test/Transforms/Coroutines/ex2.ll =================================================================== --- llvm/test/Transforms/Coroutines/ex2.ll +++ llvm/test/Transforms/Coroutines/ex2.ll @@ -49,7 +49,9 @@ ret i32 0 ; CHECK-NOT: call i8* @CustomAlloc ; CHECK: call void @print(i32 4) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: call void @print(i32 5) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: call void @print(i32 6) ; CHECK-NEXT: ret i32 0 } Index: llvm/test/Transforms/Coroutines/ex3.ll =================================================================== --- llvm/test/Transforms/Coroutines/ex3.ll +++ llvm/test/Transforms/Coroutines/ex3.ll @@ -53,7 +53,9 @@ ret i32 0 ; CHECK-NOT: i8* @malloc ; CHECK: call void @print(i32 4) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: call void @print(i32 -5) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: call void @print(i32 5) ; CHECK: ret i32 0 } Index: llvm/test/Transforms/Coroutines/ex4.ll =================================================================== --- llvm/test/Transforms/Coroutines/ex4.ll +++ llvm/test/Transforms/Coroutines/ex4.ll @@ -50,7 +50,9 @@ call void @llvm.coro.destroy(i8* %hdl) ret i32 0 ; CHECK: call void @print(i32 4) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: call void @print(i32 5) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl ; CHECK-NEXT: call void @print(i32 6) ; CHECK: ret i32 0 } Index: llvm/test/Transforms/Inline/launder.invariant.group.ll =================================================================== --- llvm/test/Transforms/Inline/launder.invariant.group.ll +++ llvm/test/Transforms/Inline/launder.invariant.group.ll @@ -23,7 +23,7 @@ ; CHECK-LABEL: define i32 @foo(%struct.A* noalias define i32 @foo(%struct.A* noalias) { ; CHECK-NOT: call i32 @bar( - ; CHECK-NOT: noalias + ; CHECK-NOT: !noalias %2 = tail call i32 @bar(%struct.A* %0) ret i32 %2 } Index: llvm/test/Transforms/Inline/noalias-calls-always.ll =================================================================== --- llvm/test/Transforms/Inline/noalias-calls-always.ll +++ llvm/test/Transforms/Inline/noalias-calls-always.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -aa-pipeline=basic-aa -passes=always-inline -enable-noalias-to-md-conversion -S < %s | FileCheck %s 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" @@ -6,6 +7,16 @@ declare void @hey() #0 define void @hello(i8* noalias nocapture %a, i8* noalias nocapture readonly %c, i8* nocapture %b) #1 { +; CHECK-LABEL: @hello( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A:%.*]], i8* align 16 [[B:%.*]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C:%.*]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: call void @hey() +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: ret void +; entry: %l = alloca i8, i32 512, align 1 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %b, i64 16, i1 0) @@ -17,12 +28,36 @@ } define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #2 { +; CHECK-LABEL: @foo( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L_I:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META0:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META3:metadata !.*]]) +; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A:%.*]], i8* align 16 [[B:%.*]], i64 16, i1 false) [[ATTR4:#.*]], !noalias !3 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C:%.*]], i64 16, i1 false) [[ATTR4]], !noalias !0 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR4]], !alias.scope !5 +; CHECK-NEXT: call void @hey() [[ATTR4]], !noalias !5 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L_I]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR4]], !noalias !0 +; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: ret void +; entry: tail call void @hello(i8* %a, i8* %c, i8* %b) ret void } define void @hello_cs(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #1 { +; CHECK-LABEL: @hello_cs( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A:%.*]], i8* align 16 [[B:%.*]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C:%.*]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: call void @hey() +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: ret void +; entry: %l = alloca i8, i32 512, align 1 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %b, i64 16, i1 0) @@ -34,46 +69,39 @@ } define void @foo_cs(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #2 { +; CHECK-LABEL: @foo_cs( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L_I:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META6:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META9:metadata !.*]]) +; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A:%.*]], i8* align 16 [[B:%.*]], i64 16, i1 false) [[ATTR4]], !noalias !9 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C:%.*]], i64 16, i1 false) [[ATTR4]], !noalias !6 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR4]], !alias.scope !11 +; CHECK-NEXT: call void @hey() [[ATTR4]], !noalias !11 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L_I]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR4]], !noalias !6 +; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: ret void +; entry: tail call void @hello_cs(i8* noalias %a, i8* noalias %c, i8* %b) ret void } -; CHECK: define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) -; CHECK: entry: -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %b, i64 16, i1 false) #4, !noalias !0 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %b, i8* align 16 %c, i64 16, i1 false) #4, !noalias !3 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %c, i64 16, i1 false) #4, !alias.scope !5 -; CHECK: call void @hey() #4, !noalias !5 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %{{.*}}, i8* align 16 %c, i64 16, i1 false) #4, !noalias !3 -; CHECK: ret void -; CHECK: } - -; CHECK: define void @foo_cs(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) -; CHECK: entry: -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %b, i64 16, i1 false) #4, !noalias !6 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %b, i8* align 16 %c, i64 16, i1 false) #4, !noalias !9 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %c, i64 16, i1 false) #4, !alias.scope !11 -; CHECK: call void @hey() #4, !noalias !11 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %{{.*}}, i8* align 16 %c, i64 16, i1 false) #4, !noalias !9 -; CHECK: ret void -; CHECK: } - attributes #0 = { nounwind argmemonly willreturn } attributes #1 = { nounwind alwaysinline } attributes #2 = { nounwind uwtable } ; CHECK: !0 = !{!1} -; CHECK: !1 = distinct !{!1, !2, !"hello: %c"} +; CHECK: !1 = distinct !{!1, !2, !"hello: %a"} ; CHECK: !2 = distinct !{!2, !"hello"} ; CHECK: !3 = !{!4} -; CHECK: !4 = distinct !{!4, !2, !"hello: %a"} -; CHECK: !5 = !{!4, !1} +; CHECK: !4 = distinct !{!4, !2, !"hello: %c"} +; CHECK: !5 = !{!1, !4} ; CHECK: !6 = !{!7} -; CHECK: !7 = distinct !{!7, !8, !"hello_cs: %c"} +; CHECK: !7 = distinct !{!7, !8, !"hello_cs: %a"} ; CHECK: !8 = distinct !{!8, !"hello_cs"} ; CHECK: !9 = !{!10} -; CHECK: !10 = distinct !{!10, !8, !"hello_cs: %a"} -; CHECK: !11 = !{!10, !7} - +; CHECK: !10 = distinct !{!10, !8, !"hello_cs: %c"} +; CHECK: !11 = !{!7, !10} Index: llvm/test/Transforms/Inline/noalias-calls.ll =================================================================== --- llvm/test/Transforms/Inline/noalias-calls.ll +++ llvm/test/Transforms/Inline/noalias-calls.ll @@ -8,6 +8,17 @@ declare void @hey() #0 define void @hello(i8* noalias nocapture %a, i8* noalias nocapture readonly %c, i8* nocapture %b) #1 { +; CHECK-LABEL: define {{[^@]+}}@hello +; CHECK-SAME: (i8* noalias nocapture [[A:%.*]], i8* noalias nocapture readonly [[C:%.*]], i8* nocapture [[B:%.*]]) [[ATTR1:#.*]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[B]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: call void @hey() +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: ret void +; entry: %l = alloca i8, i32 512, align 1 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %b, i64 16, i1 0) @@ -19,12 +30,38 @@ } define void @foo(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #2 { +; CHECK-LABEL: define {{[^@]+}}@foo +; CHECK-SAME: (i8* nocapture [[A:%.*]], i8* nocapture readonly [[C:%.*]], i8* nocapture [[B:%.*]]) [[ATTR2:#.*]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L_I:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META0:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META3:metadata !.*]]) +; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[B]], i64 16, i1 false) [[ATTR2]], !noalias !3 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR2]], !noalias !0 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR2]], !alias.scope !5 +; CHECK-NEXT: call void @hey() [[ATTR2]], !noalias !5 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L_I]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR2]], !noalias !0 +; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: ret void +; entry: tail call void @hello(i8* %a, i8* %c, i8* %b) ret void } define void @hello_cs(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #1 { +; CHECK-LABEL: define {{[^@]+}}@hello_cs +; CHECK-SAME: (i8* nocapture [[A:%.*]], i8* nocapture readonly [[C:%.*]], i8* nocapture [[B:%.*]]) [[ATTR1]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[B]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: call void @hey() +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L]], i8* align 16 [[C]], i64 16, i1 false) +; CHECK-NEXT: ret void +; entry: %l = alloca i8, i32 512, align 1 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %b, i64 16, i1 0) @@ -36,46 +73,41 @@ } define void @foo_cs(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #2 { +; CHECK-LABEL: define {{[^@]+}}@foo_cs +; CHECK-SAME: (i8* nocapture [[A:%.*]], i8* nocapture readonly [[C:%.*]], i8* nocapture [[B:%.*]]) [[ATTR2]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: [[L_I:%.*]] = alloca i8, i32 512, align 1 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META6:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META9:metadata !.*]]) +; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[B]], i64 16, i1 false) [[ATTR2]], !noalias !9 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[B]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR2]], !noalias !6 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[A]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR2]], !alias.scope !11 +; CHECK-NEXT: call void @hey() [[ATTR2]], !noalias !11 +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[L_I]], i8* align 16 [[C]], i64 16, i1 false) [[ATTR2]], !noalias !6 +; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 512, i8* [[L_I]]) +; CHECK-NEXT: ret void +; entry: tail call void @hello_cs(i8* noalias %a, i8* noalias %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* align 16 %a, i8* align 16 %b, i64 16, i1 false) #2, !noalias !0 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %b, i8* align 16 %c, i64 16, i1 false) #2, !noalias !3 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %c, i64 16, i1 false) #2, !alias.scope !5 -; CHECK: call void @hey() #2, !noalias !5 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %{{.*}}, i8* align 16 %c, i64 16, i1 false) #2, !noalias !3 -; CHECK: ret void -; CHECK: } - -; CHECK: define void @foo_cs(i8* nocapture %a, i8* nocapture readonly %c, i8* nocapture %b) #2 { -; CHECK: entry: -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %b, i64 16, i1 false) #2, !noalias !6 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %b, i8* align 16 %c, i64 16, i1 false) #2, !noalias !9 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %a, i8* align 16 %c, i64 16, i1 false) #2, !alias.scope !11 -; CHECK: call void @hey() #2, !noalias !11 -; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %{{.*}}, i8* align 16 %c, i64 16, i1 false) #2, !noalias !9 -; CHECK: ret void -; CHECK: } - attributes #0 = { argmemonly nofree nosync nounwind willreturn } attributes #1 = { argmemonly nounwind willreturn } attributes #2 = { nounwind } attributes #3 = { nounwind uwtable } ; CHECK: !0 = !{!1} -; CHECK: !1 = distinct !{!1, !2, !"hello: %c"} +; CHECK: !1 = distinct !{!1, !2, !"hello: %a"} ; CHECK: !2 = distinct !{!2, !"hello"} ; CHECK: !3 = !{!4} -; CHECK: !4 = distinct !{!4, !2, !"hello: %a"} -; CHECK: !5 = !{!4, !1} +; CHECK: !4 = distinct !{!4, !2, !"hello: %c"} +; CHECK: !5 = !{!1, !4} ; CHECK: !6 = !{!7} -; CHECK: !7 = distinct !{!7, !8, !"hello_cs: %c"} +; CHECK: !7 = distinct !{!7, !8, !"hello_cs: %a"} ; CHECK: !8 = distinct !{!8, !"hello_cs"} ; CHECK: !9 = !{!10} -; CHECK: !10 = distinct !{!10, !8, !"hello_cs: %a"} -; CHECK: !11 = !{!10, !7} +; CHECK: !10 = distinct !{!10, !8, !"hello_cs: %c"} +; CHECK: !11 = !{!7, !10} Index: llvm/test/Transforms/Inline/noalias.ll =================================================================== --- llvm/test/Transforms/Inline/noalias.ll +++ llvm/test/Transforms/Inline/noalias.ll @@ -19,14 +19,15 @@ ret void } -; CHECK: define void @foo(float* nocapture %a, float* nocapture readonly %c) #0 { +; CHECK-LABEL: define void @foo(float* nocapture %a, float* nocapture readonly %c) #0 { ; CHECK: entry: -; CHECK: %0 = load float, float* %c, align 4, !noalias !0 +; CHECK: call void @llvm.experimental.noalias.scope.decl +; CHECK: [[TMP0:%.+]] = 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: store float [[TMP0]], float* %arrayidx.i, align 4, !alias.scope !0 +; CHECK: [[TMP1:%.+]] = load float, float* %c, align 4 ; CHECK: %arrayidx = getelementptr inbounds float, float* %a, i64 7 -; CHECK: store float %1, float* %arrayidx, align 4 +; CHECK: store float [[TMP1]], float* %arrayidx, align 4 ; CHECK: ret void ; CHECK: } @@ -49,16 +50,18 @@ ret void } -; CHECK: define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { +; CHECK-LABEL: 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: call void @llvm.experimental.noalias.scope.decl(metadata !3) +; CHECK: call void @llvm.experimental.noalias.scope.decl(metadata !6) +; CHECK: [[TMP0:%.+]] = load float, float* %c, align 4, !noalias !8 ; 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: store float [[TMP0]], float* %arrayidx.i, align 4, !alias.scope !3, !noalias !6 ; 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: store float [[TMP0]], float* %arrayidx1.i, align 4, !alias.scope !6, !noalias !3 +; CHECK: [[TMP1:%.+]] = load float, float* %c, align 4 ; CHECK: %arrayidx = getelementptr inbounds float, float* %a, i64 7 -; CHECK: store float %1, float* %arrayidx, align 4 +; CHECK: store float [[TMP1]], float* %arrayidx, align 4 ; CHECK: ret void ; CHECK: } @@ -67,10 +70,9 @@ ; CHECK: !0 = !{!1} ; CHECK: !1 = distinct !{!1, !2, !"hello: %a"} ; CHECK: !2 = distinct !{!2, !"hello"} -; CHECK: !3 = !{!4, !6} +; CHECK: !3 = !{!4} ; 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} - +; CHECK: !6 = !{!7} +; CHECK: !7 = distinct !{!7, !5, !"hello2: %b"} +; CHECK: !8 = !{!4, !7} Index: llvm/test/Transforms/Inline/noalias2.ll =================================================================== --- llvm/test/Transforms/Inline/noalias2.ll +++ llvm/test/Transforms/Inline/noalias2.ll @@ -7,7 +7,7 @@ define void @hello(float* noalias nocapture %a, float* noalias nocapture readonly %c) #0 { ; CHECK-LABEL: define {{[^@]+}}@hello -; CHECK-SAME: (float* noalias nocapture [[A:%.*]], float* noalias nocapture readonly [[C:%.*]]) #0 +; CHECK-SAME: (float* noalias nocapture [[A:%.*]], float* noalias nocapture readonly [[C:%.*]]) [[ATTR0:#.*]] { ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[C]], align 4 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 5 @@ -29,14 +29,16 @@ define void @foo(float* noalias nocapture %a, float* noalias nocapture readonly %c) #0 { ; CHECK-LABEL: define {{[^@]+}}@foo -; CHECK-SAME: (float* noalias nocapture [[A:%.*]], float* noalias nocapture readonly [[C:%.*]]) #0 +; CHECK-SAME: (float* noalias nocapture [[A:%.*]], float* noalias nocapture readonly [[C:%.*]]) [[ATTR0]] { ; CHECK-NEXT: entry: -; CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[C]], align 4, !alias.scope !0, !noalias !3 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META0:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META3:metadata !.*]]) +; CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[C]], align 4, !alias.scope !3, !noalias !0 ; CHECK-NEXT: [[ARRAYIDX_I:%.*]] = getelementptr inbounds float, float* [[A]], i64 5 -; CHECK-NEXT: store float [[TMP0]], float* [[ARRAYIDX_I]], align 4, !alias.scope !3, !noalias !0 -; CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[C]], align 4 +; CHECK-NEXT: store float [[TMP2]], float* [[ARRAYIDX_I]], align 4, !alias.scope !0, !noalias !3 +; CHECK-NEXT: [[TMP3:%.*]] = load float, float* [[C]], align 4 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 7 -; CHECK-NEXT: store float [[TMP1]], float* [[ARRAYIDX]], align 4 +; CHECK-NEXT: store float [[TMP3]], float* [[ARRAYIDX]], align 4 ; CHECK-NEXT: ret void ; ; ASSUME-LABEL: @foo( @@ -59,7 +61,7 @@ define void @hello2(float* noalias nocapture %a, float* noalias nocapture %b, float* nocapture readonly %c) #0 { ; CHECK-LABEL: define {{[^@]+}}@hello2 -; CHECK-SAME: (float* noalias nocapture [[A:%.*]], float* noalias nocapture [[B:%.*]], float* nocapture readonly [[C:%.*]]) #0 +; CHECK-SAME: (float* noalias nocapture [[A:%.*]], float* noalias nocapture [[B:%.*]], float* nocapture readonly [[C:%.*]]) [[ATTR0]] { ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[C]], align 4 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 6 @@ -81,22 +83,28 @@ ; foo2(), the noalias scopes are properly concatenated. define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture readonly %c) #0 { ; CHECK-LABEL: define {{[^@]+}}@foo2 -; CHECK-SAME: (float* nocapture [[A:%.*]], float* nocapture [[B:%.*]], float* nocapture readonly [[C:%.*]]) #0 +; CHECK-SAME: (float* nocapture [[A:%.*]], float* nocapture [[B:%.*]], float* nocapture readonly [[C:%.*]]) [[ATTR0]] { ; CHECK-NEXT: entry: -; CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[C]], align 4, !alias.scope !5, !noalias !10 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META5:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META8:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META0]]) [[ATTR2:#.*]], !noalias !10 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META3]]) [[ATTR2]], !noalias !10 +; CHECK-NEXT: [[TMP4:%.*]] = load float, float* [[C]], align 4, !alias.scope !11, !noalias !14 ; CHECK-NEXT: [[ARRAYIDX_I_I:%.*]] = getelementptr inbounds float, float* [[A]], i64 5 -; CHECK-NEXT: store float [[TMP0]], float* [[ARRAYIDX_I_I]], align 4, !alias.scope !10, !noalias !5 -; CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[C]], align 4, !alias.scope !13, !noalias !14 +; CHECK-NEXT: store float [[TMP4]], float* [[ARRAYIDX_I_I]], align 4, !alias.scope !14, !noalias !11 +; CHECK-NEXT: [[TMP5:%.*]] = load float, float* [[C]], align 4, !alias.scope !8, !noalias !5 ; CHECK-NEXT: [[ARRAYIDX_I:%.*]] = getelementptr inbounds float, float* [[A]], i64 7 -; CHECK-NEXT: store float [[TMP1]], float* [[ARRAYIDX_I]], align 4, !alias.scope !14, !noalias !13 -; CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[C]], align 4, !noalias !15 +; CHECK-NEXT: store float [[TMP5]], float* [[ARRAYIDX_I]], align 4, !alias.scope !5, !noalias !8 +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META16:metadata !.*]]) +; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl([[META19:metadata !.*]]) +; CHECK-NEXT: [[TMP8:%.*]] = load float, float* [[C]], align 4, !noalias !21 ; CHECK-NEXT: [[ARRAYIDX_I1:%.*]] = getelementptr inbounds float, float* [[A]], i64 6 -; CHECK-NEXT: store float [[TMP2]], float* [[ARRAYIDX_I1]], align 4, !alias.scope !19, !noalias !20 +; CHECK-NEXT: store float [[TMP8]], float* [[ARRAYIDX_I1]], align 4, !alias.scope !16, !noalias !19 ; CHECK-NEXT: [[ARRAYIDX1_I:%.*]] = getelementptr inbounds float, float* [[B]], i64 8 -; CHECK-NEXT: store float [[TMP2]], float* [[ARRAYIDX1_I]], align 4, !alias.scope !20, !noalias !19 -; CHECK-NEXT: [[TMP3:%.*]] = load float, float* [[C]], align 4 +; CHECK-NEXT: store float [[TMP8]], float* [[ARRAYIDX1_I]], align 4, !alias.scope !19, !noalias !16 +; CHECK-NEXT: [[TMP9:%.*]] = load float, float* [[C]], align 4 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 7 -; CHECK-NEXT: store float [[TMP3]], float* [[ARRAYIDX]], align 4 +; CHECK-NEXT: store float [[TMP9]], float* [[ARRAYIDX]], align 4 ; CHECK-NEXT: ret void ; entry: @@ -109,26 +117,27 @@ } ; NO_ASSUME: !0 = !{!1} -; NO_ASSUME: !1 = distinct !{!1, !2, !"hello: %c"} +; NO_ASSUME: !1 = distinct !{!1, !2, !"hello: %a"} ; NO_ASSUME: !2 = distinct !{!2, !"hello"} ; NO_ASSUME: !3 = !{!4} -; NO_ASSUME: !4 = distinct !{!4, !2, !"hello: %a"} -; NO_ASSUME: !5 = !{!6, !8} -; NO_ASSUME: !6 = distinct !{!6, !7, !"hello: %c"} -; NO_ASSUME: !7 = distinct !{!7, !"hello"} -; NO_ASSUME: !8 = distinct !{!8, !9, !"foo: %c"} -; NO_ASSUME: !9 = distinct !{!9, !"foo"} -; NO_ASSUME: !10 = !{!11, !12} -; NO_ASSUME: !11 = distinct !{!11, !7, !"hello: %a"} -; NO_ASSUME: !12 = distinct !{!12, !9, !"foo: %a"} -; NO_ASSUME: !13 = !{!8} -; NO_ASSUME: !14 = !{!12} -; NO_ASSUME: !15 = !{!16, !18} -; NO_ASSUME: !16 = distinct !{!16, !17, !"hello2: %a"} -; NO_ASSUME: !17 = distinct !{!17, !"hello2"} -; NO_ASSUME: !18 = distinct !{!18, !17, !"hello2: %b"} -; NO_ASSUME: !19 = !{!16} -; NO_ASSUME: !20 = !{!18} +; NO_ASSUME: !4 = distinct !{!4, !2, !"hello: %c"} +; NO_ASSUME: !5 = !{!6} +; NO_ASSUME: !6 = distinct !{!6, !7, !"foo: %a"} +; NO_ASSUME: !7 = distinct !{!7, !"foo"} +; NO_ASSUME: !8 = !{!9} +; NO_ASSUME: !9 = distinct !{!9, !7, !"foo: %c"} +; NO_ASSUME: !10 = !{!6, !9} +; NO_ASSUME: !11 = !{!12, !9} +; NO_ASSUME: !12 = distinct !{!12, !13, !"hello: %c"} +; NO_ASSUME: !13 = distinct !{!13, !"hello"} +; NO_ASSUME: !14 = !{!15, !6} +; NO_ASSUME: !15 = distinct !{!15, !13, !"hello: %a"} +; NO_ASSUME: !16 = !{!17} +; NO_ASSUME: !17 = distinct !{!17, !18, !"hello2: %a"} +; NO_ASSUME: !18 = distinct !{!18, !"hello2"} +; NO_ASSUME: !19 = !{!20} +; NO_ASSUME: !20 = distinct !{!20, !18, !"hello2: %b"} +; NO_ASSUME: !21 = !{!17, !20} attributes #0 = { nounwind uwtable } Index: llvm/test/Transforms/PhaseOrdering/inlining-alignment-assumptions.ll =================================================================== --- llvm/test/Transforms/PhaseOrdering/inlining-alignment-assumptions.ll +++ llvm/test/Transforms/PhaseOrdering/inlining-alignment-assumptions.ll @@ -95,6 +95,7 @@ define amdgpu_kernel void @caller2() { ; CHECK-LABEL: @caller2( +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META0:metadata !.*]]) ; CHECK-NEXT: ret void ; %alloca = alloca i64, align 8, addrspace(5) Index: llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll =================================================================== --- llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll +++ llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll @@ -70,6 +70,7 @@ ; CHECK-NEXT: [[I2:%.*]] = alloca [[TMP0:%.*]], align 8 ; CHECK-NEXT: [[I1_SROA_0_0_I5_SROA_IDX:%.*]] = getelementptr inbounds [[TMP0]], %0* [[ARG:%.*]], i64 0, i32 0 ; CHECK-NEXT: [[I1_SROA_0_0_COPYLOAD:%.*]] = load i32*, i32** [[I1_SROA_0_0_I5_SROA_IDX]], align 8 +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META0:metadata !.*]]) ; CHECK-NEXT: [[I_SROA_0_0_I6_SROA_IDX:%.*]] = getelementptr inbounds [[TMP0]], %0* [[I2]], i64 0, i32 0 ; CHECK-NEXT: store i32* [[I1_SROA_0_0_COPYLOAD]], i32** [[I_SROA_0_0_I6_SROA_IDX]], align 8 ; CHECK-NEXT: tail call void @_Z7escape01S(%0* nonnull byval(%0) align 8 [[I2]]) @@ -109,6 +110,7 @@ ; CHECK-NEXT: bb: ; CHECK-NEXT: [[I1_SROA_0_0_I4_SROA_IDX:%.*]] = getelementptr inbounds [[TMP0:%.*]], %0* [[ARG:%.*]], i64 0, i32 0 ; CHECK-NEXT: [[I1_SROA_0_0_COPYLOAD:%.*]] = load i32*, i32** [[I1_SROA_0_0_I4_SROA_IDX]], align 8 +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META3:metadata !.*]]) ; CHECK-NEXT: [[I5:%.*]] = tail call i32 @_Z4condv() ; CHECK-NEXT: [[I6_NOT:%.*]] = icmp eq i32 [[I5]], 0 ; CHECK-NEXT: br i1 [[I6_NOT]], label [[BB10:%.*]], label [[BB7:%.*]] Index: llvm/test/Transforms/PhaseOrdering/pr39282.ll =================================================================== --- llvm/test/Transforms/PhaseOrdering/pr39282.ll +++ llvm/test/Transforms/PhaseOrdering/pr39282.ll @@ -19,12 +19,20 @@ define void @pr39282(i32* %addr1, i32* %addr2) { ; CHECK-LABEL: @pr39282( ; CHECK-NEXT: start: -; CHECK-NEXT: [[X_I:%.*]] = load i32, i32* [[ADDR1:%.*]], align 4, !alias.scope !0, !noalias !3 +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META0:metadata !.*]]) +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META3:metadata !.*]]) +; CHECK-NEXT: [[X_I:%.*]] = load i32, i32* [[ADDR1:%.*]], align 4, !alias.scope !3, !noalias !0 ; CHECK-NEXT: [[ADDR1I_1:%.*]] = getelementptr inbounds i32, i32* [[ADDR1]], i64 1 ; CHECK-NEXT: [[ADDR2I_1:%.*]] = getelementptr inbounds i32, i32* [[ADDR2:%.*]], i64 1 -; CHECK-NEXT: [[X_I_1:%.*]] = load i32, i32* [[ADDR1I_1]], align 4, !alias.scope !0, !noalias !3 -; CHECK-NEXT: store i32 [[X_I]], i32* [[ADDR2]], align 4, !alias.scope !3, !noalias !0 -; CHECK-NEXT: store i32 [[X_I_1]], i32* [[ADDR2I_1]], align 4, !alias.scope !3, !noalias !0 +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META0]]) +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META3]]) +; CHECK-NEXT: [[X_I_1:%.*]] = load i32, i32* [[ADDR1I_1]], align 4, !alias.scope !3, !noalias !0 +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META0]]) +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META3]]) +; CHECK-NEXT: store i32 [[X_I]], i32* [[ADDR2]], align 4, !alias.scope !0, !noalias !3 +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META0]]) +; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl([[META3]]) +; CHECK-NEXT: store i32 [[X_I_1]], i32* [[ADDR2I_1]], align 4, !alias.scope !0, !noalias !3 ; CHECK-NEXT: ret void ; start: