[llvm-dev] IR inline assembly: the x86 Intel "offset" operator

Eric Astor via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 10 14:01:24 PST 2019

Actually, there's more of a bug here than I realized:

https://godbolt.org/z/fktmVn seems to show that LLVM's current handling of
offset goes wrong with global variables... with a global `int Bar;`, inline
    mov eax, offset Bar
ends up as
    mov eax, dword ptr [Bar]
which I'm pretty sure is not what's intended here.

I've written LLVM IR that does produce an equivalent result (see the
Compiler Explorer link above), but I'm not sure how to get X86Operand to
produce a direct memory operand... I can't figure out where the memory
constraint gets turned into an indirect memory constraint ("*m"). Anyone
have any leads I can follow?

- Eric

On Mon, Dec 9, 2019 at 3:27 PM Eric Astor <epastor at google.com> wrote:

> Hi all,
> I'm trying to land (a rebased version of) http://llvm.org/D37461 - which
> should make it possible to handle x86 Intel assembly like
>     mov eax, offset Foo::ptr + 1
> (Currently, omitting the +1 works... but offset doesn't work in compound
> expressions.)
> I'm having trouble figuring out what inline assembly I can emit into the
> LLVM IR that will work properly. So far, the closest I've gotten is
>     call void asm sideeffect inteldialect "mov eax, offset $0 + $$1,
> "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32** @"?ptr at Foo@@2PAHA")
> But that expands to
>     mov eax, offset [?ptr at Foo@@2PAHA] + 1
> which ends up incorrectly dereferencing the address first.
> I haven't found a working combination of code & constraints that will
> expand to
>     mov eax, offset ?ptr at Foo@@2PAHA + 1
> Is this possible?
> Thanks,
> - Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191210/7d54e414/attachment.html>

More information about the llvm-dev mailing list