This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by matejam on Mar 4 2021, 5:03 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 adds two function arguments, extends the result
and multiplies it with the third function argument, and transforms that
into extend instructions combined with some of the fma instruction
depending on the architecture.

Diff Detail

Event Timeline

matejam created this revision.Mar 4 2021, 5:03 AM
matejam requested review of this revision.Mar 4 2021, 5:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2021, 5:03 AM
Herald added a subscriber: wdng. · View Herald Transcript
matejam updated this revision to Diff 329332.Mar 9 2021, 7:15 AM

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

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

Minor changes in CombinerHelper.cpp and in the tests.

matejam updated this revision to Diff 346791.May 20 2021, 10:29 AM

Use mi_match for comparing instructions instead of comparing the opcodes.

matejam updated this revision to Diff 348221.May 27 2021, 4:20 AM

A few minor changes (removal of unnecessary comments).

matejam updated this revision to Diff 375870.Sep 29 2021, 6:59 AM

Use m_MInstr instead of m_Reg in matching patterns (mi_match).
Formatting and refactoring.

matejam updated this revision to Diff 376203.Sep 30 2021, 7:08 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
4376–4382

Use B not Builder.
Also maybe rename from FpExt1 and FpExt2 to FpExtX and FpExtY so it matches the comment above.

4395–4402

(same as above)
Use B not Builder.
Also maybe rename from FpExt1 and FpExt2 to FpExtY and FpExtZ so it matches the comment above.

matejam updated this revision to Diff 376517.Oct 1 2021, 7:22 AM

Changes in tests.

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

LGTM

llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
382–383
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4543

Operand names in this comment don't match variables used below (FpExtX, FpExtY). Either update comment or rename variables below.

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

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