[llvm-dev] Manipulating global address inside GlobalAddress SDNode in (RISCV) LLVM backend

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 11 09:50:49 PDT 2019


On Thu, 11 Jul 2019 at 17:16, Reshabh Sharma <reshabhsh at gmail.com> wrote:
> We thought LUI and ADDI pair will be good to store the values in a i32 register.

With you so far, I think. To be explicit, to materialize a full 64-bit
pointer you'd need 4 instructions:

    lui rLO32, addr:MO_LO32_LO
    addi rLO32, rLO32, addr:MO_LO32_HI
    lui rHI32, addr:MO_HI32_LO
    addi rHI32, rLO32, addr:MO_LO32_HI

or some variation for PIC etc.

>  If we could transform GlobalAddress<0xHighLow> directly to GlobalAddress<0xLow>, we could use the present RISCVII::MO_HI and MO_LO as they only exact the 32 high bits. What do you think?

I still recommend against reusing GlobalAddress as-is with an i32
type, but that's probably a minor detail. The only way I can see to
reuse the existing modifiers unambiguously would be to modify the
above sequence to:

    lui rLO32, addr:MO_LO
    addi rLO32, rLO32, addr:MO_LO
    lui rHI32, addr:MO_HI
    addi rHI32, rLO32, addr:MO_HI

It kind of works, but personally I think it's stretching the
understood semantics of MO_LO and MO_HI too far -- I'd add new ones if
it was me. But I'm not an active RISC-V maintainer so take my opinions
with a grain of salt.

Cheers.

Tim.


More information about the llvm-dev mailing list