Skip to content

Commit 1662cbf

Browse files
committed
!fixup strip unneeded changes
1 parent e043144 commit 1662cbf

File tree

1 file changed

+11
-33
lines changed

1 file changed

+11
-33
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,16 +2300,9 @@ CollectAddOperandsWithScales(SmallDenseMap<const SCEV *, APInt, 16> &M,
23002300
return Interesting;
23012301
}
23022302

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) {
23132306
const SCEV *(ScalarEvolution::*Operation)(const SCEV *, const SCEV *,
23142307
SCEV::NoWrapFlags, unsigned);
23152308
switch (BinOp) {
@@ -2335,12 +2328,12 @@ static bool checkOverflow(OverflowCheckTy Check, ScalarEvolution *SE,
23352328
auto *WideTy =
23362329
IntegerType::get(NarrowTy->getContext(), NarrowTy->getBitWidth() * 2);
23372330

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)
23442337
return true;
23452338
// Can we use context to prove the fact we need?
23462339
if (!CtxI)
@@ -2368,31 +2361,21 @@ static bool checkOverflow(OverflowCheckTy Check, ScalarEvolution *SE,
23682361
}
23692362

23702363
ICmpInst::Predicate Pred = Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
2371-
if (Check == OverflowCheckTy::WillOverflow)
2372-
Pred = CmpInst::getInversePredicate(Pred);
2373-
23742364
if (OverflowDown) {
23752365
// To avoid overflow down, we need to make sure that MIN + Magnitude <= LHS.
23762366
APInt Min = Signed ? APInt::getSignedMinValue(NumBits)
23772367
: APInt::getMinValue(NumBits);
23782368
APInt Limit = Min + Magnitude;
2379-
return SE->isKnownPredicateAt(Pred, SE->getConstant(Limit), LHS, CtxI);
2369+
return isKnownPredicateAt(Pred, getConstant(Limit), LHS, CtxI);
23802370
} else {
23812371
// To avoid overflow up, we need to make sure that LHS <= MAX - Magnitude.
23822372
APInt Max = Signed ? APInt::getSignedMaxValue(NumBits)
23832373
: APInt::getMaxValue(NumBits);
23842374
APInt Limit = Max - Magnitude;
2385-
return SE->isKnownPredicateAt(Pred, LHS, SE->getConstant(Limit), CtxI);
2375+
return isKnownPredicateAt(Pred, LHS, getConstant(Limit), CtxI);
23862376
}
23872377
}
23882378

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-
23962379
std::optional<SCEV::NoWrapFlags>
23972380
ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp(
23982381
const OverflowingBinaryOperator *OBO) {
@@ -14987,11 +14970,6 @@ const SCEVAddRecExpr *ScalarEvolution::convertSCEVToAddRecWithPredicates(
1498714970
continue;
1498814971

1498914972
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-
}
1499514973
const SCEV *Add = getAddExpr(AddRecToCheck->getStart(), ExitCount);
1499614974
if (isKnownPredicate(CmpInst::ICMP_SLT, Add, AddRecToCheck->getStart())) {
1499714975
return nullptr;

0 commit comments

Comments
 (0)