From 8bdc6920cdd1fd51e5af1537462c30c06203fe85 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 12 Dec 2008 17:09:07 +0000 Subject: [PATCH] Revert my re-instated reverted commit, fixes the bootstrap build on x86-64 linux. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60951 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 30 +++++++++---------- .../ScalarEvolution/2008-12-08-FiniteSGE.ll | 1 + .../2008-12-11-SMaxOverflow.ll | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 1dd5026d749..2b714de3b3f 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2924,12 +2924,8 @@ bool ScalarEvolutionsImpl::potentialInfiniteLoop(SCEV *Stride, SCEV *RHS, if (!R) return true; - if (isSigned) { - if (SC->getValue()->isOne()) - return R->getValue()->isMaxValue(true); - + if (isSigned) return true; // XXX: because we don't have an sdiv scev. - } // If negative, it wraps around every iteration, but we don't care about that. APInt S = SC->getValue()->getValue().abs(); @@ -2975,6 +2971,14 @@ HowManyLessThans(SCEV *LHS, SCEV *RHS, const Loop *L, // run (m-n)/s times. SCEVHandle End = RHS; + if (!executesAtLeastOnce(L, isSigned, trueWhenEqual, + SE.getMinusSCEV(Start, One), RHS)) { + // If not, we get the value of the LHS in the first iteration in which + // the above condition doesn't hold. This equals to max(m,n). + End = isSigned ? SE.getSMaxExpr(RHS, Start) + : SE.getUMaxExpr(RHS, Start); + } + // If the expression is less-than-or-equal to, we need to extend the // loop by one iteration. // @@ -2983,16 +2987,12 @@ HowManyLessThans(SCEV *LHS, SCEV *RHS, const Loop *L, // division would equal one, but the loop runs twice putting the // induction variable at 12. - if (trueWhenEqual) - End = SE.getAddExpr(End, One); - - if (!executesAtLeastOnce(L, isSigned, trueWhenEqual, - SE.getMinusSCEV(Start, One), RHS)) { - // If not, we get the value of the LHS in the first iteration in which - // the above condition doesn't hold. This equals to max(m,n). - End = isSigned ? SE.getSMaxExpr(End, Start) - : SE.getUMaxExpr(End, Start); - } + if (!trueWhenEqual) + // (Stride - 1) is correct only because we know it's unsigned. + // What we really want is to decrease the magnitude of Stride by one. + Start = SE.getMinusSCEV(Start, SE.getMinusSCEV(Stride, One)); + else + Start = SE.getMinusSCEV(Start, Stride); // Finally, we subtract these two values to get the number of times the // backedge is executed: max(m,n)-n. diff --git a/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll b/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll index a9a7c056585..1bf24d7f487 100644 --- a/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll +++ b/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll @@ -1,4 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {255 iterations} +; XFAIL: * define i32 @foo(i32 %x, i32 %y, i32* %lam, i32* %alp) nounwind { bb1.thread: diff --git a/test/Analysis/ScalarEvolution/2008-12-11-SMaxOverflow.ll b/test/Analysis/ScalarEvolution/2008-12-11-SMaxOverflow.ll index 1e8787d0944..9703bcb1542 100644 --- a/test/Analysis/ScalarEvolution/2008-12-11-SMaxOverflow.ll +++ b/test/Analysis/ScalarEvolution/2008-12-11-SMaxOverflow.ll @@ -1,4 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {0 smax} +; XFAIL: * define i32 @f(i32 %c.idx.val) {