This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Check reassoc flags in aggressive fsub fusion
ClosedPublic

Authored by jsji on Jun 22 2021, 9:54 AM.

Details

Summary

The is from discussion in https://reviews.llvm.org/D104247#inline-993387

The contract and reassoc flags shouldn't imply each other .

All the aggressive fsub fusion reassociate operations,
we should guard them with reassoc flag check.

Diff Detail

Event Timeline

jsji created this revision.Jun 22 2021, 9:54 AM
jsji requested review of this revision.Jun 22 2021, 9:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2021, 9:54 AM
lebedev.ri added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13255–13260
jsji updated this revision to Diff 353690.Jun 22 2021, 9:58 AM

Fix typo.

Patch description doesn't explain *why* we should do that.

jsji added inline comments.Jun 22 2021, 10:04 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13255–13260
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:13258:25: error: no matching function for call to object of type '(lambda at llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:13255:25)'
  bool CanReassociate = isReassociable(N);
                        ^~~~~~~~~~~~~~
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:13255:25: note: candidate function not viable: no known conversion from 'llvm::SDNode *' to 'llvm::SDValue' for 1st argument
  auto isReassociable = [Options](SDValue N) {
                        ^
1 error generated.
ninja: build stopped: subcommand failed.

N is SDNode, any suggestion to get SDValue of it? SDValue() might cause crash in tests.

jsji edited the summary of this revision. (Show Details)Jun 22 2021, 10:06 AM
mcberg2017 accepted this revision.Jun 22 2021, 10:10 AM

Let some of the others also comment, but on the surface it's what I would expect.

This revision is now accepted and ready to land.Jun 22 2021, 10:10 AM
lebedev.ri added inline comments.Jun 22 2021, 10:13 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13255–13260

SDValue(N, 0)?

13255–13260

... or more generally, [why] does it have to take SDValue?

jsji updated this revision to Diff 353722.Jun 22 2021, 11:11 AM

Address comments.

jsji marked 2 inline comments as done.Jun 22 2021, 11:12 AM
jsji added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13255–13260

Good idea, thanks!

lebedev.ri added inline comments.Jun 22 2021, 11:17 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13259

foldable is a rather generic and widely used term.
I'd suggest isContractableAndReassociableFMUL()

jsji updated this revision to Diff 353724.Jun 22 2021, 11:24 AM
jsji marked an inline comment as done.

Rename to isContractableAndReassociableFMUL.

AMDGPU tests LGTM, thanks!

This revision was landed with ongoing or failed builds.Jun 23 2021, 7:00 AM
This revision was automatically updated to reflect the committed changes.
foad added a subscriber: foad.Sep 30 2021, 3:45 AM
foad added inline comments.
llvm/test/CodeGen/AMDGPU/fpext-free.ll
312

I don't think this transform should require "reassoc" on this fmul, should it? %u * %v is calculated the same way before and after the transform. Maybe it should require "reassoc" on the call to fmuladd though, because the add does get reassociated with the fsub.