[PATCH] D75982: [DAGCombine] Respect the uses when combine FMA for a*b+/-c*d
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 12 05:54:00 PDT 2020
lebedev.ri added a comment.
This doesn't look unreasonable to me now.
================
Comment at: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:11900-11919
// fold (fsub (fmul x, y), z) -> (fma x, y, (fneg z))
- if (isContractableFMUL(N0) && (Aggressive || N0->hasOneUse())) {
- return DAG.getNode(PreferredFusedOpcode, SL, VT,
- N0.getOperand(0), N0.getOperand(1),
- DAG.getNode(ISD::FNEG, SL, VT, N1), Flags);
- }
+ auto tryToFoldXYSubZ = [&](SDValue XY, SDValue Z) {
+ if (isContractableFMUL(XY) && (Aggressive || XY->hasOneUse())) {
+ return DAG.getNode(PreferredFusedOpcode, SL, VT, XY.getOperand(0),
+ XY.getOperand(1), DAG.getNode(ISD::FNEG, SL, VT, Z),
+ Flags);
+ }
----------------
I suggest to land this NFC refactoring first, to make the diff more understandable.
================
Comment at: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:11925
+ (N0.getNode()->use_size() > N1.getNode()->use_size())) {
+ // fold (fsub x, (fmul y, z)) -> (fma (fneg y), z, x)
+ if (SDValue V = tryToFoldXSubYZ(N0, N1))
----------------
```
// fold (fsub (fmul a, b), (fmul c, d)) -> (fma (fneg c), d, (fmul a, b))
```
================
Comment at: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:11928
+ return V;
+ // fold (fsub (fmul x, y), z) -> (fma x, y, (fneg z))
+ if (SDValue V = tryToFoldXYSubZ(N0, N1))
----------------
```
// fold (fsub (fmul a, b), (fmul c, d)) -> (fma a, b, (fneg (fmul c, d)))
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75982/new/
https://reviews.llvm.org/D75982
More information about the llvm-commits
mailing list