-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[SCEV] Check bitwidth for constant ranges comparison #150364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
@llvm/pr-subscribers-llvm-analysis Author: None (annamthomas) ChangesFix a crash if using isKnownPredicate with differing SCEV types. Full diff: https://github.com/llvm/llvm-project/pull/150364.diff 1 Files Affected:
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
|
I think this should at least be an assert? I used the |
Yes, this should be an assert. These APIs generally assume matching types. |
Yep, I thought we would have that in the documentation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this triggered by a caller passing mismatching types here that needs updating?
Yep, basically I was adding a fast path downstream to What is not clear to me is that we sometimes convert to wider types before using this API, but at other times we do not. Also, when I tried asserting for SCEV matching types in I don't think we really need to add an assert at the |
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.