Skip to content

Commit bd6e77c

Browse files
authored
[X86] Convert X86FixupBWInsts from LivePhysRegs to LiveRegUnits. NFCI. (#65592)
This gives a geomean 0.50% speed up according to https://llvm-compile-time-tracker.com/
1 parent 3276ac8 commit bd6e77c

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

llvm/lib/Target/X86/X86FixupBWInsts.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include "llvm/ADT/Statistic.h"
5151
#include "llvm/Analysis/ProfileSummaryInfo.h"
5252
#include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
53-
#include "llvm/CodeGen/LivePhysRegs.h"
53+
#include "llvm/CodeGen/LiveRegUnits.h"
5454
#include "llvm/CodeGen/MachineFunctionPass.h"
5555
#include "llvm/CodeGen/MachineInstrBuilder.h"
5656
#include "llvm/CodeGen/MachineLoopInfo.h"
@@ -145,7 +145,7 @@ class FixupBWInstPass : public MachineFunctionPass {
145145
MachineLoopInfo *MLI = nullptr;
146146

147147
/// Register Liveness information after the current instruction.
148-
LivePhysRegs LiveRegs;
148+
LiveRegUnits LiveUnits;
149149

150150
ProfileSummaryInfo *PSI = nullptr;
151151
MachineBlockFrequencyInfo *MBFI = nullptr;
@@ -169,7 +169,7 @@ bool FixupBWInstPass::runOnMachineFunction(MachineFunction &MF) {
169169
MBFI = (PSI && PSI->hasProfileSummary()) ?
170170
&getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI() :
171171
nullptr;
172-
LiveRegs.init(TII->getRegisterInfo());
172+
LiveUnits.init(TII->getRegisterInfo());
173173

174174
LLVM_DEBUG(dbgs() << "Start X86FixupBWInsts\n";);
175175

@@ -202,22 +202,21 @@ Register FixupBWInstPass::getSuperRegDestIfDead(MachineInstr *OrigMI) const {
202202
if (SubRegIdx == X86::sub_8bit_hi)
203203
return Register();
204204

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+
}
220217
}
218+
if (!SuperIsLive)
219+
return SuperDestReg;
221220

222221
// If we get here, the super-register destination (or some part of it) is
223222
// marked as live after the original instruction.
@@ -449,9 +448,9 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
449448

450449
// Start computing liveness for this block. We iterate from the end to be able
451450
// to update this for each instruction.
452-
LiveRegs.clear();
451+
LiveUnits.clear();
453452
// We run after PEI, so we need to AddPristinesAndCSRs.
454-
LiveRegs.addLiveOuts(MBB);
453+
LiveUnits.addLiveOuts(MBB);
455454

456455
OptForSize = MF.getFunction().hasOptSize() ||
457456
llvm::shouldOptimizeForSize(&MBB, PSI, MBFI);
@@ -461,7 +460,7 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
461460
MIReplacements.push_back(std::make_pair(&MI, NewMI));
462461

463462
// We're done with this instruction, update liveness for the next one.
464-
LiveRegs.stepBackward(MI);
463+
LiveUnits.stepBackward(MI);
465464
}
466465

467466
while (!MIReplacements.empty()) {

0 commit comments

Comments
 (0)