[llvm-commits] [llvm] r89981 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp test/Transforms/GVN/rle-phi-translate.ll
Chris Lattner
sabre at nondot.org
Thu Nov 26 16:34:38 PST 2009
Author: lattner
Date: Thu Nov 26 18:34:38 2009
New Revision: 89981
URL: http://llvm.org/viewvc/llvm-project?rev=89981&view=rev
Log:
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
Modified:
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=89981&r1=89980&r2=89981&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Thu Nov 26 18:34:38 2009
@@ -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 @@
/// 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 @@
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 @@
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)
Modified: llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll?rev=89981&r1=89980&r2=89981&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll (original)
+++ llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll Thu Nov 26 18:34:38 2009
@@ -86,3 +86,29 @@
ret i32 %dv
}
+; PR5313
+define i32 @test4(i1 %cond, i32* %b, i32* %c) nounwind {
+; CHECK: @test4
+entry:
+ br i1 %cond, label %bb, label %bb1
+
+bb:
+ store i32 4, i32* %b
+ br label %bb2
+
+bb1:
+ %c1 = getelementptr i32* %c, i32 7
+ store i32 82, i32* %c1
+ br label %bb2
+
+bb2:
+ %d = phi i32* [ %c, %bb1 ], [ %b, %bb ]
+ %i = phi i32 [ 7, %bb1 ], [ 0, %bb ]
+ %d1 = getelementptr i32* %d, i32 %i
+ %dv = load i32* %d1
+; CHECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ]
+; CHECK-NOT: load
+; CHECK: ret i32 %dv
+ ret i32 %dv
+}
+
More information about the llvm-commits
mailing list