aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetInstrInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/TargetInstrInfo.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetInstrInfo.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index 8b82deb..660a1a4 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -238,7 +238,14 @@ MachineInstr *TargetInstrInfo::commuteInstructionImpl(MachineInstr &MI,
}
if (HasDef) {
- CommutedMI->getOperand(0).setReg(Reg0);
+ // Use `substituteRegister` so that for a case like this:
+ // %0.sub = INST %0.sub(tied), %1.sub, implicit-def %0
+ // the implicit-def is also updated, to result in:
+ // %1.sub = INST %1.sub(tied), %0.sub, implicit-def %1
+ const TargetRegisterInfo &TRI =
+ *MI.getMF()->getSubtarget().getRegisterInfo();
+ Register FromReg = CommutedMI->getOperand(0).getReg();
+ CommutedMI->substituteRegister(FromReg, Reg0, /*SubRegIdx=*/0, TRI);
CommutedMI->getOperand(0).setSubReg(SubReg0);
}
CommutedMI->getOperand(Idx2).setReg(Reg1);