llvm.org GIT mirror llvm / 277a147
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60881 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 11 years ago
3 changed file(s) with 42 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
29232923 if (!R)
29242924 return true;
29252925
2926 if (isSigned)
2926 if (isSigned) {
2927 if (SC->getValue()->isOne())
2928 return R->getValue()->isMaxValue(true);
2929
29272930 return true; // XXX: because we don't have an sdiv scev.
2931 }
29282932
29292933 // If negative, it wraps around every iteration, but we don't care about that.
29302934 APInt S = SC->getValue()->getValue().abs();
29702974 // run (m-n)/s times.
29712975 SCEVHandle End = RHS;
29722976
2973 if (!executesAtLeastOnce(L, isSigned, trueWhenEqual,
2974 SE.getMinusSCEV(Start, One), RHS)) {
2975 // If not, we get the value of the LHS in the first iteration in which
2976 // the above condition doesn't hold. This equals to max(m,n).
2977 End = isSigned ? SE.getSMaxExpr(RHS, Start)
2978 : SE.getUMaxExpr(RHS, Start);
2979 }
2980
29812977 // If the expression is less-than-or-equal to, we need to extend the
29822978 // loop by one iteration.
29832979 //
29862982 // division would equal one, but the loop runs twice putting the
29872983 // induction variable at 12.
29882984
2989 if (!trueWhenEqual)
2990 // (Stride - 1) is correct only because we know it's unsigned.
2991 // What we really want is to decrease the magnitude of Stride by one.
2992 Start = SE.getMinusSCEV(Start, SE.getMinusSCEV(Stride, One));
2993 else
2994 Start = SE.getMinusSCEV(Start, Stride);
2985 if (trueWhenEqual)
2986 End = SE.getAddExpr(End, One);
2987
2988 if (!executesAtLeastOnce(L, isSigned, trueWhenEqual,
2989 SE.getMinusSCEV(Start, One), RHS)) {
2990 // If not, we get the value of the LHS in the first iteration in which
2991 // the above condition doesn't hold. This equals to max(m,n).
2992 End = isSigned ? SE.getSMaxExpr(End, Start)
2993 : SE.getUMaxExpr(End, Start);
2994 }
29952995
29962996 // Finally, we subtract these two values to get the number of times the
29972997 // backedge is executed: max(m,n)-n.
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {255 iterations}
1 ; XFAIL: *
21
32 define i32 @foo(i32 %x, i32 %y, i32* %lam, i32* %alp) nounwind {
43 bb1.thread:
0 ; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {0 smax}
1
2 define i32 @f(i32 %c.idx.val) {
3
4 bb2:
5 %k.018 = add i32 %c.idx.val, -1 ; [#uses=2]
6 %a14 = icmp slt i32 %k.018, 0 ; [#uses=1]
7 br i1 %a14, label %bb19, label %bb16.preheader
8
9 bb16.preheader:
10 %k.019 = phi i32 [ %k.0, %bb18 ], [ %k.018, %bb2 ] ; [#uses=5]
11 %x = phi i32 [ 0, %bb2 ], [ %x.1, %bb18]
12 br label %bb18
13
14 bb18: ; preds = %bb18.loopexit
15 %x.1 = add i32 %x, 1
16 %k.0 = add i32 %k.019, -1 ; [#uses=2]
17 %a107 = icmp slt i32 %k.0, 0 ; [#uses=1]
18 br i1 %a107, label %bb18.bb19_crit_edge, label %bb16.preheader
19
20 bb18.bb19_crit_edge:
21 ret i32 %x
22
23 bb19:
24 ret i32 0
25
26 }