<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 22, 2017 at 11:40 AM Kuba Mracek 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> Actually, it should be enough to use:<br>
><br>
> __attribute__((noinline))<br>
> void please_do_not_optimize_me_away(int arg1, void *arg2) {<br>
>  asm volatile("":::"memory");<br>
> }<br>
><br>
> Creating a real barrier is important.<br>
<br>
This doesn't work – the call still gets turned into please_do_not_optimize_me_away(undef, undef).<br>
<br>
> __attribute__((optnone))<br>
<br>
optnone works, but I'm actually surprised by this.  I would expect that it would only affect the generated code of that function...<br>
<br>
Is it guaranteed to work? </blockquote><div><br>Modulo bugs, yes - optnone should have the same behavior as if you put the function definition in another file and compiled that file with -O0.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Or is my safest bet still to use:<br>
<br>
__attribute__((noinline))<br>
void please_do_not_optimize_me_away(int arg1, void *arg2) {<br>
 asm volatile("" :: "r" (arg1), "r" (arg2) : "memory");<br>
}<br>
<br>
(The other benefit compared to optnone is that this will actually generate a nice empty function.  Using optnone generates code that stores the arguments to the stack.)<br>
<br>
Kuba<br>
<br>
_______________________________________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>