<div dir="ltr">Hi Rafael.<div><br></div><div>I have been looking at this for a while, but I cannot seem to find a way of preserving an LLVM intrinsic after ISel and expanding it later.</div><div>Basically, if I add an LLVM intrinsic for TLS access in IR/IntrinsicsX86.td, then the backend expects me to provide an instruction selection rule for lowering it to MachineInstructions; however as you said we cannot do it at ISel stage because we must ensure the structure is preserved so that the linker can pattern-match it.</div><div><br></div><div>With "intrinsic", do you instead mean an actual function that we manufacture on the fly in Clang (or provide a declaration for in a header), and then eliminate / patch up in MC later on?</div><div>That might work but it seems a bit convoluted to me. Also... if we manufacture the function, we end up with a declaration in the IR that doesn't correspond to anything in the source; if we instead have the function in a header, doesn't that require the user to include the header?</div><div>Is that what you're suggesting, or am I getting confused?</div><div><br></div><div>Cheers,</div><div>    Dario Domizioli</div><div>    SN Systems - Sony Computer Entertainment Group</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 6 November 2014 14:05, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 6 November 2014 09:00, Dario Domizioli <<a href="mailto:dario.domizioli@gmail.com">dario.domizioli@gmail.com</a>> wrote:<br>
><br>
> On 5 November 2014 19:55, Rafael Espíndola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>><br>
> wrote:<br>
>><br>
>> The final lowering has to happen fairly late as the linker depends on<br>
>> doing pattern matching for optimizing the different access.<br>
><br>
><br>
> I see. That explains why it's expanded in AsmPrinter. And maybe even the<br>
> reason why in some cases there is also some padding between the instructions<br>
> (I imagine the linker would patch it up, right?).<br>
<br>
</span>Correct. Some sequences use more bytes than what would be strictly<br>
necessary so that the linker can optimize linking a .o into a main<br>
executable (for example).<br>
<span class=""><br>
>> Maybe instead of having a TLS_addr64 pseudo we could have it be an<br>
>> actual call to an intrinsic and then special case the MC lowering<br>
><br>
><br>
> Hm... that would require some reworking in the places where the pseudo<br>
> instruction is handled, but it sounds like a good direction to investigate.<br>
> I'll have a look at how to implement that.<br>
<br>
</span>Thanks,<br>
Rafael<br>
</blockquote></div><br></div>