Skip to content

Commit 29065eb

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 448c6db commit 29065eb

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
@@ -11228,8 +11228,7 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
1122811228
XNonConstOp = X;
1122911229
XFlagsPresent = ExpectedFlags;
1123011230
}
11231-
if (!isa<SCEVConstant>(XConstOp) ||
11232-
(XFlagsPresent & ExpectedFlags) != ExpectedFlags)
11231+
if (!isa<SCEVConstant>(XConstOp))
1123311232
return false;
1123411233

1123511234
if (!splitBinaryAdd(Y, YConstOp, YNonConstOp, YFlagsPresent)) {
@@ -11238,13 +11237,22 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
1123811237
YFlagsPresent = ExpectedFlags;
1123911238
}
1124011239

11241-
if (!isa<SCEVConstant>(YConstOp) ||
11242-
(YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11240+
if (YNonConstOp != XNonConstOp)
1124311241
return false;
1124411242

11245-
if (YNonConstOp != XNonConstOp)
11243+
if (!isa<SCEVConstant>(YConstOp))
1124611244
return false;
1124711245

11246+
if (YNonConstOp != Y && ExpectedFlags == SCEV::FlagNUW) {
11247+
if ((YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11248+
return false;
11249+
} else {
11250+
if ((XFlagsPresent & ExpectedFlags) != ExpectedFlags)
11251+
return false;
11252+
if ((YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11253+
return false;
11254+
}
11255+
1124811256
OutC1 = cast<SCEVConstant>(XConstOp)->getAPInt();
1124911257
OutC2 = cast<SCEVConstant>(YConstOp)->getAPInt();
1125011258

0 commit comments

Comments
 (0)