llvm.org GIT mirror llvm / 2ceba77
Bugfix: SCEV incorrectly marks certain add recurrences as nsw When creating a scev for sext({X,+,Y}), scev checks if the expression is equivalent to {sext X,+,zext Y}. If it can prove that, it also tags the original {X,+,Y} as <nsw>, which is not correct. In the test case I run `-scalar-evolution` twice because the bug manifests only once SCEV has run through and seen the `sext` expressions (and then does a in-place mutation on {X,+,Y}). Differential Revision: http://reviews.llvm.org/D7495 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228586 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 5 years ago
2 changed file(s) with 36 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
15491549 getMulExpr(WideMaxBECount,
15501550 getZeroExtendExpr(Step, WideTy)));
15511551 if (SAdd == OperandExtendedAdd) {
1552 // Cache knowledge of AR NSW, which is propagated to this AddRec.
1553 const_cast(AR)->setNoWrapFlags(SCEV::FlagNSW);
1552 // If AR wraps around then
1553 //
1554 // abs(Step) * MaxBECount > unsigned-max(AR->getType())
1555 // => SAdd != OperandExtendedAdd
1556 //
1557 // Thus (AR is not NW => SAdd != OperandExtendedAdd) <=>
1558 // (SAdd == OperandExtendedAdd => AR is NW)
1559
1560 const_cast(AR)->setNoWrapFlags(SCEV::FlagNW);
1561
15541562 // Return the expression with the addrec on the outside.
15551563 return getAddRecExpr(getSignExtendAddRecStart(AR, Ty, this),
15561564 getZeroExtendExpr(Step, Ty),
0 ; RUN: opt -analyze -scalar-evolution -scalar-evolution < %s | FileCheck %s
1
2 define void @bad.nsw() {
3 ; CHECK-LABEL: Classifying expressions for: @bad.nsw
4 ; CHECK-LABEL: Classifying expressions for: @bad.nsw
5 entry:
6 br label %loop
7
8 loop:
9 %i = phi i8 [ -1, %entry ], [ %i.inc, %loop ]
10 ; CHECK: %i = phi i8 [ -1, %entry ], [ %i.inc, %loop ]
11 ; CHECK-NEXT: --> {-1,+,-128}<%loop>
12 ; CHECK-NOT: --> {-1,+,-128}<%loop>
13
14 %counter = phi i8 [ 0, %entry ], [ %counter.inc, %loop ]
15
16 %i.inc = add i8 %i, -128
17 %i.sext = sext i8 %i to i16
18
19 %counter.inc = add i8 %counter, 1
20 %continue = icmp eq i8 %counter, 1
21 br i1 %continue, label %exit, label %loop
22
23 exit:
24 ret void
25 }