Skip to content

Commit 6cff71e

Browse files
committed
[X86][AVX] Add test case showing incorrect extraction from VBROADCAST_LOAD on AVX2 targets
On AVX2 we tend to lower BUILD_VECTOR of constants as broadcasts if we can, in this case a <2 x i16> non-uniform constant has been lowered as a <4 x i32> broadcast. The test case shows that the extraction folding code has incorrectly extracted the wrong part (lower WORD) of the resulting i32 memory source. Found by internal fuzzing tests.
1 parent 3030e6b commit 6cff71e

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

‎llvm/test/CodeGen/X86/extractelement-load.ll‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,51 @@ entry:
266266
%cond = select i1 %cmp, float 1.000000e+00, float %vecext
267267
ret float %cond
268268
}
269+
270+
; FIXME: Incorrect AVX2 codegen due to bad extraction from a VBROADCAST_LOAD of the <2 x i16> constant bitcast as <4 x i32>.
271+
define void @subextract_broadcast_load_constant(<2 x i16>* nocapture %0, i16* nocapture %1, i16* nocapture %2) {
272+
; X32-SSE2-LABEL: subextract_broadcast_load_constant:
273+
; X32-SSE2: # %bb.0:
274+
; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
275+
; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
276+
; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %edx
277+
; X32-SSE2-NEXT: movl $-1583308898, (%edx) # imm = 0xA1A09F9E
278+
; X32-SSE2-NEXT: movw $-24674, (%ecx) # imm = 0x9F9E
279+
; X32-SSE2-NEXT: movw $-24160, (%eax) # imm = 0xA1A0
280+
; X32-SSE2-NEXT: retl
281+
;
282+
; X64-SSSE3-LABEL: subextract_broadcast_load_constant:
283+
; X64-SSSE3: # %bb.0:
284+
; X64-SSSE3-NEXT: movl $-1583308898, (%rdi) # imm = 0xA1A09F9E
285+
; X64-SSSE3-NEXT: movw $-24674, (%rsi) # imm = 0x9F9E
286+
; X64-SSSE3-NEXT: movw $-24160, (%rdx) # imm = 0xA1A0
287+
; X64-SSSE3-NEXT: retq
288+
;
289+
; X64-AVX1-LABEL: subextract_broadcast_load_constant:
290+
; X64-AVX1: # %bb.0:
291+
; X64-AVX1-NEXT: movl $-1583308898, (%rdi) # imm = 0xA1A09F9E
292+
; X64-AVX1-NEXT: movw $-24674, (%rsi) # imm = 0x9F9E
293+
; X64-AVX1-NEXT: movw $-24160, (%rdx) # imm = 0xA1A0
294+
; X64-AVX1-NEXT: retq
295+
;
296+
; X64-AVX2-LABEL: subextract_broadcast_load_constant:
297+
; X64-AVX2: # %bb.0:
298+
; X64-AVX2-NEXT: movl $-1583308898, (%rdi) # imm = 0xA1A09F9E
299+
; X64-AVX2-NEXT: movw $-24674, (%rsi) # imm = 0x9F9E
300+
; X64-AVX2-NEXT: movw $-24674, (%rdx) # imm = 0x9F9E
301+
; X64-AVX2-NEXT: retq
302+
%4 = bitcast <2 x i16>* %0 to i8*
303+
store i8 -98, i8* %4, align 1
304+
%5 = getelementptr inbounds i8, i8* %4, i64 1
305+
store i8 -97, i8* %5, align 1
306+
%6 = getelementptr inbounds i8, i8* %4, i64 2
307+
store i8 -96, i8* %6, align 1
308+
%7 = getelementptr inbounds i8, i8* %4, i64 3
309+
store i8 -95, i8* %7, align 1
310+
%8 = load <2 x i16>, <2 x i16>* %0, align 4
311+
%9 = extractelement <2 x i16> %8, i32 0
312+
store i16 %9, i16* %1, align 2
313+
%10 = extractelement <2 x i16> %8, i32 1
314+
store i16 %10, i16* %2, align 2
315+
ret void
316+
}

0 commit comments

Comments
 (0)