This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by matejam on Mar 4 2021, 5:06 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 that has a fma/fmad instruction as an operand for
the given MI. The transformed instruction has a fma/fmad instruction
inside another fma/fmad instruction.

Diff Detail

Event Timeline

matejam created this revision.Mar 4 2021, 5:06 AM
matejam requested review of this revision.Mar 4 2021, 5:06 AM
matejam updated this revision to Diff 329333.Mar 9 2021, 7:16 AM

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

matejam updated this revision to Diff 343372.May 6 2021, 5:46 AM

Minor changes in CombinerHelper.cpp and in the tests.

matejam updated this revision to Diff 346790.May 20 2021, 10:28 AM

Use mi_match for comparing instructions instead of comparing the opcodes.

matejam updated this revision to Diff 349873.Jun 4 2021, 7:44 AM

Typos and refactoring.

matejam updated this revision to Diff 375871.Sep 29 2021, 7:03 AM

Use m_MInstr instead of m_Reg in matching patterns (mi_match).
Use CanReassociate as a parameter in canCombineFMadOrFMA with a default value.
Formatting and refactoring.

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

Use applyBuildFn instead of writing my own apply.

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

This matches to fmul in pattern in comment above. Better to rename to FMul.

4472–4475

Use B not Builder.

You can just pass DstTy for dst instead of making TmpReg and get it below with .getReg(0). Or at lease rename it to FMA or InnerFMA.

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

Changes in tests.

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

LGTM (with a nit)

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4589–4593

use hasMoreUses

This revision is now accepted and ready to land.Nov 3 2021, 10:49 AM
matejam updated this revision to Diff 390326.Nov 29 2021, 6:09 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.