Skip to content

Commit 88f858d

Browse files
authored
IndVarSimplify: thread CmpPredicate to SCEV (NFC) (#125240)
Relevant parts of ScalarEvolution's API accept a CmpPredicate instead of a CmpInst::Predicate after 60dc450 (SCEV: migrate to CmpPredicate (NFC)). After auditing the callers of these APIs, it was found that IndVarSimplify was dropping samesign information. Fix this.
1 parent 759ef58 commit 88f858d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,14 +1262,14 @@ static std::optional<Value *>
12621262
createReplacement(ICmpInst *ICmp, const Loop *L, BasicBlock *ExitingBB,
12631263
const SCEV *MaxIter, bool Inverted, bool SkipLastIter,
12641264
ScalarEvolution *SE, SCEVExpander &Rewriter) {
1265-
ICmpInst::Predicate Pred = ICmp->getPredicate();
1265+
CmpPredicate Pred = ICmp->getCmpPredicate();
12661266
Value *LHS = ICmp->getOperand(0);
12671267
Value *RHS = ICmp->getOperand(1);
12681268

12691269
// 'LHS pred RHS' should now mean that we stay in loop.
12701270
auto *BI = cast<BranchInst>(ExitingBB->getTerminator());
12711271
if (Inverted)
1272-
Pred = CmpInst::getInversePredicate(Pred);
1272+
Pred = ICmpInst::getInverseCmpPredicate(Pred);
12731273

12741274
const SCEV *LHSS = SE->getSCEVAtScope(LHS, L);
12751275
const SCEV *RHSS = SE->getSCEVAtScope(RHS, L);

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ bool SimplifyIndvar::makeIVComparisonInvariant(ICmpInst *ICmp,
205205
if (!Preheader)
206206
return false;
207207
unsigned IVOperIdx = 0;
208-
ICmpInst::Predicate Pred = ICmp->getPredicate();
208+
CmpPredicate Pred = ICmp->getCmpPredicate();
209209
if (IVOperand != ICmp->getOperand(0)) {
210210
// Swapped
211211
assert(IVOperand == ICmp->getOperand(1) && "Can't find IVOperand");
212212
IVOperIdx = 1;
213-
Pred = ICmpInst::getSwappedPredicate(Pred);
213+
Pred = ICmpInst::getSwappedCmpPredicate(Pred);
214214
}
215215

216216
// Get the SCEVs for the ICmp operands (in the specific context of the
@@ -249,13 +249,13 @@ bool SimplifyIndvar::makeIVComparisonInvariant(ICmpInst *ICmp,
249249
void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp,
250250
Instruction *IVOperand) {
251251
unsigned IVOperIdx = 0;
252-
ICmpInst::Predicate Pred = ICmp->getPredicate();
252+
CmpPredicate Pred = ICmp->getCmpPredicate();
253253
ICmpInst::Predicate OriginalPred = Pred;
254254
if (IVOperand != ICmp->getOperand(0)) {
255255
// Swapped
256256
assert(IVOperand == ICmp->getOperand(1) && "Can't find IVOperand");
257257
IVOperIdx = 1;
258-
Pred = ICmpInst::getSwappedPredicate(Pred);
258+
Pred = ICmpInst::getSwappedCmpPredicate(Pred);
259259
}
260260

261261
// Get the SCEVs for the ICmp operands (in the specific context of the

0 commit comments

Comments
 (0)