[PATCH] D80801: [DAGCombiner] allow more folding of fadd + fmul into fma

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 08:06:57 PDT 2020


spatel created this revision.
spatel added reviewers: efriedma, fhahn, craig.topper, RKSimon.
Herald added subscribers: ecnelises, steven.zhang, hiraditya, kristof.beyls, mcrosier.
Herald added a project: LLVM.

If fmul and fadd are separated by an fma, we can fold them together to save an instruction:
fadd (fma A, B, (fmul C, D)), N1 --> fma(A, B, fma(C, D, N1))

The fold implemented here is actually a specialization - we should be able to peek through >1 fma to find this pattern. That's another patch if we want to try that enhancement though.

This transform was guarded by the TLI hook for enableAggressiveFMAFusion(), so it was done for some in-tree targets like PowerPC, but not AArch64 or x86. The hook is protecting against forming a potentially more expensive computation when fma takes longer to execute than a single fadd. That hook may be needed for other transforms, but in this case, we are replacing fmul+fadd with fma, and the fma should never take longer than the 2 individual instructions.

'contract' FMF is all we need to allow this transform. That flag corresponds to -ffp-contract=fast in Clang, so we are allowed to form fma ops freely across expressions.


https://reviews.llvm.org/D80801

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/AArch64/fadd-combines.ll
  llvm/test/CodeGen/X86/fma_patterns.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80801.267227.patch
Type: text/x-patch
Size: 10515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200529/de73d41c/attachment.bin>


More information about the llvm-commits mailing list