[llvm-branch-commits] [llvm] 5d2eda7 - [ConstraintElim] fix crash with large constants in mul nsw
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Aug 30 08:08:18 PDT 2023
Author: Erik Desjardins
Date: 2023-08-30T16:57:47+02:00
New Revision: 5d2eda78bce64798fa0fb298f0726b2baa5c9e40
URL: https://github.com/llvm/llvm-project/commit/5d2eda78bce64798fa0fb298f0726b2baa5c9e40
DIFF: https://github.com/llvm/llvm-project/commit/5d2eda78bce64798fa0fb298f0726b2baa5c9e40.diff
LOG: [ConstraintElim] fix crash with large constants in mul nsw
Another case of https://github.com/llvm/llvm-project/issues/55085.
The added test would trip an assertion due to calling `getSExtValue()` on a value that doesn't fit in int64_t.
Differential Revision: https://reviews.llvm.org/D158810
(cherry picked from commit 66ec5df3a7f33366455d50769e4e878544becea6)
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 15628d32280d8e..2b88dd08d88b66 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -424,7 +424,7 @@ static Decomposition decompose(Value *V,
return MergeResults(Op0, Op1, IsSigned);
ConstantInt *CI;
- if (match(V, m_NSWMul(m_Value(Op0), m_ConstantInt(CI)))) {
+ if (match(V, m_NSWMul(m_Value(Op0), m_ConstantInt(CI))) && canUseSExt(CI)) {
auto Result = decompose(Op0, Preconditions, IsSigned, DL);
Result.mul(CI->getSExtValue());
return Result;
diff --git a/llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll b/llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
index fa8a4a60eac145..ae49ff9063fbed 100644
--- a/llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
+++ b/llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
@@ -282,6 +282,19 @@ else:
ret i1 false
}
+define i1 @mul_nsw_decomp(i128 %x) {
+ %val = mul nsw i128 %x, 9223372036854775808
+ %cmp = icmp sgt i128 %x, %val
+ br i1 %cmp, label %then, label %else
+
+then:
+ %cmp2 = icmp sgt i128 %x, 0
+ ret i1 %cmp2
+
+else:
+ ret i1 false
+}
+
define i1 @add_nuw_decomp_recursive() {
; CHECK-LABEL: @add_nuw_decomp_recursive(
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i64 -9223372036854775808, 10
More information about the llvm-branch-commits
mailing list