<div dir="ltr">Trying to look at your example. Why is the constraint on the pointer variable to the inline assembly "ri" instead of just "r". Changing it to "r" seems to compile.<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 30, 2020 at 10:59 PM Dominic Chen via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Code: <a href="https://godbolt.org/z/T397fo" target="_blank">https://godbolt.org/z/T397fo</a><br>
</p>
<p>I'm running some performance experiments on a x86-64 linux
system, where I've modified LLVM to reserve a register, and I'd
like to use that register in my code. Currently, I'm using %r12d,
which is callee save, so I don't need to worry about compatibility
with existing libraries or system calls. For security reasons, the
generated binaries need to be position independent.</p>
<p>To access the register, I need to use inline assembly; either for
all dependent computations, or just for moving the register value
into a C++ variable. Since the latter results in a second register
allocation, I'm just doing assembly for everything. So, I have a
function `foo` that contains some inline assembly. </p>
<p>The problem is that its input arguments can sometimes be pointers
to constant data, and after function inlining, the result may no
longer link because R_X86_64_32S relocations are not permitted. I
need to get LLVM to introduce a load-effective address (`lea`) to
move the pointer into a register, if applicable, but I haven't
found a method that both works and is performant. I could modify
LLVM locally to make this happen, but this seems pretty deep in
the X86 backend and not straightforward?<br>
</p>
<ol>
<li>Make the input argument `volatile` or introduce a `volatile`
variable. Works, but adds two moves to and from the stack.</li>
<li>Introduce a `register` variable equal to the input argument.
Results in an error with C++17, and doesn't seem to work
otherwise.</li>
<li>Only use inline assembly to move %r12d into a C variable.
Mostly works, but the variable isn't incremented afterwards,
requires an extra register, and adds multiple extra moves.</li>
<li>Use the local register variable extension to force a C
variable to %r12d. Not supported by Clang/LLVM.<br>
</li>
</ol>
Thanks,
<p>Dominic<br>
</p>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>