This is an archive of the discontinued LLVM Phabricator instance.

SelectionDAG: Prefer to combine multiplication with less uses for fma
ClosedPublic

Authored by wengxt on Aug 7 2015, 5:37 PM.

Details

Summary

For example:

s6 = s0*s5;
s2 = s6*s6 + s6;
...
s4 = s6*s3;

We notice that it is possible for s2 is folded to fma (s0, s5, fmul (s6 s6)).
This only happens when Aggressive is true, otherwise hasOneUse() check
already prevents from folding the multiplication with more uses.

Test Plan: test/CodeGen/NVPTX/fma-assoc.ll

Patch by Xuetian Weng

Diff Detail

Event Timeline

wengxt updated this revision to Diff 31563.Aug 7 2015, 5:37 PM
wengxt retitled this revision from to SelectionDAG: Prefer to combine multiplication with less uses for fma.
wengxt updated this object.
wengxt added reviewers: jingyue, hfinkel, apazos.
wengxt added a subscriber: llvm-commits.
arsenm added a subscriber: arsenm.Aug 7 2015, 5:44 PM
arsenm added inline comments.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7429–7430

Grammar fixes: "If we have two choices trying to fold (fadd (fmul u, v), (fmul x, y)), prefer to fold the multiply with fewer uses"

7434–7435

Just use std::swap without using

jingyue edited edge metadata.Aug 7 2015, 7:40 PM

LGTM

test/CodeGen/NVPTX/fma-assoc.ll
27

s/choice/choices

#0 is unnecessary

wengxt updated this revision to Diff 31694.Aug 10 2015, 11:17 AM
wengxt marked 2 inline comments as done.
wengxt edited edge metadata.

Address comments

wengxt marked an inline comment as done.Aug 10 2015, 11:18 AM
jingyue added inline comments.Aug 10 2015, 11:23 AM
test/CodeGen/NVPTX/fma-assoc.ll
27

Actually, the metadata is unnecessary too. Without nvvm.annotations, all functions are treated as device functions by llc.

jholewinski added inline comments.Aug 10 2015, 11:35 AM
test/CodeGen/NVPTX/fma-assoc.ll
27

Hrm, this should give an error during compilation. Entry functions are not allowed to return values.

wengxt updated this revision to Diff 31705.Aug 10 2015, 11:48 AM

Address jingyue's comment

wengxt marked an inline comment as done.Aug 10 2015, 11:48 AM
arsenm accepted this revision.Aug 11 2015, 11:54 AM
arsenm added a reviewer: arsenm.

LGTM

This revision is now accepted and ready to land.Aug 11 2015, 11:54 AM
jingyue updated this object.Aug 11 2015, 12:21 PM
jingyue edited edge metadata.
jingyue closed this revision.Aug 11 2015, 12:22 PM