[llvm-dev] Help in understanding physreg LiveVariables
Matthias Braun via llvm-dev
llvm-dev at lists.llvm.org
Tue Aug 23 11:46:53 PDT 2016
> On Aug 23, 2016, at 6:58 AM, Tyler Kenney via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
>
> Hi all,
>
>
> The documentation at the top of LiveVariables.cpp states the following:
>
> "It ... assumes that physical registers are only live within a single basic block (allowing it to do a single local analysis to resolve physical register lifetimes in each basic block). If a physical register is not register allocatable, it is not tracked. "
>
> This is consistent with the behaviour I'm witnessing, but I don't understand why it's designed this way. I am developing an out-of-tree backend and I have the following scenario:
>
> -physreg X marked as a live-in for a successor MBB (A.K.A., a live-out of the current block)
> -physreg X is a member of an allocatable reg-class
> -the only reference to physreg X in the current block is a: %physregX<def> = COPY %vreg43<kill>
>
> That is the IR immediately before the Live Variables pass. The problem is that LiveVariables is marking physregX as dead, meaning that after LiveVariables, the IR above becomes:
>
>
> %physregX<def,dead> = COPY %vreg43<kill>
>
>
> ...and this eventually causes the COPY to be eliminated rather than lowered to machine instructions. Why does LiveVariables assume physical registers are only live within a single basic block? I have confirmed that if I remove the allocatable check in runOnBlock() [if (!TRI->isInAllocatableClass(LI.PhysReg))] and instead add all successor live-ins to LiveOuts regardless of regclass allocatability, my copy is not marked dead and not subsequently eliminated. This seems consistent with the aforementioned comment, so I don't think it's a bug but I really don't understand the intention here. If anyone could shed some light on why allocatable live-in's are pretty much ignored here, that'd be really helpful.
The long term plan is to get rid of LiveVariables and use LiveIntervalAnalysis for everything. However the TwoAddressInstructionPass has never been converted properly (some code was added to that pass to deal with LiveIntervals but the work was never completed so this is currently broken). If someone could get this working we could finally get rid of LiveVariables...
However apart from the LiveVariables situation I would expect the assumption that physregs are only live within a basic block to be a valid one. What stops you to immediate copy the physregs from/to a virtual register for each use/def? That also gives the register allocator more freedom. If on the other hand a value must be in a register even though there are no apparent def/use operand then you probably have something on your hand that should be marked as non-allocatable or better reserved.
- Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160823/c6818840/attachment.html>
More information about the llvm-dev
mailing list