This is an archive of the discontinued LLVM Phabricator instance.

GlobalIsel: Fix fma combine when one of the uses comes from unmerge
ClosedPublic

Authored by Petar.Avramovic on Jan 11 2022, 9:02 AM.

Details

Summary

Fma combine assumes that MRI.getVRegDef(Reg)->getOperand(0).getReg() = Reg
which is not true when Reg is defined by instruction with multiple defs
e.g. G_UNMERGE_VALUES.
Fix is to keep register and the instruction that defines register in
DefinitionAndSourceRegister and use when needed.

Diff Detail

Event Timeline

Petar.Avramovic requested review of this revision.Jan 11 2022, 9:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 11 2022, 9:02 AM
arsenm accepted this revision.Jan 11 2022, 9:04 AM

LGTM. I think we should move APIs away from MachineInstr based tracking and towards value based approaches, closer to SDValue

This revision is now accepted and ready to land.Jan 11 2022, 9:04 AM

TODO: do the same for remaining fma combines.

llvm/test/CodeGen/AMDGPU/GlobalISel/combine-fma-add-mul-post-legalize.mir
222

This is element 0

222

but it should be element 1

Previous version already had llvm-ir test with fma pattern covered in matchCombineFAddFMulToFMadOrFMA.
Cover remaining potential errors when MRI.getVRegDef(Reg)->getOperand(0).getReg() is used. Adding targeted mir tests for all these cases.
I don't have llvm-ir tests for these since they seem to combine before legalizer, unmerges that causes bad combine are generated in legalizer.

arsenm accepted this revision.Jan 12 2022, 7:42 AM
This revision was landed with ongoing or failed builds.Jan 12 2022, 8:48 AM
This revision was automatically updated to reflect the committed changes.