[llvm] [SCEV] Check bitwidth for constant ranges comparison (PR #150364)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 20:38:26 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: None (annamthomas)
<details>
<summary>Changes</summary>
Fix a crash if using isKnownPredicate with differing SCEV types.
We don't ever seem to assert that the types are the same and finally
crash when reaching the path of constant range comparisons.
---
Full diff: https://github.com/llvm/llvm-project/pull/150364.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+2-1)
``````````diff
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 24adfa346c642..e535845c9a358 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -11380,7 +11380,8 @@ bool ScalarEvolution::isKnownPredicateViaConstantRanges(CmpPredicate Pred,
auto CheckRange = [&](bool IsSigned) {
auto RangeLHS = IsSigned ? getSignedRange(LHS) : getUnsignedRange(LHS);
auto RangeRHS = IsSigned ? getSignedRange(RHS) : getUnsignedRange(RHS);
- return RangeLHS.icmp(Pred, RangeRHS);
+ return RangeLHS.getBitWidth() == RangeRHS.getBitWidth() &&
+ RangeLHS.icmp(Pred, RangeRHS);
};
// The check at the top of the function catches the case where the values are
``````````
</details>
https://github.com/llvm/llvm-project/pull/150364
More information about the llvm-commits
mailing list