aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetInstrInfo.cpp
diff options
context:
space:
mode:
authorSander de Smalen <sander.desmalen@arm.com>2025-07-10 15:30:02 +0100
committerGitHub <noreply@github.com>2025-07-10 15:30:02 +0100
commit362d5ffa8d2f521fc2912665270eba15f3c1bf56 (patch)
tree503f23cc799fa6da12960bc4366f2597d64517ef /llvm/lib/CodeGen/TargetInstrInfo.cpp
parentf56b6ecf088ef46fe8008f294fff456805b33a07 (diff)
downloadllvm-362d5ffa8d2f521fc2912665270eba15f3c1bf56.zip
llvm-362d5ffa8d2f521fc2912665270eba15f3c1bf56.tar.gz
llvm-362d5ffa8d2f521fc2912665270eba15f3c1bf56.tar.bz2
[CodeGen] commuteInstruction should update implicit-def (#131361)
When the RegisterCoalescer adds an implicit-def when coalescing a SUBREG_TO_REG (#123632), this causes issues when removing other COPY nodes by commuting the instruction because it doesn't take the implicit-def into consideration. This PR fixes that.
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);