[llvm] b504152 - DeadMachineInstructionElim: Switch to using LiveRegUnits
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 12 05:15:15 PDT 2022
Author: Matt Arsenault
Date: 2022-09-12T07:55:14-04:00
New Revision: b5041527c75de2f409aa9e2e6deba12b17834c59
URL: https://github.com/llvm/llvm-project/commit/b5041527c75de2f409aa9e2e6deba12b17834c59
DIFF: https://github.com/llvm/llvm-project/commit/b5041527c75de2f409aa9e2e6deba12b17834c59.diff
LOG: DeadMachineInstructionElim: Switch to using LiveRegUnits
Theoretically improves compile time for targets with many overlapping
registers
Added:
Modified:
llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
llvm/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
index ce00be634e9a5..021744d1e9a36 100644
--- a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
+++ b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/CodeGen/LiveRegUnits.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
@@ -30,10 +31,9 @@ namespace {
class DeadMachineInstructionElim : public MachineFunctionPass {
bool runOnMachineFunction(MachineFunction &MF) override;
- const TargetRegisterInfo *TRI;
const MachineRegisterInfo *MRI;
const TargetInstrInfo *TII;
- BitVector LivePhysRegs;
+ LiveRegUnits LivePhysRegs;
public:
static char ID; // Pass identification, replacement for typeid
@@ -78,9 +78,9 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const {
for (const MachineOperand &MO : MI->operands()) {
if (MO.isReg() && MO.isDef()) {
Register Reg = MO.getReg();
- if (Register::isPhysicalRegister(Reg)) {
+ if (Reg.isPhysical()) {
// Don't delete live physreg defs, or any reserved register defs.
- if (LivePhysRegs.test(Reg) || MRI->isReserved(Reg))
+ if (!LivePhysRegs.available(Reg) || MRI->isReserved(Reg))
return false;
} else {
if (MO.isDead()) {
@@ -117,26 +117,19 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
bool DeadMachineInstructionElim::eliminateDeadMI(MachineFunction &MF) {
bool AnyChanges = false;
MRI = &MF.getRegInfo();
- TRI = MF.getSubtarget().getRegisterInfo();
TII = MF.getSubtarget().getInstrInfo();
+ LivePhysRegs.init(*MF.getSubtarget().getRegisterInfo());
+
// Loop over all instructions in all blocks, from bottom to top, so that it's
// more likely that chains of dependent but ultimately dead instructions will
// be cleaned up.
for (MachineBasicBlock *MBB : post_order(&MF)) {
- // Start out assuming that reserved registers are live out of this block.
- LivePhysRegs = MRI->getReservedRegs();
-
- // Add live-ins from successors to LivePhysRegs. Normally, physregs are not
- // live across blocks, but some targets (x86) can have flags live out of a
- // block.
- for (const MachineBasicBlock *Succ : MBB->successors())
- for (const auto &LI : Succ->liveins())
- LivePhysRegs.set(LI.PhysReg);
+ LivePhysRegs.addLiveOuts(*MBB);
// Now scan the instructions and delete dead ones, tracking physreg
// liveness as we go.
- for (MachineInstr &MI : llvm::make_early_inc_range(llvm::reverse(*MBB))) {
+ for (MachineInstr &MI : make_early_inc_range(reverse(*MBB))) {
// If the instruction is dead, delete it!
if (isDead(&MI)) {
LLVM_DEBUG(dbgs() << "DeadMachineInstructionElim: DELETING: " << MI);
@@ -149,34 +142,7 @@ bool DeadMachineInstructionElim::eliminateDeadMI(MachineFunction &MF) {
continue;
}
- // Record the physreg defs.
- for (const MachineOperand &MO : MI.operands()) {
- if (MO.isReg() && MO.isDef()) {
- Register Reg = MO.getReg();
- if (Register::isPhysicalRegister(Reg)) {
- // Check the subreg set, not the alias set, because a def
- // of a super-register may still be partially live after
- // this def.
- for (MCSubRegIterator SR(Reg, TRI,/*IncludeSelf=*/true);
- SR.isValid(); ++SR)
- LivePhysRegs.reset(*SR);
- }
- } else if (MO.isRegMask()) {
- // Register mask of preserved registers. All clobbers are dead.
- LivePhysRegs.clearBitsNotInMask(MO.getRegMask());
- }
- }
- // Record the physreg uses, after the defs, in case a physreg is
- // both defined and used in the same instruction.
- for (const MachineOperand &MO : MI.operands()) {
- if (MO.isReg() && MO.isUse()) {
- Register Reg = MO.getReg();
- if (Register::isPhysicalRegister(Reg)) {
- for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
- LivePhysRegs.set(*AI);
- }
- }
- }
+ LivePhysRegs.stepBackward(MI);
}
}
diff --git a/llvm/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir b/llvm/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir
index 9ebd367d9e227..11854f22d2568 100644
--- a/llvm/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir
+++ b/llvm/test/CodeGen/AMDGPU/fold-immediate-operand-shrink.mir
@@ -160,6 +160,7 @@ body: |
; GCN: bb.0:
; GCN-NEXT: successors: %bb.1(0x80000000)
; GCN-NEXT: {{ $}}
+ ; GCN-NEXT: $vcc = S_MOV_B64 -1
; GCN-NEXT: [[S_MOV_B32_:%[0-9]+]]:sreg_32_xm0 = S_MOV_B32 12345
; GCN-NEXT: [[DEF:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
; GCN-NEXT: [[V_ADD_CO_U32_e64_:%[0-9]+]]:vgpr_32, [[V_ADD_CO_U32_e64_1:%[0-9]+]]:sreg_64 = V_ADD_CO_U32_e64 [[S_MOV_B32_]], [[DEF]], 0, implicit $exec
More information about the llvm-commits
mailing list