[llvm-commits] [llvm] r71354 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Analysis/ScalarEvolution/2009-05-09-PointerEdgeCount.ll
Eli Friedman
eli.friedman at gmail.com
Sat May 9 05:32:47 PDT 2009
Author: efriedma
Date: Sat May 9 07:32:42 2009
New Revision: 71354
URL: http://llvm.org/viewvc/llvm-project?rev=71354&view=rev
Log:
Allow scalar evolution to compute iteration counts for loops with a
pointer-based condition. This fixes PR3171.
Added:
llvm/trunk/test/Analysis/ScalarEvolution/2009-05-09-PointerEdgeCount.ll
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=71354&r1=71353&r2=71354&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sat May 9 07:32:42 2009
@@ -2372,10 +2372,8 @@
ICmpInst *ExitCond = dyn_cast<ICmpInst>(ExitBr->getCondition());
- // If it's not an integer comparison then compute it the hard way.
- // Note that ICmpInst deals with pointer comparisons too so we must check
- // the type of the operand.
- if (ExitCond == 0 || isa<PointerType>(ExitCond->getOperand(0)->getType()))
+ // If it's not an integer or pointer comparison then compute it the hard way.
+ if (ExitCond == 0)
return ComputeBackedgeTakenCountExhaustively(L, ExitBr->getCondition(),
ExitBr->getSuccessor(0) == ExitBlock);
@@ -2416,21 +2414,12 @@
if (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS))
if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(LHS))
if (AddRec->getLoop() == L) {
- // Form the comparison range using the constant of the correct type so
- // that the ConstantRange class knows to do a signed or unsigned
- // comparison.
- ConstantInt *CompVal = RHSC->getValue();
- const Type *RealTy = ExitCond->getOperand(0)->getType();
- CompVal = dyn_cast<ConstantInt>(
- ConstantExpr::getBitCast(CompVal, RealTy));
- if (CompVal) {
- // Form the constant range.
- ConstantRange CompRange(
- ICmpInst::makeConstantRange(Cond, CompVal->getValue()));
+ // Form the constant range.
+ ConstantRange CompRange(
+ ICmpInst::makeConstantRange(Cond, RHSC->getValue()->getValue()));
- SCEVHandle Ret = AddRec->getNumIterationsInRange(CompRange, *this);
- if (!isa<SCEVCouldNotCompute>(Ret)) return Ret;
- }
+ SCEVHandle Ret = AddRec->getNumIterationsInRange(CompRange, *this);
+ if (!isa<SCEVCouldNotCompute>(Ret)) return Ret;
}
switch (Cond) {
Added: llvm/trunk/test/Analysis/ScalarEvolution/2009-05-09-PointerEdgeCount.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/2009-05-09-PointerEdgeCount.ll?rev=71354&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/2009-05-09-PointerEdgeCount.ll (added)
+++ llvm/trunk/test/Analysis/ScalarEvolution/2009-05-09-PointerEdgeCount.ll Sat May 9 07:32:42 2009
@@ -0,0 +1,27 @@
+; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {count is 2}
+; PR3171
+
+ %struct.Foo = type { i32 }
+ %struct.NonPod = type { [2 x %struct.Foo] }
+
+define void @_Z3foov() nounwind {
+entry:
+ %x = alloca %struct.NonPod, align 8 ; <%struct.NonPod*> [#uses=2]
+ %0 = getelementptr %struct.NonPod* %x, i32 0, i32 0 ; <[2 x %struct.Foo]*> [#uses=1]
+ %1 = getelementptr [2 x %struct.Foo]* %0, i32 1, i32 0 ; <%struct.Foo*> [#uses=1]
+ br label %bb1.i
+
+bb1.i: ; preds = %bb2.i, %entry
+ %.0.i = phi %struct.Foo* [ %1, %entry ], [ %4, %bb2.i ] ; <%struct.Foo*> [#uses=2]
+ %2 = getelementptr %struct.NonPod* %x, i32 0, i32 0, i32 0 ; <%struct.Foo*> [#uses=1]
+ %3 = icmp eq %struct.Foo* %.0.i, %2 ; <i1> [#uses=1]
+ br i1 %3, label %_ZN6NonPodD1Ev.exit, label %bb2.i
+
+bb2.i: ; preds = %bb1.i
+ %4 = getelementptr %struct.Foo* %.0.i, i32 -1 ; <%struct.Foo*> [#uses=1]
+ br label %bb1.i
+
+_ZN6NonPodD1Ev.exit: ; preds = %bb1.i
+ ret void
+}
+
More information about the llvm-commits
mailing list