[llvm-dev] Question about register allocation

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 15 14:18:16 PST 2019


Hi Josh,

On Fri, 15 Feb 2019 at 13:40, Josh Sharp <mm92126 at hotmail.com> wrote:
>   $r0 = ADDR %stack.0.a, $r0(tied-def 0), implicit-def dead $cf, implicit-def dead $nf, implicit-def dead $zf, implicit-def dead $of

>   $r0 = ADDR $noreg, $r0(tied-def 0), implicit-def dead $cf, implicit-def dead $nf, implicit-def dead $zf, implicit-def dead $of

> Somehow '%stack.0.a' became '$noreg'

That's normally done by the "eliminateFrameIndex" functions, which do
get called during the prologue/epilogue pass but live in
XYZRegisterInfo.cpp. They get told that "%stack.0.a" lives at SP+N,
and they have to rewrite the specified instruction to encode that
information.

Usually the instruction involved is (or contains) an add-immediate,
and what would be the base of the addition is %stack.whatever at the
start. For example:

   $r0 = ADDri %stack.0.a, 0

Then if eliminateFrameIndex gets called with that instruction and the
variable is actually at sp+12 it'll rewrite it to:

   $r0 = ADDri $sp, 12

modifying two of the operands (the base and the offset).

That immediately starts ringing alarm-bells with your ADDR since it
doesn't look like it allows a constant offset, so there's no way
eliminateFrameIndex *can* make it compute the local's address and
really it probably shouldn't be the instruction that %stack.0.a got
folded into in the first place. If I'm reading your example correctly,
what I'd expect to see instead is:

    $rTmp = ADDri %stack.0.a, 0
    $r0 = ADDR $rTmp, $r0(tied-def 0)

Obviously I don't know what you've called your stack-capable
instruction so I'm just guessing ADDri.

Cheers.

Tim.


More information about the llvm-dev mailing list