[PATCH] D132837: [ISel] Enable generating more fma instructions.

Thomas Symalla via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 16 00:33:23 PDT 2022


tsymalla added inline comments.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:14185
+        SDValue NewFMA = DAG.getNode(PreferredFusedOpcode, SL, VT, C, D, FMA);
+        DAG.UpdateNodeOperands(TmpFMA.getNode(), A, B, E);
+
----------------
arsenm wrote:
> Why use UpdateNodeOperands here instead of just constructing the new node normally?
This is updating the innermost FMA node which already exists, I am just replacing the last operand of it.
The newly created node is the FMA node in NewFMA:

Example steps:

```
fadd (fma A, B, (fmul C, D)), E

1. NewFMA = fma_o (C, D, fma_i (A, B, fmul(C, D)))
2. fma_i = fma (A, B, E)
=> NewFMA = fma (C, D, fma (A, B, E))
```

More complex case:
```
fadd (fma_i0 A, B, (fma (C, D, (fmul (E, F))))), G:
1. TmpFMA = fma_i = fma (C, D, (fmul (E, F))))
2. NewFMA = fma (E, F, fma_i0) = fma (E, F, fma (A, B, fma (C, D, (fmul (E, F))))) (construct outermost FMA)
3. TmpFMA.UpdateNodeOperands: fma_i = fma (C, D, (fmul (E, F)) => fma (C, D, G) => fma (E, F, fma (A, B, fma (C, D, (fmul (E, F))))) = fma (E, F, fma (A, B, fma (C, D, G))) (replace innermost FMA operand with addition operator of the initial FADD)
```

I can create a new node for the innermost FMA, but isn't `UpdateNodeOperands` being used for such cases?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132837/new/

https://reviews.llvm.org/D132837



More information about the llvm-commits mailing list