[LLVMdev] instruction/intrinsic for segmented adressing

Tim Northover t.p.northover at gmail.com
Sat Dec 6 19:09:18 PST 2014

>> That's a more complex addressing mode and an additional MRS
>> instruction over the usual sequence. You also lose the ability to fold
>> the actual address-computation into the LDR.
> but this is the price you pay always for RISC vs. x86, or?

The price is paid in different ways, everywhere. All I can say for
sure is that addressing based on TPIDR is going to be more expensive
than without. Only benchmarks could quantify it.

> wouldn't it make sense to add such an addressing instruction at LLVM IR
> level? I mean there were no similar requests?

It's not come up before, no. It's not the worst idea I've heard, but
equally I'm not exactly convinced of the benefit yet. Either way, it
won't happen unless someone implements it ("patches welcome" as the
saying goes).

> Another solution for my problem would be to carry around the segment address
> as extra function parameter to all functions, but that would be a funny

That's not exactly a terrible idea (I believe GHC might do something
morally similar). It allows the compiler to spill it if necessary
unlike reserving a register absolutely (say before a
performance-critical loop), but its omnipresence probably discourages
the spilling.

If nothing else, it sounds like a useful way to get yourself up and
running without backend or OS support.

> So I wonder if it is possible in a
> LLVM pass to track back all pointers in the IR that were initialized with a
> certain function (factory function) and change the addressing

This is the problem I believe is logically impossible without source
help, and if you've got that you'd just as well emit different IR to
begin with.

> On x86-64, unless I call some library functions I have the guaranty that
> nobody would change the values in the gs/fs registers.

You do? I thought both were reserved by Linux. I suppose if you hack
the kernel and/or libc you could fix them.

>Is there a way to tell LLVM not to reserve a certain register?

I don't think I follow here. Reserving a register is possible in
certain limited circumstances (though discouraged, at least by me).
Unreserving a register isn't, as far as I'm aware.



More information about the llvm-dev mailing list