@@ -87,16 +87,13 @@ class FixupBWInstPass : public MachineFunctionPass {
8787 // / of the original destination register of the MachineInstr
8888 // / passed in. It returns true if that super register is dead
8989 // / just prior to \p OrigMI, and false if not.
90- // / \pre OrigDestSize must be 8 or 16.
91- bool getSuperRegDestIfDead (MachineInstr *OrigMI, unsigned OrigDestSize,
90+ bool getSuperRegDestIfDead (MachineInstr *OrigMI,
9291 unsigned &SuperDestReg) const ;
9392
9493 // / \brief Change the MachineInstr \p MI into the equivalent extending load
9594 // / to 32 bit register if it is safe to do so. Return the replacement
9695 // / instruction if OK, otherwise return nullptr.
97- // / \pre OrigDestSize must be 8 or 16.
98- MachineInstr *tryReplaceLoad (unsigned New32BitOpcode, unsigned OrigDestSize,
99- MachineInstr *MI) const ;
96+ MachineInstr *tryReplaceLoad (unsigned New32BitOpcode, MachineInstr *MI) const ;
10097
10198public:
10299 FixupBWInstPass () : MachineFunctionPass(ID) {}
@@ -168,31 +165,30 @@ bool FixupBWInstPass::runOnMachineFunction(MachineFunction &MF) {
168165// only portion of SuperDestReg that is alive is the portion that
169166// was the destination register of OrigMI.
170167bool FixupBWInstPass::getSuperRegDestIfDead (MachineInstr *OrigMI,
171- unsigned OrigDestSize,
172168 unsigned &SuperDestReg) const {
169+ auto *TRI = &TII->getRegisterInfo ();
173170
174171 unsigned OrigDestReg = OrigMI->getOperand (0 ).getReg ();
175172 SuperDestReg = getX86SubSuperRegister (OrigDestReg, 32 );
176173
174+ const auto SubRegIdx = TRI->getSubRegIndex (SuperDestReg, OrigDestReg);
175+
177176 // Make sure that the sub-register that this instruction has as its
178177 // destination is the lowest order sub-register of the super-register.
179178 // If it isn't, then the register isn't really dead even if the
180179 // super-register is considered dead.
181- // This test works because getX86SubSuperRegister returns the low portion
182- // register by default when getting a sub-register, so if that doesn't
183- // match the original destination register, then the original destination
184- // register must not have been the low register portion of that size.
185- if (getX86SubSuperRegister (SuperDestReg, OrigDestSize) != OrigDestReg)
180+ if (SubRegIdx == X86::sub_8bit_hi)
186181 return false ;
187182
188183 if (LiveRegs.contains (SuperDestReg))
189184 return false ;
190185
191- if (OrigDestSize == 8 ) {
186+ if (SubRegIdx == X86::sub_8bit ) {
192187 // In the case of byte registers, we also have to check that the upper
193188 // byte register is also dead. That is considered to be independent of
194189 // whether the super-register is dead.
195- unsigned UpperByteReg = getX86SubSuperRegister (SuperDestReg, 8 , true );
190+ unsigned UpperByteReg =
191+ getX86SubSuperRegister (SuperDestReg, 8 , /* High=*/ true );
196192
197193 if (LiveRegs.contains (UpperByteReg))
198194 return false ;
@@ -202,15 +198,14 @@ bool FixupBWInstPass::getSuperRegDestIfDead(MachineInstr *OrigMI,
202198}
203199
204200MachineInstr *FixupBWInstPass::tryReplaceLoad (unsigned New32BitOpcode,
205- unsigned OrigDestSize,
206201 MachineInstr *MI) const {
207202 unsigned NewDestReg;
208203
209204 // We are going to try to rewrite this load to a larger zero-extending
210205 // load. This is safe if all portions of the 32 bit super-register
211206 // of the original destination register, except for the original destination
212207 // register are dead. getSuperRegDestIfDead checks that.
213- if (!getSuperRegDestIfDead (MI, OrigDestSize, NewDestReg))
208+ if (!getSuperRegDestIfDead (MI, NewDestReg))
214209 return nullptr ;
215210
216211 // Safe to change the instruction.
@@ -260,7 +255,7 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
260255 // an extra byte to encode, and provides limited performance upside.
261256 if (MachineLoop *ML = MLI->getLoopFor (&MBB)) {
262257 if (ML->begin () == ML->end () && !OptForSize)
263- NewMI = tryReplaceLoad (X86::MOVZX32rm8, 8 , MI);
258+ NewMI = tryReplaceLoad (X86::MOVZX32rm8, MI);
264259 }
265260 break ;
266261
@@ -269,7 +264,7 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
269264 // Code size is the same, and there is sometimes a perf advantage
270265 // from eliminating a false dependence on the upper portion of
271266 // the register.
272- NewMI = tryReplaceLoad (X86::MOVZX32rm16, 16 , MI);
267+ NewMI = tryReplaceLoad (X86::MOVZX32rm16, MI);
273268 break ;
274269
275270 default :
0 commit comments