From: Dan Gohman Date: Fri, 29 Oct 2010 01:14:04 +0000 (+0000) Subject: Teach memdep to use pointsToConstantMemory to determine that loads X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=cd5c123a1d8723dbd5d493210c0a56890bffe409;p=oota-llvm.git Teach memdep to use pointsToConstantMemory to determine that loads from constant memory don't alias any stores. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117636 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index 5940105a3aa..c72cd1e83a8 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -161,8 +161,9 @@ getCallSiteDependencyFrom(CallSite CS, bool isReadOnlyCall, } /// getPointerDependencyFrom - Return the instruction on which a memory -/// location depends. If isLoad is true, this routine ignore may-aliases with -/// read-only operations. +/// location depends. If isLoad is true, this routine ignores may-aliases with +/// read-only operations. If isLoad is false, this routine ignores may-aliases +/// with reads from read-only locations. MemDepResult MemoryDependenceAnalysis:: getPointerDependencyFrom(const AliasAnalysis::Location &MemLoc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB) { @@ -225,17 +226,21 @@ getPointerDependencyFrom(const AliasAnalysis::Location &MemLoc, bool isLoad, Value *Pointer = LI->getPointerOperand(); uint64_t PointerSize = AA->getTypeStoreSize(LI->getType()); MDNode *TBAATag = LI->getMetadata(LLVMContext::MD_tbaa); + AliasAnalysis::Location LoadLoc(Pointer, PointerSize, TBAATag); // If we found a pointer, check if it could be the same as our pointer. - AliasAnalysis::AliasResult R = - AA->alias(AliasAnalysis::Location(Pointer, PointerSize, TBAATag), - MemLoc); + AliasAnalysis::AliasResult R = AA->alias(LoadLoc, MemLoc); if (R == AliasAnalysis::NoAlias) continue; // May-alias loads don't depend on each other without a dependence. if (isLoad && R == AliasAnalysis::MayAlias) continue; + + // Stores don't alias loads from read-only memory. + if (!isLoad && AA->pointsToConstantMemory(LoadLoc)) + continue; + // Stores depend on may and must aliased loads, loads depend on must-alias // loads. return MemDepResult::getDef(Inst); diff --git a/test/Analysis/TypeBasedAliasAnalysis/dse.ll b/test/Analysis/TypeBasedAliasAnalysis/dse.ll index 180149a7ad1..09a7f2c3b78 100644 --- a/test/Analysis/TypeBasedAliasAnalysis/dse.ll +++ b/test/Analysis/TypeBasedAliasAnalysis/dse.ll @@ -25,6 +25,29 @@ define i8 @test0_no(i8* %a, i8* %b) nounwind { ret i8 %y } +; CHECK: @test1_yes +; CHECK-NEXT: load i8* %b +; CHECK-NEXT: store i8 1, i8* %a +; CHECK-NEXT: ret i8 %y +define i8 @test1_yes(i8* %a, i8* %b) nounwind { + store i8 0, i8* %a + %y = load i8* %b, !tbaa !5 + store i8 1, i8* %a + ret i8 %y +} + +; CHECK: @test1_no +; CHECK-NEXT: store i8 0, i8* %a +; CHECK-NEXT: load i8* %b +; CHECK-NEXT: store i8 1, i8* %a +; CHECK-NEXT: ret i8 %y +define i8 @test1_no(i8* %a, i8* %b) nounwind { + store i8 0, i8* %a + %y = load i8* %b, !tbaa !6 + store i8 1, i8* %a + ret i8 %y +} + ; Root note. !0 = metadata !{ } ; Some type.