[llvm-commits] [llvm] r117636 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp test/Analysis/TypeBasedAliasAnalysis/dse.ll
Dan Gohman
gohman at apple.com
Thu Oct 28 18:14:05 PDT 2010
Author: djg
Date: Thu Oct 28 20:14:04 2010
New Revision: 117636
URL: http://llvm.org/viewvc/llvm-project?rev=117636&view=rev
Log:
Teach memdep to use pointsToConstantMemory to determine that loads
from constant memory don't alias any stores.
Modified:
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/dse.ll
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=117636&r1=117635&r2=117636&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Thu Oct 28 20:14:04 2010
@@ -161,8 +161,9 @@
}
/// 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 @@
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);
Modified: llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/dse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/dse.ll?rev=117636&r1=117635&r2=117636&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/dse.ll (original)
+++ llvm/trunk/test/Analysis/TypeBasedAliasAnalysis/dse.ll Thu Oct 28 20:14:04 2010
@@ -25,6 +25,29 @@
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.
More information about the llvm-commits
mailing list