@@ -84,18 +84,18 @@ static bool handleInstructionWithEGPR(MachineFunction &MF,
8484 if (!ST.hasEGPR ())
8585 return false ;
8686
87- auto suppressEGPRInRegs = [&](MachineInstr &MI,
87+ auto suppressEGPRInInstrWithReloc = [&](MachineInstr &MI,
8888 ArrayRef<unsigned > OpNoArray) {
8989 int MemOpNo = X86II::getMemoryOperandNo (MI.getDesc ().TSFlags ) +
9090 X86II::getOperandBias (MI.getDesc ());
9191 auto &MO = MI.getOperand (X86::AddrDisp + MemOpNo);
9292 if (MO.getTargetFlags () == X86II::MO_GOTTPOFF ||
9393 MO.getTargetFlags () == X86II::MO_GOTPCREL) {
94- LLVM_DEBUG (dbgs () << " Transform instruction with relocation type: " << MI
95- << " \n " );
94+ LLVM_DEBUG (dbgs () << " Transform instruction with relocation type:\n "
95+ << MI );
9696 for (auto OpNo : OpNoArray)
9797 suppressEGPRRegClass (MF, MI, OpNo);
98- LLVM_DEBUG (dbgs () << " to\n " << MI << " \n " );
98+ LLVM_DEBUG (dbgs () << " to: \n " << MI << " \n " );
9999 }
100100 };
101101
@@ -109,14 +109,14 @@ static bool handleInstructionWithEGPR(MachineFunction &MF,
109109 // in this pass (before emitting assembly).
110110 case X86::TEST32mr:
111111 case X86::TEST64mr: {
112- suppressEGPRInRegs (MI, {5 });
112+ suppressEGPRInInstrWithReloc (MI, {5 });
113113 break ;
114114 }
115115 case X86::CMP32rm:
116116 case X86::CMP64rm:
117117 case X86::MOV32rm:
118118 case X86::MOV64rm: {
119- suppressEGPRInRegs (MI, {0 });
119+ suppressEGPRInInstrWithReloc (MI, {0 });
120120 break ;
121121 }
122122 case X86::ADC32rm:
@@ -133,7 +133,7 @@ static bool handleInstructionWithEGPR(MachineFunction &MF,
133133 case X86::SBB64rm:
134134 case X86::SUB64rm:
135135 case X86::XOR64rm: {
136- suppressEGPRInRegs (MI, {0 , 1 });
136+ suppressEGPRInInstrWithReloc (MI, {0 , 1 });
137137 break ;
138138 }
139139 }
@@ -144,7 +144,7 @@ static bool handleInstructionWithEGPR(MachineFunction &MF,
144144
145145static bool handleNDDOrNFInstructions (MachineFunction &MF,
146146 const X86Subtarget &ST) {
147- if (!ST.hasNDD () && !ST. hasNF () )
147+ if (!ST.hasNDD ())
148148 return false ;
149149
150150 auto TII = ST.getInstrInfo ();
@@ -162,39 +162,36 @@ static bool handleNDDOrNFInstructions(MachineFunction &MF,
162162 X86II::getOperandBias (MI.getDesc ());
163163 auto &MO = MI.getOperand (X86::AddrDisp + MemOpNo);
164164 if (MO.getTargetFlags () == X86II::MO_GOTTPOFF) {
165- LLVM_DEBUG (dbgs () << " Transform instruction with relocation type: "
166- << MI << " \n " );
165+ LLVM_DEBUG (dbgs () << " Transform instruction with relocation type:\n "
166+ << MI);
167167 Register Reg = MRI->createVirtualRegister (&X86::GR64_NOREX2RegClass);
168- auto &CopyMI = BuildMI (MBB, MI, MI.getDebugLoc (),
169- TII->get (TargetOpcode::COPY), Reg)
170- .addReg (MI.getOperand (1 ).getReg ());
171- auto &NewMI =
172- BuildMI (MBB, MI, MI.getDebugLoc (), TII->get (X86::ADD64rm),
173- MI.getOperand (0 ).getReg ())
174- .addReg (Reg)
175- .addReg (MI.getOperand (2 ).getReg ())
176- .addImm (MI.getOperand (3 ).getImm ())
177- .addReg (MI.getOperand (4 ).getReg ())
178- .add (MI.getOperand (5 ))
179- .addReg (MI.getOperand (6 ).getReg ());
180- suppressEGPRRegClass (MF, *NewMI, 0 );
181- MI.eraseFromParent ();
168+ auto &CopyMI =
169+ BuildMI (MBB, MI, MI.getDebugLoc (), TII->get (TargetOpcode::COPY),
170+ Reg)
171+ .addReg (MI.getOperand (1 ).getReg ());
172+ MI.getOperand (1 ).setReg (Reg);
173+ const MCInstrDesc &NewDesc = TII->get (X86::ADD64rm);
174+ MI.setDesc (NewDesc);
175+ suppressEGPRRegClass (MF, MI, 0 );
176+ MI.tieOperands (0 , 1 );
182177 LLVM_DEBUG (dbgs () << " to:\n " << *CopyMI << " \n " );
183- LLVM_DEBUG (dbgs () << " " << *NewMI << " \n " );
178+ LLVM_DEBUG (dbgs () << " " << MI << " \n " );
184179 }
185180 break ;
186181 }
187182 case X86::ADD64mr_ND: {
188183 int MemRefBegin = X86II::getMemoryOperandNo (MI.getDesc ().TSFlags );
189184 auto &MO = MI.getOperand (MemRefBegin + X86::AddrDisp);
190185 if (MO.getTargetFlags () == X86II::MO_GOTTPOFF) {
191- LLVM_DEBUG (dbgs () << " Transform instruction with relocation type: "
192- << MI << " \n " );
186+ LLVM_DEBUG (dbgs () << " Transform instruction with relocation type:\n "
187+ << MI);
188+ suppressEGPRRegClass (MF, MI, 0 );
193189 Register Reg = MRI->createVirtualRegister (&X86::GR64_NOREX2RegClass);
194- auto &CopyMI = BuildMI (MBB, MI, MI.getDebugLoc (),
195- TII->get (TargetOpcode::COPY), Reg)
196- .addReg (MI.getOperand (6 ).getReg ());
197- [[maybe_unused]] auto &NewMI =
190+ auto &CopyMI =
191+ BuildMI (MBB, MI, MI.getDebugLoc (), TII->get (TargetOpcode::COPY),
192+ Reg)
193+ .addReg (MI.getOperand (6 ).getReg ());
194+ auto &NewMI =
198195 BuildMI (MBB, MI, MI.getDebugLoc (), TII->get (X86::ADD64rm),
199196 MI.getOperand (0 ).getReg ())
200197 .addReg (Reg)
@@ -203,7 +200,6 @@ static bool handleNDDOrNFInstructions(MachineFunction &MF,
203200 .addReg (MI.getOperand (3 ).getReg ())
204201 .add (MI.getOperand (4 ))
205202 .addReg (MI.getOperand (5 ).getReg ());
206- suppressEGPRRegClass (MF, *NewMI, 0 );
207203 MI.eraseFromParent ();
208204 LLVM_DEBUG (dbgs () << " to:\n " << *CopyMI << " \n " );
209205 LLVM_DEBUG (dbgs () << " " << *NewMI << " \n " );
0 commit comments