<div dir="ltr">Efficient looking on a 386, sure, but I presume you're running AMD64 code on a modern CPU :-)<div><br></div><div>I suggest you try:</div><div><br></div><div>   call foobar</div><div>foobar:</div><div>   pop %rcx</div><div>   mov    %rcx,0x1083a60(,%rax,8)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 3, 2017 at 12:14 AM, Kostya Serebryany via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">FTR: <div>I've made a simple experiment with inline asm, it's as simple as </div><div><div>InlineAsm::get(FunctionType::<wbr>get(IntptrTy, false),</div><div>                             StringRef("lea (%rip),$0"), StringRef("=r"),</div><div>                             /*hasSideEffects=*/false);</div></div><div><br></div><div>It generates a pretty efficient-looking code: </div><div><div>  42194c:<span class="m_7562042030501171672gmail-Apple-tab-span" style="white-space:pre-wrap">       </span>48 8d 0d 00 00 00 00 <span class="m_7562042030501171672gmail-Apple-tab-span" style="white-space:pre-wrap">       </span>lea    0x0(%rip),%rcx        # 421953 <_Z3fooPi+0x13></div><div>  421953:<span class="m_7562042030501171672gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>48 89 0c c5 60 3a 08 <span class="m_7562042030501171672gmail-Apple-tab-span" style="white-space:pre-wrap">       </span>mov    %rcx,0x1083a60(,%rax,8)</div></div><div>(first instruction gets the PC, the other stores it somewhere)</div><div><br></div><div>However, this introduces a significant slowdown in my case, over 20%</div><div>(I need to execute this roughly for 50% of basic blocks)</div><div><br></div><div>So, I'll be looking for some other solutions that don't require reading the PC this often. :(</div><div><br></div><div>--kcc </div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 31, 2017 at 3:13 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Tue, Jan 31, 2017 at 3:11 PM, Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><span><div><div class="gmail_extra"><div class="gmail_quote">On 31 Jan 2017 8:58 p.m., "Kostya Serebryany" <<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>> wrote:<blockquote class="m_7562042030501171672m_-6242900704664175330m_4657174565163629080quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>hmm. I am not sure I understood you. The last two paragraphs seem to contradict each other. </div><div>So, you recommend to extend read_register to read the PC, or </div><div>"read_register is locked at the stack pointer as a design decision"?</div></div></div></div></blockquote></div></div></div><div dir="auto"><br></div></span><div dir="auto">Both. :-)</div><div dir="auto"><br></div><div dir="auto">There was a design decision to only support SP because we had no clear case for anything other than the stack pointer. </div><div dir="auto"><br></div><div dir="auto">If you have one for the PC, it would be a much better technical decision to reuse the machinery that already exists, is documented and tested, than come up with an independent implementation. </div><div dir="auto"><br></div><div dir="auto">The discussion whether to support it in clang or not is orthogonal. But once decided that we should support reading the PC, then read_register is the obvious place. </div><div dir="auto"><br></div><div dir="auto">If the clang developers refuse the idea, then inline assembly is the only option that would work across compilers. </div><div dir="auto"><br></div><div dir="auto">Makes sense? </div></div></blockquote><div><br></div></span><div>Yep, will give it a try. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto">Cheers, </div><span class="m_7562042030501171672m_-6242900704664175330HOEnZb"><font color="#888888"><div dir="auto">Renato </div><div dir="auto"></div></font></span></div>
</blockquote></div><br></div></div>
</blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>