Skip to content

Commit 3ec83f5

Browse files
authored
[X86][DAGCombiner] Fix assertion failure in combinei64TruncSrlAdd (llvm#128194)
Closes llvm#128158.
1 parent 998b28f commit 3ec83f5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53712,7 +53712,7 @@ static SDValue combinei64TruncSrlAdd(SDValue N, EVT VT, SelectionDAG &DAG,
5371253712
m_ConstInt(SrlConst)))))
5371353713
return SDValue();
5371453714

53715-
if (SrlConst.ule(31) || AddConst.lshr(SrlConst).shl(SrlConst) != AddConst)
53715+
if (SrlConst.ule(32) || AddConst.lshr(SrlConst).shl(SrlConst) != AddConst)
5371653716
return SDValue();
5371753717

5371853718
SDValue AddLHSSrl =

llvm/test/CodeGen/X86/combine-i64-trunc-srl-add.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,31 @@ define i32 @test_trunc_add(i64 %x) {
123123
%conv = trunc i64 %shr to i32
124124
ret i32 %conv
125125
}
126+
127+
; Make sure we don't crash on this test case.
128+
129+
define i32 @pr128158(i64 %x) {
130+
; X64-LABEL: pr128158:
131+
; X64: # %bb.0: # %entry
132+
; X64-NEXT: movabsq $-4294967296, %rax # imm = 0xFFFFFFFF00000000
133+
; X64-NEXT: addq %rdi, %rax
134+
; X64-NEXT: shrq $32, %rax
135+
; X64-NEXT: .p2align 4
136+
; X64-NEXT: .LBB9_1: # %for.body
137+
; X64-NEXT: # =>This Inner Loop Header: Depth=1
138+
; X64-NEXT: cmpl $9, %eax
139+
; X64-NEXT: jb .LBB9_1
140+
; X64-NEXT: # %bb.2: # %exit
141+
; X64-NEXT: xorl %eax, %eax
142+
; X64-NEXT: retq
143+
entry:
144+
br label %for.body
145+
146+
for.body:
147+
%add = add i64 %x, -4294967296
148+
%cmp = icmp ult i64 %add, 38654705664
149+
br i1 %cmp, label %for.body, label %exit
150+
151+
exit:
152+
ret i32 0
153+
}

0 commit comments

Comments
 (0)