[PowerPC] Select between VSX A-type and M-type FMA instructions just before RA
authorHal Finkel <hfinkel@anl.gov>
Tue, 25 Mar 2014 23:29:21 +0000 (23:29 +0000)
committerHal Finkel <hfinkel@anl.gov>
Tue, 25 Mar 2014 23:29:21 +0000 (23:29 +0000)
commit6a0f060f64dbe08623b84dae55c8651d12c25705
tree946c77d6a97d14a551c6ec6f0c7eb35c1220c1c3
parent99ab0798a2198aed08d529a6b5bd03aa9405b719
[PowerPC] Select between VSX A-type and M-type FMA instructions just before RA

The VSX instruction set has two types of FMA instructions: A-type (where the
addend is taken from the output register) and M-type (where one of the product
operands is taken from the output register). This adds a small pass that runs
just after MI scheduling (and, thus, just before register allocation) that
mutates A-type instructions (that are created during isel) into M-type
instructions when:

 1. This will eliminate an otherwise-necessary copy of the addend

 2. One of the product operands is killed by the instruction

The "right" moment to make this decision is in between scheduling and register
allocation, because only there do we know whether or not one of the product
operands is killed by any particular instruction. Unfortunately, this also
makes the implementation somewhat complicated, because the MIs are not in SSA
form and we need to preserve the LiveIntervals analysis.

As a simple example, if we have:

%vreg5<def> = COPY %vreg9; VSLRC:%vreg5,%vreg9
%vreg5<def,tied1> = XSMADDADP %vreg5<tied0>, %vreg17, %vreg16,
                        %RM<imp-use>; VSLRC:%vreg5,%vreg17,%vreg16
  ...
  %vreg9<def,tied1> = XSMADDADP %vreg9<tied0>, %vreg17, %vreg19,
                        %RM<imp-use>; VSLRC:%vreg9,%vreg17,%vreg19
  ...

We can eliminate the copy by changing from the A-type to the
M-type instruction. This means:

  %vreg5<def,tied1> = XSMADDADP %vreg5<tied0>, %vreg17, %vreg16,
                        %RM<imp-use>; VSLRC:%vreg5,%vreg17,%vreg16

is replaced by:

  %vreg16<def,tied1> = XSMADDMDP %vreg16<tied0>, %vreg18, %vreg9,
                        %RM<imp-use>; VSLRC:%vreg16,%vreg18,%vreg9

and we remove: %vreg5<def> = COPY %vreg9; VSLRC:%vreg5,%vreg9

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204768 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/PowerPC/PPC.h
lib/Target/PowerPC/PPCInstrInfo.cpp
lib/Target/PowerPC/PPCTargetMachine.cpp
test/CodeGen/PowerPC/vsx-fma-m.ll [new file with mode: 0644]