This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add isCommutable to scalar FMA instructions.
ClosedPublic

Authored by craig.topper on Apr 26 2022, 9:23 AM.

Details

Summary

The default implementation of findCommutedOpIndices picks the
first two source operands. That's exactly what we want for the
scalar FMA instructions.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 26 2022, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 9:23 AM
craig.topper requested review of this revision.Apr 26 2022, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 9:23 AM

Declaring a three operand opcode as commutative when only two of the arguments can be safely commuted feels rather suspect to me.

Declaring a three operand opcode as commutative when only two of the arguments can be safely commuted feels rather suspect to me.

The commutable operands are determined by TargetInstrInfo::findCommutedOpIndices. The default implementation picks the first two source operands. X86 relies on this for commuting AMD's FMA4 instructions. For the FMA3 instructions, X86 overrides TargetInstrInfo::findCommutedOpIndices and calls X86InstrInfo::findThreeSrcCommutedOpIndices. An additional override of TargetInstrInfo::commuteInstructionImpl is used to change the opcode for FMA3.

Should I add more tests or more comments or both?

reames accepted this revision.Apr 26 2022, 11:54 AM

Declaring a three operand opcode as commutative when only two of the arguments can be safely commuted feels rather suspect to me.

The commutable operands are determined by TargetInstrInfo::findCommutedOpIndices. The default implementation picks the first two source operands. X86 relies on this for commuting AMD's FMA4 instructions. For the FMA3 instructions, X86 overrides TargetInstrInfo::findCommutedOpIndices and calls X86InstrInfo::findThreeSrcCommutedOpIndices. An additional override of TargetInstrInfo::commuteInstructionImpl is used to change the opcode for FMA3.

Should I add more tests or more comments or both?

I'm not arguing correctness of the change, just that it is quite confusingly structured. However, I went and dug through the existing code as you suggested, and you're definitely right that backends rely on the first-two-non-def-operands thing already. This isn't adding new weirdness, it's just matching what everyone else already does.

Given that, LGTM.

This revision is now accepted and ready to land.Apr 26 2022, 11:54 AM
This revision was landed with ongoing or failed builds.Apr 27 2022, 11:17 AM
This revision was automatically updated to reflect the committed changes.