[LLVMdev] Default behavior of DeadMachineInstructionElim deletes all instructions

Dale Johannesen dalej at apple.com
Wed Apr 14 14:15:12 PDT 2010

On Apr 14, 2010, at 1:55 PMPDT, Villmow, Micah wrote:

> I’ve recently sync’d to a newer version of LLVM(Apple branch 2326 from Apple branch 2323.8) that changed the interface to addCommonCodeGenPasses which caused the default implementation to be executed instead of my overriding implementation. This default implementation has DeadMachineInstructionElim pass enabled, which is causing havoc with my backend. Before entering this pass, everything in my machine function is fine, after this pass, all instructions that are not function calls are deleted. I’ve tracked this issue down to the line:
> BitVector NonAllocatableRegs = TRI->getAllocatableSet(MF); (In my case all registers defined in RegisterInfo.td)
> This function loops through all registers classes and sets all registers in the bitset that are allocatable. It then inverts the registers that are set to get the NonAllocatable registers and assigns that to the LivePhysRegs for each basic block in a function. The function then loops through all instructions in a basic block and checks to see if it is a dead instruction.  The check is whether it is a physical register or not with the check:
> TargetRegisterInfo::isPhysicalRegister(reg) ? LivePhysRegs[Reg] : !MRI->use_nodbg_empty(Reg) 
> If the register is virtual, then MRI->use_nodbg_empty() returns false, if the register is physical LivePhysRegs[Reg] returns false, since the bitvector was inverted. So my instruction is considered dead and deleted.
Huh?  The code is

      if (TargetRegisterInfo::isPhysicalRegister(Reg) ?
          LivePhysRegs[Reg] : !MRI->use_nodbg_empty(Reg)) {
        // This def has a non-debug use. Don't delete the instruction!
        return false;

Returning false from MRI->use_nodbg_empty means the instruction has a use, and it is not deleted. That's what's supposed to happen.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100414/318ac109/attachment.html>

More information about the llvm-dev mailing list