[x86] Implement combineRepeatedFPDivisors
authorSanjay Patel <spatel@rotateright.com>
Wed, 15 Apr 2015 15:22:55 +0000 (15:22 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 15 Apr 2015 15:22:55 +0000 (15:22 +0000)
commit0332323ab6873b59a104602de766694a88d69787
tree5a1881f6f7e4d5f749acdf8e5f5c8af60d377146
parentea604d92efcbf53fd0909da562d3db7860ff6199
[x86] Implement combineRepeatedFPDivisors

Set the transform bar at 2 divisions because the fastest current
x86 FP divider circuit is in SandyBridge / Haswell at 10 cycle
latency (best case) relative to a 5 cycle multiplier.
So that's the worst case for this transform (no latency win),
but multiplies are obviously pipelined while divisions are not,
so there's still a big throughput win which we would expect to
show up in typical FP code.

These are the sequences I'm comparing:

  divss   %xmm2, %xmm0
  mulss   %xmm1, %xmm0
  divss   %xmm2, %xmm0

Becomes:

  movss   LCPI0_0(%rip), %xmm3    ## xmm3 = mem[0],zero,zero,zero
  divss   %xmm2, %xmm3
  mulss   %xmm3, %xmm0
  mulss   %xmm1, %xmm0
  mulss   %xmm3, %xmm0

[Ignore for the moment that we don't optimize the chain of 3 multiplies
into 2 independent fmuls followed by 1 dependent fmul...this is the DAG
version of: https://llvm.org/bugs/show_bug.cgi?id=21768 ...if we fix that,
then the transform becomes even more profitable on all targets.]

Differential Revision: http://reviews.llvm.org/D8941

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235012 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86ISelLowering.h
test/CodeGen/X86/fdiv-combine.ll [new file with mode: 0644]