Skip to content

Commit 8938362

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 ab03116 commit 8938362

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
@@ -11231,8 +11231,7 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
1123111231
XNonConstOp = X;
1123211232
XFlagsPresent = ExpectedFlags;
1123311233
}
11234-
if (!isa<SCEVConstant>(XConstOp) ||
11235-
(XFlagsPresent & ExpectedFlags) != ExpectedFlags)
11234+
if (!isa<SCEVConstant>(XConstOp))
1123611235
return false;
1123711236

1123811237
if (!splitBinaryAdd(Y, YConstOp, YNonConstOp, YFlagsPresent)) {
@@ -11241,13 +11240,22 @@ bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred,
1124111240
YFlagsPresent = ExpectedFlags;
1124211241
}
1124311242

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

11248-
if (YNonConstOp != XNonConstOp)
11246+
if (!isa<SCEVConstant>(YConstOp))
1124911247
return false;
1125011248

11249+
if (YNonConstOp != Y && ExpectedFlags == SCEV::FlagNUW) {
11250+
if ((YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11251+
return false;
11252+
} else {
11253+
if ((XFlagsPresent & ExpectedFlags) != ExpectedFlags)
11254+
return false;
11255+
if ((YFlagsPresent & ExpectedFlags) != ExpectedFlags)
11256+
return false;
11257+
}
11258+
1125111259
OutC1 = cast<SCEVConstant>(XConstOp)->getAPInt();
1125211260
OutC2 = cast<SCEVConstant>(YConstOp)->getAPInt();
1125311261

0 commit comments

Comments
 (0)