<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 18, 2015 at 7:04 PM, Shriramana Sharma <span dir="ltr"><<a href="mailto:samjnaa@gmail.com" target="_blank">samjnaa@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 11/19/15, Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br>
> LLVM believes that floating point division will never trap, and speculates<br>
> it to make code like this:<br>
> float tmp = 1.0 / scale;<br>
> scale = scale == 0.0 ? scale : tmp;<br>
<br>
</span>I don't get it. In what way is the above code more efficient than:<br>
<br>
if (scale != 0) scale = 1 / scale;<br>
<br>
... that the compiler should replace this with that?<br>
<span class=""><br>
> Normally, FP division produces NaN. The only way that I'm aware of to make<br>
> FP div trap is to use fenv.h, which isn't supported:<br>
> <a href="https://llvm.org/bugs/show_bug.cgi?id=8100" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=8100</a><br>
<br>
</span>But the code above is perfectly legal, logical and safe C/C++ code,<br>
and that Clang doesn't support it (in the sense of emitting code that<br>
causes a SIGFPE when one isn't warranted) *is* a bug, no?<br></blockquote><div><br></div><div>We support the code you listed, but we don't support configuring your processor to make FP divide by zero trap.</div><div><br></div><div>I'm not making a value judgement on what LLVM does here, I'm just relaying the facts.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And it doesn't seem to be per se a dup of the bug you mention above<br>
(in which case I should report it separately) or is it?</blockquote><div><br></div><div></div></div></div><div class="gmail_extra">This bug has been reported enough times that it's probably worth having one just for speculation of FP divide. There might already be one there in the list of dupes that we could split off.</div></div>