@@ -7205,27 +7205,7 @@ unsigned X86InstrInfo::commuteOperandsForFold(MachineInstr &MI,
7205
7205
if ((HasDef && Reg0 == Reg1 && Tied1) || (HasDef && Reg0 == Reg2 && Tied2))
7206
7206
return Idx1;
7207
7207
7208
- MachineInstr *CommutedMI = commuteInstruction (MI, false , Idx1, Idx2);
7209
- if (!CommutedMI) {
7210
- // Unable to commute.
7211
- return Idx1;
7212
- }
7213
- if (CommutedMI != &MI) {
7214
- // New instruction. We can't fold from this.
7215
- CommutedMI->eraseFromParent ();
7216
- return Idx1;
7217
- }
7218
-
7219
- return Idx2;
7220
- }
7221
-
7222
- void X86InstrInfo::UndoCommuteForFold (MachineInstr &MI, unsigned Idx1,
7223
- unsigned Idx2) const {
7224
- // Folding failed again - undo the commute before returning.
7225
- MachineInstr *UncommutedMI = commuteInstruction (MI, false , Idx1, Idx2);
7226
- // New instruction. It doesn't need to be kept.
7227
- if (UncommutedMI && UncommutedMI != &MI)
7228
- UncommutedMI->eraseFromParent ();
7208
+ return commuteInstruction (MI, false , Idx1, Idx2) ? Idx2 : Idx1;
7229
7209
}
7230
7210
7231
7211
static void printFailMsgforFold (const MachineInstr &MI, unsigned Idx) {
@@ -7369,7 +7349,8 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
7369
7349
Alignment, /* AllowCommute=*/ false );
7370
7350
if (NewMI)
7371
7351
return NewMI;
7372
- UndoCommuteForFold (MI, OpNum, CommuteOpIdx2);
7352
+ // Folding failed again - undo the commute before returning.
7353
+ commuteInstruction (MI, false , OpNum, CommuteOpIdx2);
7373
7354
}
7374
7355
7375
7356
printFailMsgforFold (MI, OpNum);
@@ -8156,7 +8137,8 @@ X86InstrInfo::foldMemoryBroadcast(MachineFunction &MF, MachineInstr &MI,
8156
8137
/* AllowCommute=*/ false );
8157
8138
if (NewMI)
8158
8139
return NewMI;
8159
- UndoCommuteForFold (MI, OpNum, CommuteOpIdx2);
8140
+ // Folding failed again - undo the commute before returning.
8141
+ commuteInstruction (MI, false , OpNum, CommuteOpIdx2);
8160
8142
}
8161
8143
8162
8144
printFailMsgforFold (MI, OpNum);
0 commit comments