<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 19, 2014 at 10:26 AM, Chad Rosier <span dir="ltr"><<a href="mailto:mcrosier@codeaurora.org" target="_blank">mcrosier@codeaurora.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":2u6" class="a3s" style="overflow:hidden">Hal and I discussed this on IRC and here's the synopsis (mostly in Hal's words):<br>

<br>
Many of these builtins turn into libc calls, and those do set errno. Marking them as readnone is a problem, because we can reorder/eliminate writes to errno.  For example, if we assume readnone for something like __builtin_sqrt(); write(); perror(); it may be reordered to write(); __builtin_sqrt(); perror(); and perror may provide junk.  However, if we don't mark the builtins as readnone, then they won't get lowered into ISD nodes (for those nodes that are relevant), and that means that they won't get instruction selected into native instructions on targets where that's possible. So the __builtin_sqrt is kind of an escape hatch to force the direct lowering behavior even when we can't do it for sqrt because sqrt might set errno.  But, as Hal said, this behavior *is* broken, technically. And, in fact, it is not hard to create test cases where you can see buggy behavior.  Hak's just not sure what the right way of handling it is. Hal thinks we really need some kind of target inp!<br>

 ut, so that we can know ahead of time whether the builtin will *really* set errno or not after isel.  Hal thinks there are two solutions possible.<br>
<br>
1. Like with inline asm registers/constraints; each target will provide a table describing what builtins will really not set errno.<br>
2. Let Clang essentially query TTI for those builtins that are relevant. This second method will require a bit of infrastructure work, but is probably not too difficult.<br>
<br>
I'm not going to push this patch further because it's not the right solution.  In theory, I believe it is correct, but it breaks the __buitlin escape hatch, which would likely result in serious performance degradations.</div>
</blockquote></div><br>Crazy idea:</div><div class="gmail_extra"><br></div><div class="gmail_extra">When we lower one of these to a call to a libc function, save and restore errno around it.</div><div class="gmail_extra">
<br></div><div class="gmail_extra">Too crazy?</div></div>