This is an archive of the discontinued LLVM Phabricator instance.

[MCP] Optimize copies from undef
ClosedPublic

Authored by Pierre-vh on Jun 27 2023, 12:27 AM.

Details

Summary

Revert D152502 and instead optimize away copy from undefs, but clear the undef flag on the original copy.
Apparently, not optimizing the COPY can cause performance issues in some cases.

Fixes SWDEV-405813, SWDEV-405899

Diff Detail

Event Timeline

Pierre-vh created this revision.Jun 27 2023, 12:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2023, 12:27 AM
Pierre-vh requested review of this revision.Jun 27 2023, 12:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2023, 12:27 AM
foad added inline comments.Jun 27 2023, 1:46 AM
llvm/lib/CodeGen/MachineCopyPropagation.cpp
486–487

Doesn't PrevCopyOperands->Source->setIsUndef(false) work?

Pierre-vh added inline comments.Jun 27 2023, 2:42 AM
llvm/lib/CodeGen/MachineCopyPropagation.cpp
486–487

The reference to the MachineOperand is const, unfortunately

arsenm added inline comments.Jun 27 2023, 3:16 PM
llvm/lib/CodeGen/MachineCopyPropagation.cpp
486–487

You can change that?

Pierre-vh marked 2 inline comments as done.Jun 27 2023, 10:55 PM
Pierre-vh added inline comments.
llvm/lib/CodeGen/MachineCopyPropagation.cpp
486–487

It's struct DestSourcePair, it's sometimes initialized from const MachineInstr so I can't just remove the const qualifier there.

An alternative may be to create a copy of that struct and name it MutableDestSourcePair, and use it where relevant.

Pierre-vh marked an inline comment as done.Jun 27 2023, 11:04 PM
Pierre-vh added inline comments.
llvm/lib/CodeGen/MachineCopyPropagation.cpp
486–487

In particular, the issue is with isCopyInstr which is used to generate the value here. It takes a const instruction and many user also pass const instructions, so it'd be a bit of a refactor (not sure how big).

If we really want to avoid the code above, then I will need to create an overload of that function that takes a non-const instr and returns a MutableDestSourcePair.

IMO, the piece of code above is ok and not worth the refactor, but I'd also like to get this in soon as it's a blocker for several tickets so I have no strong opinions - I just need to know how to proceed :)

foad added inline comments.Jun 28 2023, 6:07 AM
llvm/lib/CodeGen/MachineCopyPropagation.cpp
486–487

I think the code above is fine as-is, now that you've explained the reason.

arsenm accepted this revision.Jun 29 2023, 5:53 AM
This revision is now accepted and ready to land.Jun 29 2023, 5:53 AM
Pierre-vh updated this revision to Diff 535759.Jun 29 2023, 6:05 AM

Update tests

This revision was landed with ongoing or failed builds.Jun 29 2023, 6:12 AM
This revision was automatically updated to reflect the committed changes.