OSDN Git Service

LegalizeDAG: Fix and improve FCOPYSIGN/FABS legalization
authorMatthias Braun <matze@braunis.de>
Tue, 14 Jul 2015 02:08:26 +0000 (02:08 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 14 Jul 2015 02:08:26 +0000 (02:08 +0000)
commit2a46e4c020f3daf69b044b1e0c62ed6676036b49
tree5c83c412e13290cc5ac93ac5fcd849dc11cdf112
parentdbe717878a965c8cf89e4a226ea9e158687c68e5
LegalizeDAG: Fix and improve FCOPYSIGN/FABS legalization

- Factor out code to query and modify the sign bit of a floatingpoint
  value as an integer. This also works if none of the targets integer
  types is big enough to hold all bits of the floatingpoint value.

- Legalize FABS(x) as FCOPYSIGN(x, 0.0) if FCOPYSIGN is available,
  otherwise perform bit manipulation on the sign bit. The previous code
  used "x >u 0 ? x : -x" which is incorrect for x being -0.0! It also
  takes 34 instructions on ARM Cortex-M4. With this patch we only
  require 5:
    vldr d0, LCPI0_0
    vmov r2, r3, d0
    lsrs r2, r3, #31
    bfi r1, r2, #31, #1
    bx lr
  (This could be further improved if the compiler would recognize that
   r2, r3 is zero).

- Only lower FCOPYSIGN(x, y) = sign(x) ? -FABS(x) : FABS(x) if FABS is
  available otherwise perform bit manipulation on the sign bit.

- Perform the sign(x) test by masking out the sign bit and comparing
  with 0 rather than shifting the sign bit to the highest position and
  testing for "<s 0". For x86 copysignl (on 80bit values) this gets us:
    testl $32768, %eax
  rather than:
    shlq $48, %rax
    sets %al
    testb %al, %al

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242107 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
test/CodeGen/Thumb2/float-intrinsics-double.ll
test/CodeGen/X86/pr13577.ll