[llvm] [SCEV] Check bitwidth for constant ranges comparison (PR #150364)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 20:37:57 PDT 2025
https://github.com/annamthomas created https://github.com/llvm/llvm-project/pull/150364
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.
>From 5c94201de6123b7c27d0b571734cc119b622e960 Mon Sep 17 00:00:00 2001
From: Anna Thomas <anna at azul.com>
Date: Wed, 23 Jul 2025 23:33:54 -0400
Subject: [PATCH] [SCEV] Check bitwidth for constant ranges comparison
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/lib/Analysis/ScalarEvolution.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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
More information about the llvm-commits
mailing list