[llvm] 3019e49 - SCEV: thread samesign in isBasicBlockEntryGuardedByCond (NFC) (#125840)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 06:47:17 PST 2025
Author: Ramkumar Ramachandra
Date: 2025-02-10T14:47:13Z
New Revision: 3019e49ebfc5d710191712b6d437c56c01e65b87
URL: https://github.com/llvm/llvm-project/commit/3019e49ebfc5d710191712b6d437c56c01e65b87
DIFF: https://github.com/llvm/llvm-project/commit/3019e49ebfc5d710191712b6d437c56c01e65b87.diff
LOG: SCEV: thread samesign in isBasicBlockEntryGuardedByCond (NFC) (#125840)
isBasicBlockEntryGuardedByCond inadvertedenly drops samesign information
when calling ICmpInst::getNonStrictPredicate. Fix this.
Added:
Modified:
llvm/include/llvm/IR/Instructions.h
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 9a41971b63373c..a1f964352207f7 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -1231,6 +1231,18 @@ class ICmpInst: public CmpInst {
return getSwappedCmpPredicate(getCmpPredicate());
}
+ /// @returns the non-strict predicate along with samesign information: static
+ /// variant.
+ static CmpPredicate getNonStrictCmpPredicate(CmpPredicate Pred) {
+ return {getNonStrictPredicate(Pred), Pred.hasSameSign()};
+ }
+
+ /// For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
+ /// @returns the non-strict predicate along with samesign information.
+ Predicate getNonStrictCmpPredicate() const {
+ return getNonStrictCmpPredicate(getCmpPredicate());
+ }
+
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
/// @returns the predicate that would be the result if the operand were
/// regarded as signed.
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 573b052aa4b2ce..8f74c1c398cedb 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -11632,8 +11632,9 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
// non-strict comparison is known from ranges and non-equality is known from
// dominating predicates. If we are proving strict comparison, we always try
// to prove non-equality and non-strict comparison separately.
- auto NonStrictPredicate = ICmpInst::getNonStrictPredicate(Pred);
- const bool ProvingStrictComparison = (Pred != NonStrictPredicate);
+ CmpPredicate NonStrictPredicate = ICmpInst::getNonStrictCmpPredicate(Pred);
+ const bool ProvingStrictComparison =
+ (Pred != static_cast<CmpInst::Predicate>(NonStrictPredicate));
bool ProvedNonStrictComparison = false;
bool ProvedNonEquality = false;
More information about the llvm-commits
mailing list