[llvm] [TailDup][MachineSSAUpdater] Let RewriteUse insert a COPY when needed (PR #95553)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 01:37:06 PDT 2024
================
@@ -236,6 +236,20 @@ void MachineSSAUpdater::RewriteUse(MachineOperand &U) {
NewVR = GetValueInMiddleOfBlock(UseMI->getParent());
}
+ // Insert a COPY if needed to satisfy register class constraints for the using
+ // MO. Or, if possible, just constrain the class for NewVR to avoid the need
+ // for a COPY.
+ const TargetRegisterClass *UseRC =
+ dyn_cast_or_null<const TargetRegisterClass *>(RegAttrs.RCOrRB);
+ if (NewVR && UseRC && !MRI->constrainRegClass(NewVR, UseRC)) {
+ MachineBasicBlock *UseBB = UseMI->getParent();
+ MachineInstr *InsertedCopy =
+ InsertNewDef(TargetOpcode::COPY, UseBB, UseBB->getFirstNonPHI(),
+ RegAttrs, MRI, TII)
+ .addReg(NewVR);
+ NewVR = InsertedCopy->getOperand(0).getReg();
+ LLVM_DEBUG(dbgs() << " Inserted COPY: " << *InsertedCopy << "\n");
----------------
arsenm wrote:
Don't need the newline, it's implied in the << for MachineInstr
https://github.com/llvm/llvm-project/pull/95553
More information about the llvm-commits
mailing list