Page MenuHomePhabricator

[AMDGPU][GlobalISel] Transform (fsub (fpext (fneg (fmul x, y))), z) -> (fneg (fma (fpext x), (fpext y), z))
Needs ReviewPublic

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

Details

Summary

Instead of sub 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 one multiplication, which gets negated and
extended, and from that the third argument is subtracted. This combiner
will transform that into two extends and one negation within the fma/fmad
instruction.

Diff Detail

Event Timeline

matejam created this revision.Mar 5 2021, 7:51 AM
matejam requested review of this revision.Mar 5 2021, 7:51 AM
matejam updated this revision to Diff 329340.Mar 9 2021, 7:19 AM

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

arsenm requested changes to this revision.Mar 31 2021, 4:23 PM
arsenm added inline comments.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4481–4482

First, fadd only has as single type index. Second, I don't think there's much point in checking it's legality. It doesn't imply "LegalOperations"

4488

We have a separate check for before the legalizer. FMA also only has one type index

4527

Should probably be using mi_matches for all of these instead of your own getVRegDefs and nested ifs

This revision now requires changes to proceed.Mar 31 2021, 4:23 PM
matejam updated this revision to Diff 343377.May 6 2021, 5:50 AM

Minor changes in CombinerHelper.cpp and in the tests.

arsenm added inline comments.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4725

Should have mi_match support for fneg/fpext and use that

matejam updated this revision to Diff 346782.May 20 2021, 10:24 AM

Use mi_match for comparing instructions instead of comparing the opcodes.

matejam updated this revision to Diff 346784.May 20 2021, 10:25 AM

Use mi_match for comparing instructions instead of comparing the opcodes.