Skip to content

Commit 2a2d242

Browse files
committed
[DAGCombine] foldVSelectOfConstants - ensure constants are same type
Fix bug identified by https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21167, foldVSelectOfConstants must ensure that the 2 build vectors have scalars of the same type before trying to compare APInt values.
1 parent 6174fdd commit 2a2d242

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8975,6 +8975,8 @@ SDValue DAGCombiner::foldVSelectOfConstants(SDNode *N) {
89758975
SDValue N2Elt = N2.getOperand(i);
89768976
if (N1Elt.isUndef() || N2Elt.isUndef())
89778977
continue;
8978+
if (N1Elt.getValueType() != N2Elt.getValueType())
8979+
continue;
89788980

89798981
const APInt &C1 = cast<ConstantSDNode>(N1Elt)->getAPIntValue();
89808982
const APInt &C2 = cast<ConstantSDNode>(N2Elt)->getAPIntValue();

llvm/test/CodeGen/X86/vselect-constants.ll

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,42 @@ define <4 x i32> @cmp_sel_0_or_1_vec(<4 x i32> %x, <4 x i32> %y) {
256256
ret <4 x i32> %add
257257
}
258258

259+
; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21167
260+
define <2 x i37> @ossfuzz21167(<2 x i37> %x, <2 x i37> %y) {
261+
; SSE-LABEL: ossfuzz21167:
262+
; SSE: # %bb.0: # %BB
263+
; SSE-NEXT: psllq $27, %xmm1
264+
; SSE-NEXT: movdqa %xmm1, %xmm0
265+
; SSE-NEXT: psrad $27, %xmm0
266+
; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,3,2,3]
267+
; SSE-NEXT: psrlq $27, %xmm1
268+
; SSE-NEXT: pshufd {{.*#+}} xmm1 = xmm1[0,2,2,3]
269+
; SSE-NEXT: punpckldq {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
270+
; SSE-NEXT: movdqa {{.*#+}} xmm0 = [2147483648,2147483648]
271+
; SSE-NEXT: pxor %xmm0, %xmm1
272+
; SSE-NEXT: movdqa %xmm1, %xmm2
273+
; SSE-NEXT: pcmpgtd %xmm0, %xmm2
274+
; SSE-NEXT: pcmpeqd %xmm0, %xmm1
275+
; SSE-NEXT: pshufd {{.*#+}} xmm1 = xmm1[1,1,3,3]
276+
; SSE-NEXT: pand %xmm2, %xmm1
277+
; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm2[1,1,3,3]
278+
; SSE-NEXT: por %xmm1, %xmm0
279+
; SSE-NEXT: pand {{.*}}(%rip), %xmm0
280+
; SSE-NEXT: retq
281+
;
282+
; AVX-LABEL: ossfuzz21167:
283+
; AVX: # %bb.0: # %BB
284+
; AVX-NEXT: vpsllq $27, %xmm1, %xmm0
285+
; AVX-NEXT: vpsrad $27, %xmm0, %xmm1
286+
; AVX-NEXT: vpsrlq $27, %xmm0, %xmm0
287+
; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3],xmm0[4,5],xmm1[6,7]
288+
; AVX-NEXT: vpxor %xmm1, %xmm1, %xmm1
289+
; AVX-NEXT: vpcmpgtq %xmm1, %xmm0, %xmm0
290+
; AVX-NEXT: vpsrlq $63, %xmm0, %xmm0
291+
; AVX-NEXT: retq
292+
BB:
293+
%c0 = icmp sgt <2 x i37> %y, zeroinitializer
294+
%xor_x = xor <2 x i37> undef, undef
295+
%smax96 = select <2 x i1> %c0, <2 x i37> %xor_x, <2 x i37> zeroinitializer
296+
ret <2 x i37> %smax96
297+
}

0 commit comments

Comments
 (0)