[llvm-dev] How to handle ISD::STORE when both operands are FrameIndex?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 24 05:08:00 PDT 2019

On Mon, 24 Jun 2019 at 12:16, Gleb Popov via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> 1. Where does it come from? Can I do anything to make it not appear?

It comes from something like:

    %ptr = alloca i8
   %var = alloca i8*
   store i8* %ptr, i8** %var

and in general it's not possible to eliminate the combination.

> 2. If not, how do I change it so that the operand being stored would be first loaded into a register, and that register would be used instead?

While the store is being selected LLVM will just treat the value being
stored as a generic pointer-width integer unless you have written a
specific pattern for storing a FrameIndex somewhere. That's probably
what you want so no need to change anything.

After that, LLVM will try to select the FrameIndex itself (which
you'll need to support anyway so that you can pass a pointer to a
local variable between functions).

Generally this seems to be handled by XYZISelDAGToDAG.cpp, which
converts an ISD::FrameIndex into an appropriate arithmetic instruction
that can offset from SP. That gets lowered to actual known offsets
later on, in exactly the same way loads and stores are.

It's probably done in C++ rather than TableGen because the operands of
these resulting instructions often look pretty weird (for example a
TargetFrameIndex instead of a register). That's mostly speculation
though, I haven't tried to write a bare frameindex pattern.



More information about the llvm-dev mailing list