50
50
#include " llvm/ADT/Statistic.h"
51
51
#include " llvm/Analysis/ProfileSummaryInfo.h"
52
52
#include " llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
53
- #include " llvm/CodeGen/LivePhysRegs .h"
53
+ #include " llvm/CodeGen/LiveRegUnits .h"
54
54
#include " llvm/CodeGen/MachineFunctionPass.h"
55
55
#include " llvm/CodeGen/MachineInstrBuilder.h"
56
56
#include " llvm/CodeGen/MachineLoopInfo.h"
@@ -145,7 +145,7 @@ class FixupBWInstPass : public MachineFunctionPass {
145
145
MachineLoopInfo *MLI = nullptr ;
146
146
147
147
// / Register Liveness information after the current instruction.
148
- LivePhysRegs LiveRegs ;
148
+ LiveRegUnits LiveUnits ;
149
149
150
150
ProfileSummaryInfo *PSI = nullptr ;
151
151
MachineBlockFrequencyInfo *MBFI = nullptr ;
@@ -169,7 +169,7 @@ bool FixupBWInstPass::runOnMachineFunction(MachineFunction &MF) {
169
169
MBFI = (PSI && PSI->hasProfileSummary ()) ?
170
170
&getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI () :
171
171
nullptr ;
172
- LiveRegs .init (TII->getRegisterInfo ());
172
+ LiveUnits .init (TII->getRegisterInfo ());
173
173
174
174
LLVM_DEBUG (dbgs () << " Start X86FixupBWInsts\n " ;);
175
175
@@ -202,22 +202,21 @@ Register FixupBWInstPass::getSuperRegDestIfDead(MachineInstr *OrigMI) const {
202
202
if (SubRegIdx == X86::sub_8bit_hi)
203
203
return Register ();
204
204
205
- // If neither the destination-super register nor any applicable subregisters
206
- // are live after this instruction, then the super register is safe to use.
207
- if (!LiveRegs.contains (SuperDestReg)) {
208
- // If the original destination register was not the low 8-bit subregister
209
- // then the super register check is sufficient.
210
- if (SubRegIdx != X86::sub_8bit)
211
- return SuperDestReg;
212
- // If the original destination register was the low 8-bit subregister and
213
- // we also need to check the 16-bit subregister and the high 8-bit
214
- // subregister.
215
- MCRegister HighReg = getX86SubSuperRegister (SuperDestReg, 8 , /* High=*/ true );
216
- if (!LiveRegs.contains (getX86SubSuperRegister (OrigDestReg, 16 )) &&
217
- (!HighReg.isValid () || !LiveRegs.contains (HighReg)))
218
- return SuperDestReg;
219
- // Otherwise, we have a little more checking to do.
205
+ // Test all regunits of the super register that are not part of the
206
+ // sub register. If none of them are live then the super register is safe to
207
+ // use.
208
+ bool SuperIsLive = false ;
209
+ auto Range = TRI->regunits (OrigDestReg);
210
+ MCRegUnitIterator I = Range.begin (), E = Range.end ();
211
+ for (MCRegUnit S : TRI->regunits (SuperDestReg)) {
212
+ I = std::lower_bound (I, E, S);
213
+ if ((I == E || *I > S) && LiveUnits.getBitVector ().test (S)) {
214
+ SuperIsLive = true ;
215
+ break ;
216
+ }
220
217
}
218
+ if (!SuperIsLive)
219
+ return SuperDestReg;
221
220
222
221
// If we get here, the super-register destination (or some part of it) is
223
222
// marked as live after the original instruction.
@@ -449,9 +448,9 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
449
448
450
449
// Start computing liveness for this block. We iterate from the end to be able
451
450
// to update this for each instruction.
452
- LiveRegs .clear ();
451
+ LiveUnits .clear ();
453
452
// We run after PEI, so we need to AddPristinesAndCSRs.
454
- LiveRegs .addLiveOuts (MBB);
453
+ LiveUnits .addLiveOuts (MBB);
455
454
456
455
OptForSize = MF.getFunction ().hasOptSize () ||
457
456
llvm::shouldOptimizeForSize (&MBB, PSI, MBFI);
@@ -461,7 +460,7 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
461
460
MIReplacements.push_back (std::make_pair (&MI, NewMI));
462
461
463
462
// We're done with this instruction, update liveness for the next one.
464
- LiveRegs .stepBackward (MI);
463
+ LiveUnits .stepBackward (MI);
465
464
}
466
465
467
466
while (!MIReplacements.empty ()) {
0 commit comments