This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix regression due to interaction of MachineOutliner and MachineCopyPropagation
ClosedPublic

Authored by asb on Mar 14 2023, 5:41 AM.

Details

Summary

D144535 enabled machine copy propagation for RISC-V and added it to the pass pipeline in addPreEmitPass2 (after the MachineOutliner). Unfortunately, the MachineCopyPropagation pass is unable to correctly analyse outlined functions, and will delete copy instructions where a register is set that is intended to be live-out. RISCVInstrInfo::buildOutlinedFrame will directly insert a JALR, while a similar function going through the normal codegen path would have a PseudoRet with operands indicating registers that are live-out.

This patch does the simplest fix, which is to run MachineCopyPropagation before the MachineOutliner. I think it would make sense to land something like this quickly, but I'd also be interested in discussing thoughts on a "better" follow-up fix that might allow MCP to run later in the pipeline.

Diff Detail

Event Timeline

asb created this revision.Mar 14 2023, 5:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2023, 5:41 AM
asb requested review of this revision.Mar 14 2023, 5:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2023, 5:41 AM
asb edited reviewers, added: wangpc, craig.topper, reames; removed: llvm-commits.Mar 14 2023, 5:42 AM
asb added a subscriber: llvm-commits.
This revision is now accepted and ready to land.Mar 14 2023, 8:41 AM
This revision was landed with ongoing or failed builds.Mar 14 2023, 10:56 AM
This revision was automatically updated to reflect the committed changes.

Thanks for the fix!

I posted two patches that may be approach to fix this issue:

  • D146191: [MachineOutliner][MCP][RISCV] Don't run MCP on outlined functions.
  • D146192: [RISCV] Add an empty block after outlined MBB.