This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Tighten reasscociation of visitFMA
ClosedPublic

Authored by qiucf on Oct 15 2020, 10:08 PM.

Details

Summary

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).

Diff Detail

Event Timeline

qiucf created this revision.Oct 15 2020, 10:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2020, 10:08 PM
qiucf requested review of this revision.Oct 15 2020, 10:08 PM
spatel added inline comments.Oct 16 2020, 8:49 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13257

Can you add a test for this transform too?

qiucf updated this revision to Diff 298934.Oct 18 2020, 11:42 PM
qiucf marked an inline comment as done.

Add another test about preventing combined into (fmul x, c1+c2). (test was not pre-committed, diff is for review)

spatel accepted this revision.Oct 19 2020, 5:15 AM

LGTM

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13214

This comment line seems to be misplaced now - it can be moved above the FlagInserter declaration or deleted.

This revision is now accepted and ready to land.Oct 19 2020, 5:15 AM
This revision was automatically updated to reflect the committed changes.