This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU][GlobalISel] Transform (fadd (fma x, y, (fpext (fmul u, v))), z) -> (fma x, y, (fma (fpext u), (fpext v), z))
ClosedPublic

Authored by matejam on Mar 5 2021, 7:39 AM.

Details

Summary

Instead of add and mul instructions, use v_mad, v_mac or v_fma if fma
instructions are faster and are legal for the given architecture.
Combiner for a case in which two function arguments are multiplied, the
result of the multiplication gets extended, which gets added to the
result of the multiplication of another two arguments, and the result
of that gets added to the last function argument. The result of the
combiner will be a fma instruction within a fma instruction.

Diff Detail

Event Timeline

matejam created this revision.Mar 5 2021, 7:39 AM
matejam requested review of this revision.Mar 5 2021, 7:39 AM
matejam updated this revision to Diff 329334.Mar 9 2021, 7:17 AM

Put back the accidentally deleted combiner from the list of combiners (load_or_combine).

matejam updated this revision to Diff 343373.May 6 2021, 5:47 AM

Minor changes in CombinerHelper.cpp and in the tests.

matejam updated this revision to Diff 346788.May 20 2021, 10:27 AM

Use mi_match for comparing instructions instead of comparing the opcodes.

matejam updated this revision to Diff 349872.Jun 4 2021, 7:43 AM

Typos and refactoring.

matejam updated this revision to Diff 375872.Sep 29 2021, 7:04 AM

Use m_MInstr instead of m_Reg in matching patterns (mi_match).
A few minor bug fixes.
Formatting and refactoring.

matejam updated this revision to Diff 376205.Sep 30 2021, 7:09 AM

Use applyBuildFn instead of writing my own apply.

mbrkusanin added inline comments.Sep 30 2021, 7:48 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
5063

Use B not Builder. Same for everywhere else below.

5076–5080

These are fpext for X and Y which do not happen in this pattern. Just remove these lines.

5113–5117

You already checked above for m_GFPExt(m_MInstr(FMAMI))
In this case you always need to build fpext for X and Y.

5149–5152

(same as first fold)
These are fpext for X and Y which do not happen in this pattern. Just remove these lines.

5186–5189

(same as second fold)
You already checked above for m_GFPExt(m_MInstr(FMAMI))
In this case you always need to build fpext for X and Y.

matejam updated this revision to Diff 376519.Oct 1 2021, 7:23 AM

Changes in tests.

mbrkusanin accepted this revision.Nov 3 2021, 10:50 AM

LGTM with a few nits

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
5030–5033

Put this after canCombineFMadOrFMA call and !Agressive check

5053

Maybe add a comment for what this builds

This revision is now accepted and ready to land.Nov 3 2021, 10:50 AM
matejam updated this revision to Diff 390327.Nov 29 2021, 6:10 AM

Added missing comments and an FMA combiner group in table gen.

This revision was landed with ongoing or failed builds.Nov 29 2021, 7:28 AM
This revision was automatically updated to reflect the committed changes.