I wonder why AVX is not used automatically if available at the host machine. In contrast to that, SSE41 instructions (like pmulld) are automatically used if the host machine supports SSE41. E.g. $ cat avx.ll define void @_fun1(<8 x float>*, <8 x float>*) { _L1: %x = load <8 x float>* %0 %y = load <8 x float>* %1 %z = fadd <8 x float> %x, %y store <8 x float> %z, <8 x float>* %0 ret void } $ llc -o - avx.ll .file "avx.ll" .text .globl _fun1 .align 16, 0x90 .type _fun1, at function _fun1: # @_fun1 .cfi_startproc # BB#0: # %_L1 movaps (%rdi), %xmm0 movaps 16(%rdi), %xmm1 addps (%rsi), %xmm0 addps 16(%rsi), %xmm1 movaps %xmm1, 16(%rdi) movaps %xmm0, (%rdi) ret .Ltmp0: .size _fun1, .Ltmp0-_fun1 .cfi_endproc .section ".note.GNU-stack","", at progbits $ llc -o - -mattr avx avx.ll .file "avx.ll" .text .globl _fun1 .align 16, 0x90 .type _fun1, at function _fun1: # @_fun1 .cfi_startproc # BB#0: # %_L1 pushq %rbp .Ltmp2: .cfi_def_cfa_offset 16 .Ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp .Ltmp4: .cfi_def_cfa_register %rbp vmovaps (%rdi), %ymm0 vaddps (%rsi), %ymm0, %ymm0 vmovaps %ymm0, (%rdi) popq %rbp vzeroupper ret .Ltmp5: .size _fun1, .Ltmp5-_fun1 .cfi_endproc .section ".note.GNU-stack","", at progbits I guess your answer is that I did not specify a target triple. However why is SSE41 automatically detected and AVX is not?
Very likely AVX is not enabled in your llc. This feature was enabled just recently (late of April). -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Henning Thielemann Sent: Thursday, May 24, 2012 4:20 PM To: LLVM developer mailing list Subject: [LLVMdev] use AVX automatically if present I wonder why AVX is not used automatically if available at the host machine. In contrast to that, SSE41 instructions (like pmulld) are automatically used if the host machine supports SSE41. E.g. $ cat avx.ll define void @_fun1(<8 x float>*, <8 x float>*) { _L1: %x = load <8 x float>* %0 %y = load <8 x float>* %1 %z = fadd <8 x float> %x, %y store <8 x float> %z, <8 x float>* %0 ret void } $ llc -o - avx.ll .file "avx.ll" .text .globl _fun1 .align 16, 0x90 .type _fun1, at function _fun1: # @_fun1 .cfi_startproc # BB#0: # %_L1 movaps (%rdi), %xmm0 movaps 16(%rdi), %xmm1 addps (%rsi), %xmm0 addps 16(%rsi), %xmm1 movaps %xmm1, 16(%rdi) movaps %xmm0, (%rdi) ret .Ltmp0: .size _fun1, .Ltmp0-_fun1 .cfi_endproc .section ".note.GNU-stack","", at progbits $ llc -o - -mattr avx avx.ll .file "avx.ll" .text .globl _fun1 .align 16, 0x90 .type _fun1, at function _fun1: # @_fun1 .cfi_startproc # BB#0: # %_L1 pushq %rbp .Ltmp2: .cfi_def_cfa_offset 16 .Ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp .Ltmp4: .cfi_def_cfa_register %rbp vmovaps (%rdi), %ymm0 vaddps (%rsi), %ymm0, %ymm0 vmovaps %ymm0, (%rdi) popq %rbp vzeroupper ret .Ltmp5: .size _fun1, .Ltmp5-_fun1 .cfi_endproc .section ".note.GNU-stack","", at progbits I guess your answer is that I did not specify a target triple. However why is SSE41 automatically detected and AVX is not? _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On Thu, 24 May 2012, Pan, Wei wrote:> Very likely AVX is not enabled in your llc. This feature was enabled > just recently (late of April).I forgot to mention that I am using recent LLVM-3.1 and in principle my llc knows about avx as I have shown in the second example. But avx does not seem to be used by default. On Thu, 24 May 2012, Henning Thielemann wrote:> $ llc -o - -mattr avx avx.ll > .file "avx.ll" > .text > .globl _fun1 > .align 16, 0x90 > .type _fun1, at function > _fun1: # @_fun1 > .cfi_startproc > # BB#0: # %_L1 > pushq %rbp > .Ltmp2: > .cfi_def_cfa_offset 16 > .Ltmp3: > .cfi_offset %rbp, -16 > movq %rsp, %rbp > .Ltmp4: > .cfi_def_cfa_register %rbp > vmovaps (%rdi), %ymm0 > vaddps (%rsi), %ymm0, %ymm0 > vmovaps %ymm0, (%rdi) > popq %rbp > vzeroupper > ret > .Ltmp5: > .size _fun1, .Ltmp5-_fun1 > .cfi_endproc > > > .section ".note.GNU-stack","", at progbits > > > > > I guess your answer is that I did not specify a target triple. However why is > SSE41 automatically detected and AVX is not?
Henning, I believe the code that is supposed to do this is in: lib/Target/X86/X86Subtarget.cpp in X86Subtarget::AutoDetectSubtargetFeatures() Is there a bug in that function? -Hal On Thu, 24 May 2012 23:56:48 +0200 (CEST) Henning Thielemann <llvm at henning-thielemann.de> wrote:> > On Thu, 24 May 2012, Pan, Wei wrote: > > > Very likely AVX is not enabled in your llc. This feature was > > enabled just recently (late of April). > > I forgot to mention that I am using recent LLVM-3.1 and in principle > my llc knows about avx as I have shown in the second example. But avx > does not seem to be used by default. > > > On Thu, 24 May 2012, Henning Thielemann wrote: > > > $ llc -o - -mattr avx avx.ll > > .file "avx.ll" > > .text > > .globl _fun1 > > .align 16, 0x90 > > .type _fun1, at function > > _fun1: # @_fun1 > > .cfi_startproc > > # BB#0: # %_L1 > > pushq %rbp > > .Ltmp2: > > .cfi_def_cfa_offset 16 > > .Ltmp3: > > .cfi_offset %rbp, -16 > > movq %rsp, %rbp > > .Ltmp4: > > .cfi_def_cfa_register %rbp > > vmovaps (%rdi), %ymm0 > > vaddps (%rsi), %ymm0, %ymm0 > > vmovaps %ymm0, (%rdi) > > popq %rbp > > vzeroupper > > ret > > .Ltmp5: > > .size _fun1, .Ltmp5-_fun1 > > .cfi_endproc > > > > > > .section ".note.GNU-stack","", at progbits > > > > > > > > > > I guess your answer is that I did not specify a target triple. > > However why is SSE41 automatically detected and AVX is not? > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- Hal Finkel Postdoctoral Appointee Leadership Computing Facility Argonne National Laboratory
llc built from the current trunk generates avx code as you expected. I tested that. Avx in llvm3.1 is not enabled by default. -----Original Message----- From: Henning Thielemann [mailto:llvm at henning-thielemann.de] Sent: Thursday, May 24, 2012 5:57 PM To: Pan, Wei Cc: LLVM developer mailing list Subject: Re: use AVX automatically if present On Thu, 24 May 2012, Pan, Wei wrote:> Very likely AVX is not enabled in your llc. This feature was enabled > just recently (late of April).I forgot to mention that I am using recent LLVM-3.1 and in principle my llc knows about avx as I have shown in the second example. But avx does not seem to be used by default. On Thu, 24 May 2012, Henning Thielemann wrote:> $ llc -o - -mattr avx avx.ll > .file "avx.ll" > .text > .globl _fun1 > .align 16, 0x90 > .type _fun1, at function > _fun1: # @_fun1 > .cfi_startproc > # BB#0: # %_L1 > pushq %rbp > .Ltmp2: > .cfi_def_cfa_offset 16 > .Ltmp3: > .cfi_offset %rbp, -16 > movq %rsp, %rbp > .Ltmp4: > .cfi_def_cfa_register %rbp > vmovaps (%rdi), %ymm0 > vaddps (%rsi), %ymm0, %ymm0 > vmovaps %ymm0, (%rdi) > popq %rbp > vzeroupper > ret > .Ltmp5: > .size _fun1, .Ltmp5-_fun1 > .cfi_endproc > > > .section ".note.GNU-stack","", at progbits > > > > > I guess your answer is that I did not specify a target triple. However > why is > SSE41 automatically detected and AVX is not?