diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-09-20 21:00:18 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-09-20 21:00:18 +0000 |
| commit | eea16a168a790d802cd79d8da93f8e3fd9313fee (patch) | |
| tree | ddb3feb7dfbec61c898cd219d4269c85cda65a07 | |
| parent | a0aa8fb6a6486f0b96b58912f414b503985b849c (diff) | |
| download | bcm5719-llvm-eea16a168a790d802cd79d8da93f8e3fd9313fee.tar.gz bcm5719-llvm-eea16a168a790d802cd79d8da93f8e3fd9313fee.zip | |
improve memdep to eliminate bitcasts (and aliases, and noop geps)
early for the stated reasons: this allows it to find more
equivalences and depend less on code layout.
llvm-svn: 82404
| -rw-r--r-- | llvm/lib/Analysis/MemoryDependenceAnalysis.cpp | 15 | ||||
| -rw-r--r-- | llvm/test/Transforms/GVN/rle.ll | 26 |
2 files changed, 40 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp index 97b791caf92..d5db2ed651e 100644 --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -521,6 +521,13 @@ getNonLocalPointerDependency(Value *Pointer, bool isLoad, BasicBlock *FromBB, const Type *EltTy = cast<PointerType>(Pointer->getType())->getElementType(); uint64_t PointeeSize = AA->getTypeStoreSize(EltTy); + // If Pointer is a bitcast instruction, chomp through to the pointee since + // they are must alias. This increases the effectiveness of caching by + // finding more equivalences, avoids having to phi translate the bitcast, and + // avoids conflicts where we are looking for two "different" values in the + // same block when they are really just must aliases. + Pointer = Pointer->stripPointerCasts(); + // This is the set of blocks we've inspected, and the pointer we consider in // each block. Because of critical edges, we currently bail out if querying // a block with multiple different pointers. This can happen during PHI @@ -660,7 +667,6 @@ getNonLocalPointerDepFromBB(Value *Pointer, uint64_t PointeeSize, SmallVectorImpl<NonLocalDepEntry> &Result, DenseMap<BasicBlock*, Value*> &Visited, bool SkipFirstBlock) { - // Look up the cached info for Pointer. ValueIsLoadPair CacheKey(Pointer, isLoad); @@ -793,6 +799,13 @@ getNonLocalPointerDepFromBB(Value *Pointer, uint64_t PointeeSize, BasicBlock *Pred = *PI; Value *PredPtr = PtrPHI->getIncomingValueForBlock(Pred); + // If Pointer is a bitcast instruction, chomp through to the pointee since + // they are must alias. This increases the effectiveness of caching by + // finding more equivalences, avoids having to phi translate the bitcast, and + // avoids conflicts where we are looking for two "different" values in the + // same block when they are really just must aliases. + PredPtr = PredPtr->stripPointerCasts(); + // Check to see if we have already visited this pred block with another // pointer. If so, we can't do this lookup. This failure can occur // with PHI translation when a critical edge exists and the PHI node in diff --git a/llvm/test/Transforms/GVN/rle.ll b/llvm/test/Transforms/GVN/rle.ll index 503a5bbacd1..1c5ab676f7d 100644 --- a/llvm/test/Transforms/GVN/rle.ll +++ b/llvm/test/Transforms/GVN/rle.ll @@ -141,6 +141,32 @@ Cont: ; CHECK: ret i8 %A } +;; non-local i32/float -> i8 load forwarding. This also tests that the "P3" +;; bitcast equivalence can be properly phi translated. +define i8 @coerce_mustalias_nonlocal1(i32* %P, i1 %cond) { + %P2 = bitcast i32* %P to float* + br i1 %cond, label %T, label %F +T: + store i32 42, i32* %P + br label %Cont + +F: + store float 1.0, float* %P2 + br label %Cont + +Cont: + %P3 = bitcast i32* %P to i8* + %A = load i8* %P3 + ret i8 %A + +; CHECK: @coerce_mustalias_nonlocal1 +; CHECK: Cont: +; CHECK: %A = phi i8 [ +; CHECK-NOT: load +; CHECK: ret i8 %A +} + + ;; non-local i32 -> i8 partial redundancy load forwarding. define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) { %P3 = bitcast i32* %P to i8* |

