Skip to content

Commit eed10c9

Browse files
committed
[SCEV] Don't require NUW at first add when checking A+C1 < (A+C2)<nuw>
Relax the NUW requirements for isKnownPredicateViaNoOverflow, if the second operand (Y) is a BinOp. The code only simplifies the condition if C1 < C2, so if the BinOp is NUW, it doesn't matter whether the first operand also has the NUW flag, as it cannot wrap if C1 < C2.
1 parent 9a8305b commit eed10c9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11292,8 +11292,7 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
1129211292
XNonConstOp = X;
1129311293
XFlagsPresent = ExpectedFlags;
1129411294
}
11295-
if (!isa<SCEVConstant>(XConstOp) ||
11296-
(XFlagsPresent & ExpectedFlags) != ExpectedFlags)
11295+
if (!isa<SCEVConstant>(XConstOp))
1129711296
return false;
1129811297

1129911298
if (!splitBinaryAdd(Y, YConstOp, YNonConstOp, YFlagsPresent)) {
@@ -11302,13 +11301,22 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
1130211301
YFlagsPresent = ExpectedFlags;
1130311302
}
1130411303

11305-
if (!isa<SCEVConstant>(YConstOp) ||
11306-
(YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11304+
if (YNonConstOp != XNonConstOp)
1130711305
return false;
1130811306

11309-
if (YNonConstOp != XNonConstOp)
11307+
if (!isa<SCEVConstant>(YConstOp))
1131011308
return false;
1131111309

11310+
if (YNonConstOp != Y && ExpectedFlags == SCEV::FlagNUW) {
11311+
if ((YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11312+
return false;
11313+
} else {
11314+
if ((XFlagsPresent & ExpectedFlags) != ExpectedFlags)
11315+
return false;
11316+
if ((YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11317+
return false;
11318+
}
11319+
1131211320
OutC1 = cast<SCEVConstant>(XConstOp)->getAPInt();
1131311321
OutC2 = cast<SCEVConstant>(YConstOp)->getAPInt();
1131411322

0 commit comments

Comments
 (0)