Skip to content

Commit 1ddf4e3

Browse files
RKSimontru
authored andcommitted
[X86] getTargetConstantBitsFromNode - early-out if the element bitsize doesn't align with the source bitsize (#150184)
As we use getTargetConstantBitsFromNode in a wider variety of places we can't guarantee that all the sources match (or are legal) anymore - better to early out than assert. Fixes #150117 (cherry picked from commit 3345582)
1 parent 6077f45 commit 1ddf4e3

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4997,9 +4997,12 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
49974997

49984998
EVT VT = Op.getValueType();
49994999
unsigned SizeInBits = VT.getSizeInBits();
5000-
assert((SizeInBits % EltSizeInBits) == 0 && "Can't split constant!");
50015000
unsigned NumElts = SizeInBits / EltSizeInBits;
50025001

5002+
// Can't split constant.
5003+
if ((SizeInBits % EltSizeInBits) != 0)
5004+
return false;
5005+
50035006
// Bitcast a source array of element bits to the target size.
50045007
auto CastBitData = [&](APInt &UndefSrcElts, ArrayRef<APInt> SrcEltBits) {
50055008
unsigned NumSrcElts = UndefSrcElts.getBitWidth();

llvm/test/CodeGen/X86/vec_extract.ll

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,72 @@ entry:
104104
}
105105
declare <2 x double> @foo()
106106

107+
define i64 @pr150117(<31 x i8> %a0) nounwind {
108+
; X86-LABEL: pr150117:
109+
; X86: # %bb.0:
110+
; X86-NEXT: pushl %ebx
111+
; X86-NEXT: pushl %edi
112+
; X86-NEXT: pushl %esi
113+
; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
114+
; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
115+
; X86-NEXT: movzbl {{[0-9]+}}(%esp), %esi
116+
; X86-NEXT: movzbl {{[0-9]+}}(%esp), %edi
117+
; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ebx
118+
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
119+
; X86-NEXT: shll $8, %edx
120+
; X86-NEXT: orl %ebx, %edx
121+
; X86-NEXT: shll $8, %edi
122+
; X86-NEXT: orl %esi, %edi
123+
; X86-NEXT: shll $16, %ecx
124+
; X86-NEXT: orl %edi, %ecx
125+
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
126+
; X86-NEXT: shll $24, %esi
127+
; X86-NEXT: orl %ecx, %esi
128+
; X86-NEXT: movd %esi, %xmm0
129+
; X86-NEXT: pinsrw $2, %edx, %xmm0
130+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
131+
; X86-NEXT: shll $8, %ecx
132+
; X86-NEXT: orl %eax, %ecx
133+
; X86-NEXT: pinsrw $3, %ecx, %xmm0
134+
; X86-NEXT: movd %xmm0, %eax
135+
; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,1,1,1]
136+
; X86-NEXT: movd %xmm0, %edx
137+
; X86-NEXT: popl %esi
138+
; X86-NEXT: popl %edi
139+
; X86-NEXT: popl %ebx
140+
; X86-NEXT: retl
141+
;
142+
; X64-LABEL: pr150117:
143+
; X64: # %bb.0:
144+
; X64-NEXT: movzbl {{[0-9]+}}(%rsp), %eax
145+
; X64-NEXT: movzbl {{[0-9]+}}(%rsp), %ecx
146+
; X64-NEXT: movzbl {{[0-9]+}}(%rsp), %edx
147+
; X64-NEXT: movzbl {{[0-9]+}}(%rsp), %esi
148+
; X64-NEXT: movzbl {{[0-9]+}}(%rsp), %edi
149+
; X64-NEXT: movl {{[0-9]+}}(%rsp), %r8d
150+
; X64-NEXT: shll $8, %r8d
151+
; X64-NEXT: orl %edi, %r8d
152+
; X64-NEXT: shll $8, %esi
153+
; X64-NEXT: orl %edx, %esi
154+
; X64-NEXT: shll $16, %ecx
155+
; X64-NEXT: orl %esi, %ecx
156+
; X64-NEXT: movl {{[0-9]+}}(%rsp), %edx
157+
; X64-NEXT: shll $24, %edx
158+
; X64-NEXT: orl %ecx, %edx
159+
; X64-NEXT: movd %edx, %xmm0
160+
; X64-NEXT: pinsrw $2, %r8d, %xmm0
161+
; X64-NEXT: movl {{[0-9]+}}(%rsp), %ecx
162+
; X64-NEXT: shll $8, %ecx
163+
; X64-NEXT: orl %eax, %ecx
164+
; X64-NEXT: pinsrw $3, %ecx, %xmm0
165+
; X64-NEXT: movq %xmm0, %rax
166+
; X64-NEXT: retq
167+
%shuffle = shufflevector <31 x i8> %a0, <31 x i8> zeroinitializer, <32 x i32> <i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
168+
%bitcast = bitcast <32 x i8> %shuffle to <4 x i64>
169+
%elt = extractelement <4 x i64> %bitcast, i64 0
170+
ret i64 %elt
171+
}
172+
107173
; OSS-Fuzz #15662
108174
; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=15662
109175
define <4 x i32> @ossfuzz15662(ptr %in) {

0 commit comments

Comments
 (0)