diff options
author | Chris Lattner <sabre@nondot.org> | 2009-11-27 00:34:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-11-27 00:34:38 +0000 |
commit | e19e4baf3b4f145fad122de7e6a02ed3a68bc082 (patch) | |
tree | 9809e0aee28bbf9b3d16ca3ffb68ef7eea5b988a /lib/Analysis/MemoryDependenceAnalysis.cpp | |
parent | c514c1f5218b8fe7499a0b9a4737860344cf4c43 (diff) | |
download | external_llvm-e19e4baf3b4f145fad122de7e6a02ed3a68bc082.zip external_llvm-e19e4baf3b4f145fad122de7e6a02ed3a68bc082.tar.gz external_llvm-e19e4baf3b4f145fad122de7e6a02ed3a68bc082.tar.bz2 |
teach phi translation of GEPs to simplify geps like 'gep x, 0'.
This allows us to compile the example from PR5313 into:
LBB1_2: ## %bb
incl %ecx
movb %al, (%rsi)
movslq %ecx, %rax
movb (%rdi,%rax), %al
testb %al, %al
jne LBB1_2
instead of:
LBB1_2: ## %bb
movslq %eax, %rcx
incl %eax
movb (%rdi,%rcx), %cl
movb %cl, (%rsi)
movslq %eax, %rcx
cmpb $0, (%rdi,%rcx)
jne LBB1_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89981 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MemoryDependenceAnalysis.cpp')
-rw-r--r-- | lib/Analysis/MemoryDependenceAnalysis.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index 6bffca6..d749751 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -20,6 +20,7 @@ #include "llvm/IntrinsicInst.h" #include "llvm/Function.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/STLExtras.h" @@ -716,7 +717,8 @@ static bool isPHITranslatable(Instruction *Inst) { /// PHITranslateForPred - Given a computation that satisfied the /// isPHITranslatable predicate, see if we can translate the computation into /// the specified predecessor block. If so, return that value. -static Value *PHITranslateForPred(Instruction *Inst, BasicBlock *Pred) { +static Value *PHITranslateForPred(Instruction *Inst, BasicBlock *Pred, + const TargetData *TD) { if (PHINode *PN = dyn_cast<PHINode>(Inst)) return PN->getIncomingValueForBlock(Pred); @@ -751,7 +753,9 @@ static Value *PHITranslateForPred(Instruction *Inst, BasicBlock *Pred) { GEPOps.back() = APHIOp = PN->getIncomingValueForBlock(Pred); } - // TODO: Simplify the GEP to handle 'gep x, 0' -> x etc. + // Simplify the GEP to handle 'gep x, 0' -> x etc. + if (Value *V = SimplifyGEPInst(&GEPOps[0], GEPOps.size(), TD)) + return V; // Scan to see if we have this GEP available. for (Value::use_iterator UI = APHIOp->use_begin(), E = APHIOp->use_end(); @@ -926,7 +930,7 @@ getNonLocalPointerDepFromBB(Value *Pointer, uint64_t PointeeSize, for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) { BasicBlock *Pred = *PI; - Value *PredPtr = PHITranslateForPred(PtrInst, Pred); + Value *PredPtr = PHITranslateForPred(PtrInst, Pred, TD); // If PHI translation fails, bail out. if (PredPtr == 0) |