[llvm] SCEV: thread samesign in isBasicBlockEntryGuardedByCond (NFC) (PR #125840)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 03:33:41 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Ramkumar Ramachandra (artagnon)
<details>
<summary>Changes</summary>
isBasicBlockEntryGuardedByCond inadvertedenly drops samesign information when calling ICmpInst::getNonStrictPredicate. Fix this.
---
Full diff: https://github.com/llvm/llvm-project/pull/125840.diff
2 Files Affected:
- (modified) llvm/include/llvm/IR/Instructions.h (+12)
- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+3-2)
``````````diff
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 0d7bbe3f996408..1673dc3acd2a12 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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/125840
More information about the llvm-commits
mailing list