This is an archive of the discontinued LLVM Phabricator instance.

[SVE] Add pattern to commute FMLS operands
ClosedPublic

Authored by cameron.mcinally on Feb 25 2022, 8:35 AM.

Details

Summary

AArch64ISD::FMA_PRED nodes with negated operands are matching to suboptimal hardware instructions. We can commute the multiplication operands to generate better instruction sequences. This patch adds a pattern to commute operands for an unmasked FMSB instruction.

I'll try to send matching patches for predicated FMLS and FNMLA patterns soon, assuming this is accepted. Although, if someone is motivated to rework this multiclass in a cohesive way, please feel free.

Diff Detail

Event Timeline

cameron.mcinally requested review of this revision.Feb 25 2022, 8:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2022, 8:35 AM
paulwalker-arm added inline comments.Feb 28 2022, 4:40 AM
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
562–563

Perhaps you can create a PatFrags called AArch64fmls_p that contains the two compatible forms of AArch64fma_p. You should then be able to update the relevant patterns here instead of needing new ones. See AArch64bic for inspiration.

Updated Diff to implement commuting with PatFrags.

@paulwalker-arm, I wasn't sure if the PatFrags live at the head of the file, or close to the pattern that uses them. I chose the head. Keep an eye out for that.

cameron.mcinally marked an inline comment as done.Feb 28 2022, 12:55 PM

@paulwalker-arm, I wasn't sure if the PatFrags live at the head of the file, or close to the pattern that uses them. I chose the head. Keep an eye out for that.

PatFrags placement looks perfect to me.

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
296–299

When creating the PatFrags you want the ops operands to be treated consistently. In this instance you always want $op1 to be the negated operand because that is the operand that will be negated by the instruction you'll eventually match it to. So the first pattern is fine but the second should switch the usage of $op1 and $op2.

paulwalker-arm added inline comments.Feb 28 2022, 1:31 PM
llvm/test/CodeGen/AArch64/sve-fp.ll
321–323

Can these tests treat the operands the same as the fma tests. You're currently treating %c as the addend whereas the existing tests have this as %a. The output will likely change to fmls instead of fmsb but that seems find to me.

paulwalker-arm added inline comments.Feb 28 2022, 1:37 PM
llvm/test/CodeGen/AArch64/sve-fp.ll
321–323

I've just checked and these negated patterns are tested within sve-fp-combine.ll so I think that'll be a better home for your new tests.

llvm/test/CodeGen/AArch64/sve-fp.ll
321–323

I saw that file when I added the tests. The sve-fp-combine.ll tests all deal with FMUL+[FADD|FSUB] IR. There are no intrinsic tests in that file, so a little bit of a weird fit.

I don't have a preference on where these tests live though, so it's up to you...

paulwalker-arm added inline comments.Mar 1 2022, 7:51 AM
llvm/test/CodeGen/AArch64/sve-fp.ll
321–323

Oh, I see what you mean. I only focused on the output. In which case feel free to keep the tests here.

Addressed Paul's review...

cameron.mcinally marked 4 inline comments as done.Mar 1 2022, 8:21 AM
cameron.mcinally retitled this revision from [SVE] Add pattern to commute FMSB operands to [SVE] Add pattern to commute FMLS operands.Mar 1 2022, 8:46 AM
cameron.mcinally edited the summary of this revision. (Show Details)
paulwalker-arm accepted this revision.Mar 1 2022, 8:53 AM
This revision is now accepted and ready to land.Mar 1 2022, 8:53 AM
This revision was landed with ongoing or failed builds.Mar 1 2022, 12:53 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 12:53 PM