[PATCH] D75982: [DAGCombine] Respect the uses when combine FMA for a*b+/-c*d and add target hook if there uses are the same

qshanz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 11 04:33:35 PDT 2020


steven.zhang created this revision.
steven.zhang added reviewers: arsenm, RKSimon, spatel, jsji, nemanjai, PowerPC.
Herald added subscribers: wuzish, kbarton, hiraditya, wdng.
Herald added a project: LLVM.

If the DAG looks like this: a*b+c*d, it could be folded into fma(a, b, c*d) or fma(c, d, a*b). https://reviews.llvm.org/D11855 was posted to improve it that respects the uses of a*b or c*d to do the best choice. 
But for a*b-c*d, it could be also folded into fma(a, b, -c*d) or fma(-c, d, a*b). This patch is trying to respect the uses of a*b and c*d to make the best choice. 
And this is the motivated case:

  define double @fsub1(double %a, double %b, double %c, double %d)  {
  entry:
    %mul = fmul fast double %b, %a
    %mul1 = fmul fast double %d, %c
    %sub = fsub fast double %mul, %mul1
    %mul3 = fmul fast double %mul, %sub
    ret double %mul3
  }

   define double @fsub1(double %a, double %b, double %c, double %d)  {
   ; CHECK-LABEL: fsub1:
   ; CHECK:       # %bb.0: # %entry
  -; CHECK-NEXT:    xsmuldp 3, 4, 3
   ; CHECK-NEXT:    xsmuldp 0, 2, 1
  -; CHECK-NEXT:    xsmsubadp 3, 2, 1
  -; CHECK-NEXT:    xsmuldp 1, 0, 3
  +; CHECK-NEXT:    fmr 1, 0
  +; CHECK-NEXT:    xsnmsubadp 1, 4, 3
  +; CHECK-NEXT:    xsmuldp 1, 0, 1

If their uses are the same, add a target hook to allow some platform such as PowerPC to make the choice, as it has different precisions between these two folding which is caused by round a*b or c*d. 
In PowerPC, we have some floating precision quite sensitive libraries that depend on the slightly difference between rounding a*b or c*d.  So, we need some way to control the behavior of this combine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75982

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/test/CodeGen/PowerPC/fma-precision.ll
  llvm/test/CodeGen/PowerPC/recipest.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75982.249582.patch
Type: text/x-patch
Size: 10352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200311/e5af3081/attachment.bin>


More information about the llvm-commits mailing list