[llvm-dev] Undef physical registers?
Matthias Braun via llvm-dev
llvm-dev at lists.llvm.org
Tue Feb 13 09:44:33 PST 2018
> On Feb 13, 2018, at 1:11 AM, Jesper Antonsson via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> Hi,
>
> I'm a bit unsure of the semantics of undef physical registers. The explanations I've seen in the code and in the langref seems to
> pertain more to constant values and virtual registers.
The LangRef talks about the llvm IR, not the representation used in the backend. The undef node in IR is something different from the machine operand flag named undef.
>
> What I really want to achieve is a push-pop of a register to have a temporary to work with, without having to check if this
> register is defined or not. However, whenever the reg is not defined before the push, the MachineVerifier complains about that.
It sounds like you may functionality that the register scavenger provides.
>
> If I add RegState::Undef to the push, the verifier complaint goes away, but I worry that this might be unsafe. I would like
> "Undef" for physical registers to mean "we don't care if this register has been defined or not", but perhaps it means "this
> register can now have any bits set", so it'd be allowed to optimize the push away?
>
> So, is the latter interpretation true, and if so, is there some other idiom that would allow me to push-pop a possibly undefined
> physical register?
You can't blindly insert a push/store of a register without knowing whether it is alive or not. At least for targets that track liveness post register allocation which is nearly all of them nowadays.
I'd recommend using LiveRegUnits (or LivePhysRegs) to figure out whether a register is alive or not. If your pass is before or during PEI than you can also use the RegisterScavenger to do the spilling/restoring for you.
- Matthias
More information about the llvm-dev
mailing list