[llvm-bugs] [Bug 24366] New: [x86, FMA] use FMA instructions for negation instead of loading a constant and xor'ing?

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 5 10:38:18 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24366

            Bug ID: 24366
           Summary: [x86, FMA] use FMA instructions for negation instead
                    of loading a constant and xor'ing?
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

With the addition of FMA instructions, x86 can negate FP values without loading
a constant:

$ cat nmul.ll 

define float @nmul(float %a, float %b) {
  %mul = fmul float %a, %b
  %neg = fsub float -0.0, %mul
  ret float %neg
}


$ ./llc -o - nmul.ll -mattr=fma 
    .section    __TEXT,__text,regular,pure_instructions
    .macosx_version_min 14, 4
    .section    __TEXT,__literal16,16byte_literals
    .align    4
LCPI0_0:
    .long    2147483648              ## 0x80000000
    .long    2147483648              ## 0x80000000
    .long    2147483648              ## 0x80000000
    .long    2147483648              ## 0x80000000
    .section    __TEXT,__text,regular,pure_instructions
    .globl    _nmul
    .align    4, 0x90
_nmul:                                  ## @nmul
    .cfi_startproc
## BB#0:
    vmulss    %xmm1, %xmm0, %xmm0
    vxorps    LCPI0_0(%rip), %xmm0, %xmm0
    retq

-------------------------------------------------------------------------------

Better speed/size, but does require a temp register:
  vxorps        %xmm2, %xmm2, %xmm2  <--- make zero cheaply for add operand
  vfnmadd213ss  %xmm2, %xmm1, %xmm0


I don't think this causes any IEEE-754 problems, but if it does, it should
still be possible to do this with -ffast-math?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150805/08d200b7/attachment.html>


More information about the llvm-bugs mailing list