mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Sneaky, sneaky: move the -1 to the outside of the SMax. Reinstate the
optimization of SGE/SLE with unit stride, now that it works properly. llvm-svn: 60881
This commit is contained in:
parent
74411f221b
commit
312d95be37
@ -2924,8 +2924,12 @@ bool ScalarEvolutionsImpl::potentialInfiniteLoop(SCEV *Stride, SCEV *RHS,
|
||||
if (!R)
|
||||
return true;
|
||||
|
||||
if (isSigned)
|
||||
if (isSigned) {
|
||||
if (SC->getValue()->isOne())
|
||||
return R->getValue()->isMaxValue(true);
|
||||
|
||||
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();
|
||||
@ -2971,14 +2975,6 @@ 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.
|
||||
//
|
||||
@ -2987,12 +2983,16 @@ 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)
|
||||
// (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);
|
||||
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);
|
||||
}
|
||||
|
||||
// Finally, we subtract these two values to get the number of times the
|
||||
// backedge is executed: max(m,n)-n.
|
||||
|
@ -1,5 +1,4 @@
|
||||
; 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:
|
||||
|
27
test/Analysis/ScalarEvolution/2008-12-11-SMaxOverflow.ll
Normal file
27
test/Analysis/ScalarEvolution/2008-12-11-SMaxOverflow.ll
Normal file
@ -0,0 +1,27 @@
|
||||
; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {0 smax}
|
||||
|
||||
define i32 @f(i32 %c.idx.val) {
|
||||
|
||||
bb2:
|
||||
%k.018 = add i32 %c.idx.val, -1 ; <i32> [#uses=2]
|
||||
%a14 = icmp slt i32 %k.018, 0 ; <i1> [#uses=1]
|
||||
br i1 %a14, label %bb19, label %bb16.preheader
|
||||
|
||||
bb16.preheader:
|
||||
%k.019 = phi i32 [ %k.0, %bb18 ], [ %k.018, %bb2 ] ; <i32> [#uses=5]
|
||||
%x = phi i32 [ 0, %bb2 ], [ %x.1, %bb18]
|
||||
br label %bb18
|
||||
|
||||
bb18: ; preds = %bb18.loopexit
|
||||
%x.1 = add i32 %x, 1
|
||||
%k.0 = add i32 %k.019, -1 ; <i32> [#uses=2]
|
||||
%a107 = icmp slt i32 %k.0, 0 ; <i1> [#uses=1]
|
||||
br i1 %a107, label %bb18.bb19_crit_edge, label %bb16.preheader
|
||||
|
||||
bb18.bb19_crit_edge:
|
||||
ret i32 %x
|
||||
|
||||
bb19:
|
||||
ret i32 0
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user