llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

llc generates incorrect AVX code on sandy bridge on following .ll file

Open llvmbot opened this issue 13 years ago • 3 comments

Bugzilla Link 15298
Resolution FIXED
Resolved on Apr 26, 2017 05:39
Version 3.2
OS Linux
Reporter LLVM Bugzilla Contributor
CC @RKSimon,@darkbuck

Extended Description

Following ll code is designed to produce a vector of 8 floats with following values

<0.0, elem(0, source), elem(0, source), 0.0, 0.0, 0.0, 0.0, 0.0>

; ModuleID = 'shufxbug.ll' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" target triple = "i386-pc-linux-gnu"

define void @​sample_test(<4 x float>* nocapture %source, <8 x float>* nocapture %dest) nounwind noinline { L.entry: %0 = getelementptr <4 x float>* %source, i32 19 %1 = load <4 x float>* %0, align 16 %2 = extractelement <4 x float> %1, i32 0 %3 = insertelement <8 x float> <float 0.000000e+00, float undef, float undef, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, float %2, i32 2 %4 = insertelement <8 x float> %3, float %2, i32 1 %5 = getelementptr <8 x float>* %dest, i32 19 store <8 x float> %4, <8 x float>* %5, align 4 ret void }

When compiled on a sandy bridge machine as follows:

llc shufxbug.ll -march=x86 -relocation-model=pic -o shufxbug.s

Following assembly is generated:

... pushl %ebp .Ltmp5: .cfi_def_cfa_offset 8 .Ltmp6: .cfi_offset %ebp, -8 movl %esp, %ebp .Ltmp7: .cfi_def_cfa_register %ebp movl 12(%ebp), %eax .loc 1 9 0 prologue_end # shufxbug.cl:9:0 .Ltmp8: vpermilps $65, 304(%eax), %xmm0 # xmm0 = mem[1,0,0,1] vxorps %xmm1, %xmm1, %xmm1 vinsertf128 $1, %xmm1, %ymm0, %ymm0 movl 16(%ebp), %eax .loc 1 10 0 # shufxbug.cl:10:0 vmovups %ymm0, 608(%eax) .loc 1 11 0 # shufxbug.cl:11:0 popl %ebp vzeroupper ret ...

Vector created is then

<elem(1, source), elem(0, source), elem(0, source), elem(1, source), 0.0, 0.0, 0.0, 0.0>

On a Core i7 machine code is slightly different and produce expected result

llvmbot avatar Feb 19 '13 16:02 llvmbot

Resolving old ticket - the new shuffle combining changed this considerably but it works fine and I added a test at rL301396:

BB#0: # %L.entry

movl {{[0-9]+}}(%esp), %eax movl {{[0-9]+}}(%esp), %ecx vbroadcastss 304(%ecx), %xmm0 vxorps %ymm1, %ymm1, %ymm1 vblendps {{.*#+}} ymm0 = ymm1[0],ymm0[1,2],ymm1[3,4,5,6,7] vmovups %ymm0, 608(%eax) vzeroupper retl

RKSimon avatar Apr 26 '17 12:04 RKSimon

When using LLVM 3.2, I've got behavior described in bug report. When I'm using LLVM trunk, I've got behavior you described. If this problem has been fixed on purpose, do youi know which file has been affected by this fix so that I can back-port change to our LLVM 3.2 ? Thanks for the time you spent looking at this problem

llvmbot avatar Mar 18 '13 12:03 llvmbot

I could not reproduce your assembly output on TT. Could you let me know the revision number you tested.

BTW, I got the following output

$ ../build/bin/llc -march=x86 -relocation-model=pic -mcpu=core-avx-i < pr15298.ll .file "" .text .globl sample_test .align 16, 0x90 .type sample_test,@function sample_test: # @​sample_test

BB#0: # %L.entry

movl	4(%esp), %eax
vmovss	304(%eax), %xmm0
vxorps	%xmm1, %xmm1, %xmm1
movl	8(%esp), %eax
vmovups	%xmm1, 624(%eax)
vpshufd	$65, %xmm0, %xmm0       # xmm0 = xmm0[1,0,0,1]
vmovdqu	%xmm0, 608(%eax)
ret

.Ltmp0: .size sample_test, .Ltmp0-sample_test

.section	".note.GNU-stack","",@progbits

darkbuck avatar Mar 14 '13 07:03 darkbuck