Ignore Constant Physical Register Def in MachineCSE::hasLivePhysRegDefUses()

Hello,

Why can’t a constant physical register be ignored in MachineCSE::hasLivePhysRegDefUses()?
Like as shown below:
diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp
index 9561a06ce8d…b92c26feb30 100644
— a/llvm/lib/CodeGen/MachineCSE.cpp
+++ b/llvm/lib/CodeGen/MachineCSE.cpp
@@ -297,6 +297,7 @@ bool MachineCSE::hasLivePhysRegDefUses(const MachineInstr *MI,
// Next, collect all defs into PhysDefs. If any is already in PhysRefs
// (which currently contains only uses), set the PhysUseDef flag.
PhysUseDef = false;

  • const MachineRegisterInfo &MRI = MI->getMF()->getRegInfo();
    MachineBasicBlock::const_iterator I = MI; I = std::next(I);
    for (const auto &MOP : llvm::enumerate(MI->operands())) {
    const MachineOperand &MO = MOP.value();
    @@ -307,6 +308,8 @@ bool MachineCSE::hasLivePhysRegDefUses(const MachineInstr *MI,
    continue;
    if (Register::isVirtualRegister(Reg))
    continue;
  • if (MRI.isConstantPhysReg(Reg))
  • continue;
    // Check against PhysRefs even if the def is “dead”.
    if (PhysRefs.count(Reg))
    PhysUseDef = true;

Thanks,
Vivek

Hi Vivek,

Constant physical register should be fine to ignore.

Cheers,
-Quentin