@@ -2300,16 +2300,9 @@ CollectAddOperandsWithScales(SmallDenseMap<const SCEV *, APInt, 16> &M,
2300
2300
return Interesting;
2301
2301
}
2302
2302
2303
- namespace {
2304
- enum class OverflowCheckTy { WillOverflow, WillNotOverflow };
2305
- }
2306
-
2307
- // Return true if (LHS BinOp RHS) is guaranteed to overflow (if \p Check is
2308
- // WillOverflow) or to not overflow (if \p Check is WillNotOverflow).
2309
- static bool checkOverflow(OverflowCheckTy Check, ScalarEvolution *SE,
2310
- Instruction::BinaryOps BinOp, bool Signed,
2311
- const SCEV *LHS, const SCEV *RHS,
2312
- const Instruction *CtxI) {
2303
+ bool ScalarEvolution::willNotOverflow(Instruction::BinaryOps BinOp, bool Signed,
2304
+ const SCEV *LHS, const SCEV *RHS,
2305
+ const Instruction *CtxI) {
2313
2306
const SCEV *(ScalarEvolution::*Operation)(const SCEV *, const SCEV *,
2314
2307
SCEV::NoWrapFlags, unsigned);
2315
2308
switch (BinOp) {
@@ -2335,12 +2328,12 @@ static bool checkOverflow(OverflowCheckTy Check, ScalarEvolution *SE,
2335
2328
auto *WideTy =
2336
2329
IntegerType::get(NarrowTy->getContext(), NarrowTy->getBitWidth() * 2);
2337
2330
2338
- const SCEV *A = (SE ->*Extension)(
2339
- (SE ->*Operation)(LHS, RHS, SCEV::FlagAnyWrap, 0), WideTy, 0);
2340
- const SCEV *LHSB = (SE ->*Extension)(LHS, WideTy, 0);
2341
- const SCEV *RHSB = (SE ->*Extension)(RHS, WideTy, 0);
2342
- const SCEV *B = (SE ->*Operation)(LHSB, RHSB, SCEV::FlagAnyWrap, 0);
2343
- if (Check == OverflowCheckTy::WillNotOverflow && A == B)
2331
+ const SCEV *A = (this ->*Extension)(
2332
+ (this ->*Operation)(LHS, RHS, SCEV::FlagAnyWrap, 0), WideTy, 0);
2333
+ const SCEV *LHSB = (this ->*Extension)(LHS, WideTy, 0);
2334
+ const SCEV *RHSB = (this ->*Extension)(RHS, WideTy, 0);
2335
+ const SCEV *B = (this ->*Operation)(LHSB, RHSB, SCEV::FlagAnyWrap, 0);
2336
+ if (A == B)
2344
2337
return true;
2345
2338
// Can we use context to prove the fact we need?
2346
2339
if (!CtxI)
@@ -2368,31 +2361,21 @@ static bool checkOverflow(OverflowCheckTy Check, ScalarEvolution *SE,
2368
2361
}
2369
2362
2370
2363
ICmpInst::Predicate Pred = Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
2371
- if (Check == OverflowCheckTy::WillOverflow)
2372
- Pred = CmpInst::getInversePredicate(Pred);
2373
-
2374
2364
if (OverflowDown) {
2375
2365
// To avoid overflow down, we need to make sure that MIN + Magnitude <= LHS.
2376
2366
APInt Min = Signed ? APInt::getSignedMinValue(NumBits)
2377
2367
: APInt::getMinValue(NumBits);
2378
2368
APInt Limit = Min + Magnitude;
2379
- return SE-> isKnownPredicateAt(Pred, SE-> getConstant(Limit), LHS, CtxI);
2369
+ return isKnownPredicateAt(Pred, getConstant(Limit), LHS, CtxI);
2380
2370
} else {
2381
2371
// To avoid overflow up, we need to make sure that LHS <= MAX - Magnitude.
2382
2372
APInt Max = Signed ? APInt::getSignedMaxValue(NumBits)
2383
2373
: APInt::getMaxValue(NumBits);
2384
2374
APInt Limit = Max - Magnitude;
2385
- return SE-> isKnownPredicateAt(Pred, LHS, SE-> getConstant(Limit), CtxI);
2375
+ return isKnownPredicateAt(Pred, LHS, getConstant(Limit), CtxI);
2386
2376
}
2387
2377
}
2388
2378
2389
- bool ScalarEvolution::willNotOverflow(Instruction::BinaryOps BinOp, bool Signed,
2390
- const SCEV *LHS, const SCEV *RHS,
2391
- const Instruction *CtxI) {
2392
- return checkOverflow(OverflowCheckTy::WillNotOverflow, this, BinOp, Signed,
2393
- LHS, RHS, CtxI);
2394
- }
2395
-
2396
2379
std::optional<SCEV::NoWrapFlags>
2397
2380
ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp(
2398
2381
const OverflowingBinaryOperator *OBO) {
@@ -14987,11 +14970,6 @@ const SCEVAddRecExpr *ScalarEvolution::convertSCEVToAddRecWithPredicates(
14987
14970
continue;
14988
14971
14989
14972
ExitCount = getTruncateOrSignExtend(ExitCount, Step->getType());
14990
- if (checkOverflow(OverflowCheckTy::WillOverflow, this, Instruction::Add,
14991
- /*CheckSigned=*/true, AddRecToCheck->getStart(),
14992
- ExitCount, nullptr)) {
14993
- return nullptr;
14994
- }
14995
14973
const SCEV *Add = getAddExpr(AddRecToCheck->getStart(), ExitCount);
14996
14974
if (isKnownPredicate(CmpInst::ICMP_SLT, Add, AddRecToCheck->getStart())) {
14997
14975
return nullptr;
0 commit comments