Skip to content

Commit 66ec5df

Browse files
[ConstraintElim] fix crash with large constants in mul nsw
Another case of #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
1 parent 8d0c3db commit 66ec5df

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static Decomposition decompose(Value *V,
424424
return MergeResults(Op0, Op1, IsSigned);
425425

426426
ConstantInt *CI;
427-
if (match(V, m_NSWMul(m_Value(Op0), m_ConstantInt(CI)))) {
427+
if (match(V, m_NSWMul(m_Value(Op0), m_ConstantInt(CI))) && canUseSExt(CI)) {
428428
auto Result = decompose(Op0, Preconditions, IsSigned, DL);
429429
Result.mul(CI->getSExtValue());
430430
return Result;

llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ else:
280280
ret i1 false
281281
}
282282

283+
define i1 @mul_nsw_decomp(i128 %x) {
284+
%val = mul nsw i128 %x, 9223372036854775808
285+
%cmp = icmp sgt i128 %x, %val
286+
br i1 %cmp, label %then, label %else
287+
288+
then:
289+
%cmp2 = icmp sgt i128 %x, 0
290+
ret i1 %cmp2
291+
292+
else:
293+
ret i1 false
294+
}
295+
283296
define i1 @add_nuw_decomp_recursive() {
284297
; CHECK-LABEL: @add_nuw_decomp_recursive(
285298
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i64 -9223372036854775808, 10

0 commit comments

Comments
 (0)