[PATCH] D89527: [DAGCombiner] Tighten reasscociation of visitFMA

Qiu Chaofan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 15 22:08:53 PDT 2020


qiucf created this revision.
qiucf added reviewers: spatel, PowerPC, nemanjai, jsji, cameron.mcinally, RKSimon, steven.zhang.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
qiucf requested review of this revision.

>From LangRef:

> `contract`: Allow floating-point contraction (e.g. fusing a multiply followed by an addition into a fused multiply-and-add). This does not enable reassociating to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations.



> `reassoc`: Allow reassociation transformations for floating-point instructions. This may dramatically change results in floating-point.

So `contract` should only help in fusing several operations into one (FMA), not rearrange nodes like `(fma (fmul x, c1), c2, y)` into `(fma x, c1*c2, y)`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89527

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/PowerPC/fma-combine.ll


Index: llvm/test/CodeGen/PowerPC/fma-combine.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/fma-combine.ll
+++ llvm/test/CodeGen/PowerPC/fma-combine.ll
@@ -333,8 +333,11 @@
 ; CHECK:       # %bb.0: # %entry
 ; CHECK-NEXT:    addis 3, 2, .LCPI9_0 at toc@ha
 ; CHECK-NEXT:    lfd 0, .LCPI9_0 at toc@l(3)
-; CHECK-NEXT:    xsmaddadp 2, 1, 0
+; CHECK-NEXT:    addis 3, 2, .LCPI9_1 at toc@ha
+; CHECK-NEXT:    lfd 3, .LCPI9_1 at toc@l(3)
+; CHECK-NEXT:    xsmuldp 0, 1, 0
 ; CHECK-NEXT:    fmr 1, 2
+; CHECK-NEXT:    xsmaddadp 1, 0, 3
 ; CHECK-NEXT:    blr
 entry:
   %0 = fmul double %a, 1.1
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -13212,7 +13212,8 @@
   SelectionDAG::FlagInserter FlagsInserter(DAG, N);
 
   // FMA nodes have flags that propagate to the created nodes.
-  bool UnsafeFPMath = Options.UnsafeFPMath || isContractable(N);
+  bool UnsafeFPMath =
+      Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
 
   // Constant fold FMA.
   if (isa<ConstantFPSDNode>(N0) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89527.298544.patch
Type: text/x-patch
Size: 1216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201016/ff22ed6d/attachment.bin>


More information about the llvm-commits mailing list