Skip to content

Commit 5950e82

Browse files
committed
address comment
1 parent 7a347d8 commit 5950e82

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,38 +214,38 @@ MachineInstr *TargetInstrInfo::commuteInstructionImpl(MachineInstr &MI,
214214
Reg1.isPhysical() ? MI.getOperand(Idx1).isRenamable() : false;
215215
bool Reg2IsRenamable =
216216
Reg2.isPhysical() ? MI.getOperand(Idx2).isRenamable() : false;
217-
// If destination is tied to either of the commuted source register, then
218-
// it must be updated.
219-
if (HasDef && Reg0 == Reg1 &&
220-
MI.getDesc().getOperandConstraint(Idx1, MCOI::TIED_TO) == 0) {
221-
Reg2IsKill = false;
222-
Reg0 = Reg2;
223-
SubReg0 = SubReg2;
224-
} else if (HasDef && Reg0 == Reg2 &&
225-
MI.getDesc().getOperandConstraint(Idx2, MCOI::TIED_TO) == 0) {
226-
Reg1IsKill = false;
227-
Reg0 = Reg1;
228-
SubReg0 = SubReg1;
229-
}
230217

231218
// For a case like this:
232219
// %0.sub = INST %0.sub(tied), %1.sub, implicit-def %0
233220
// we need to update the implicit-def after commuting to result in:
234221
// %1.sub = INST %1.sub(tied), %0.sub, implicit-def %1
235222
SmallVector<unsigned> UpdateImplicitDefIdx;
236-
if (HasDef && MI.hasImplicitDef() && MI.getOperand(0).getReg() != Reg0) {
223+
if (HasDef && MI.hasImplicitDef() && MI.getOperand(0).getReg() == Reg0) {
237224
const TargetRegisterInfo *TRI =
238225
MI.getMF()->getSubtarget().getRegisterInfo();
239-
Register OrigReg0 = MI.getOperand(0).getReg();
240226
for (auto [OpNo, MO] : llvm::enumerate(MI.implicit_operands())) {
241227
Register ImplReg = MO.getReg();
242-
if ((ImplReg.isVirtual() && ImplReg == OrigReg0) ||
243-
(ImplReg.isPhysical() && OrigReg0.isPhysical() &&
244-
TRI->isSubRegisterEq(ImplReg, OrigReg0)))
228+
if ((ImplReg.isVirtual() && ImplReg == Reg0) ||
229+
(ImplReg.isPhysical() && Reg0.isPhysical() &&
230+
TRI->isSubRegisterEq(ImplReg, Reg0)))
245231
UpdateImplicitDefIdx.push_back(OpNo + MI.getNumExplicitOperands());
246232
}
247233
}
248234

235+
// If destination is tied to either of the commuted source register, then
236+
// it must be updated.
237+
if (HasDef && Reg0 == Reg1 &&
238+
MI.getDesc().getOperandConstraint(Idx1, MCOI::TIED_TO) == 0) {
239+
Reg2IsKill = false;
240+
Reg0 = Reg2;
241+
SubReg0 = SubReg2;
242+
} else if (HasDef && Reg0 == Reg2 &&
243+
MI.getDesc().getOperandConstraint(Idx2, MCOI::TIED_TO) == 0) {
244+
Reg1IsKill = false;
245+
Reg0 = Reg1;
246+
SubReg0 = SubReg1;
247+
}
248+
249249
MachineInstr *CommutedMI = nullptr;
250250
if (NewMI) {
251251
// Create a new instruction.

0 commit comments

Comments
 (0)