Skip to content

Commit 3019e49

Browse files
authored
SCEV: thread samesign in isBasicBlockEntryGuardedByCond (NFC) (#125840)
isBasicBlockEntryGuardedByCond inadvertedenly drops samesign information when calling ICmpInst::getNonStrictPredicate. Fix this.
1 parent ec60e1d commit 3019e49

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,18 @@ class ICmpInst: public CmpInst {
12311231
return getSwappedCmpPredicate(getCmpPredicate());
12321232
}
12331233

1234+
/// @returns the non-strict predicate along with samesign information: static
1235+
/// variant.
1236+
static CmpPredicate getNonStrictCmpPredicate(CmpPredicate Pred) {
1237+
return {getNonStrictPredicate(Pred), Pred.hasSameSign()};
1238+
}
1239+
1240+
/// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
1241+
/// @returns the non-strict predicate along with samesign information.
1242+
Predicate getNonStrictCmpPredicate() const {
1243+
return getNonStrictCmpPredicate(getCmpPredicate());
1244+
}
1245+
12341246
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
12351247
/// @returns the predicate that would be the result if the operand were
12361248
/// regarded as signed.

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11632,8 +11632,9 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
1163211632
// non-strict comparison is known from ranges and non-equality is known from
1163311633
// dominating predicates. If we are proving strict comparison, we always try
1163411634
// to prove non-equality and non-strict comparison separately.
11635-
auto NonStrictPredicate = ICmpInst::getNonStrictPredicate(Pred);
11636-
const bool ProvingStrictComparison = (Pred != NonStrictPredicate);
11635+
CmpPredicate NonStrictPredicate = ICmpInst::getNonStrictCmpPredicate(Pred);
11636+
const bool ProvingStrictComparison =
11637+
(Pred != static_cast<CmpInst::Predicate>(NonStrictPredicate));
1163711638
bool ProvedNonStrictComparison = false;
1163811639
bool ProvedNonEquality = false;
1163911640

0 commit comments

Comments
 (0)