@@ -5352,12 +5352,12 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
53525352 MachineInstr *MI = nullptr ;
53535353 MachineInstr *Sub = nullptr ;
53545354 MachineInstr *Movr0Inst = nullptr ;
5355- SmallVector<MachineInstr *, 4 > NDDInsts ;
5355+ SmallVector<std::pair< MachineInstr *, unsigned >, 4 > InstsToUpdate ;
53565356 bool NoSignFlag = false ;
53575357 bool ClearsOverflowFlag = false ;
53585358 bool ShouldUpdateCC = false ;
53595359 bool IsSwapped = false ;
5360- bool HasCF = Subtarget.hasNF ();
5360+ bool HasNF = Subtarget.hasNF ();
53615361 unsigned OpNo = 0 ;
53625362 X86::CondCode NewCC = X86::COND_INVALID;
53635363 int64_t ImmDelta = 0 ;
@@ -5443,10 +5443,13 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
54435443 continue ;
54445444 }
54455445
5446- // Try to replace NDD with NF instructions.
5447- if (HasCF && X86II::hasNewDataDest (Inst.getDesc ().TSFlags ) &&
5448- Inst.registerDefIsDead (X86::EFLAGS, TRI)) {
5449- NDDInsts.push_back (&Inst);
5446+ // Try to replace non-NF with NF instructions.
5447+ if (HasNF && Inst.registerDefIsDead (X86::EFLAGS, TRI)) {
5448+ unsigned NewOp = X86::getNFVariant (Inst.getOpcode ());
5449+ if (!NewOp)
5450+ return false ;
5451+
5452+ InstsToUpdate.push_back (std::make_pair (&Inst, NewOp));
54505453 continue ;
54515454 }
54525455
@@ -5646,10 +5649,10 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
56465649 return false ;
56475650 }
56485651
5649- // Replace NDD with NF instructions.
5650- for (MachineInstr *NDD : NDDInsts ) {
5651- NDD ->setDesc (get (X86::getNFVariant (NDD-> getOpcode ()) ));
5652- NDD ->removeOperand (NDD ->getNumOperands () - 1 );
5652+ // Replace non-NF with NF instructions.
5653+ for (auto &Inst : InstsToUpdate ) {
5654+ Inst. first ->setDesc (get (Inst. second ));
5655+ Inst. first ->removeOperand (Inst. first ->getNumOperands () - 1 );
56535656 }
56545657
56555658 // Make sure Sub instruction defines EFLAGS and mark the def live.
0 commit comments