<div dir="ltr"><div class="gmail_extra">Yes, if transforming the int op to an FP op induces target-dependent behavior, then we can't do this transform in InstCombine without some kind of predication. And we should revert or rein in:<br><a href="http://reviews.llvm.org/rL249702" target="_blank">http://reviews.llvm.org/rL249702</a><br><br></div><div class="gmail_extra">As I noted in that commit message, it's not clear what the FP model of LLVM IR actually is. Based on existing IR transforms, I assumed it was IEEE-754...ish.<br><br><br><div class="gmail_quote">On Thu, Apr 7, 2016 at 10:43 AM,  <span dir="ltr"><<a href="mailto:escha@apple.com" target="_blank">escha@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">I am not entirely sure this is safe. Transforming this to an fsub could change the value stored on platforms that implement negates using arithmetic instead of with bitmath (such as ours) and either canonicalize NaNs or don’t support denormals. This is actually important because this kind of bitmath on floats is very commonly used as part of algorithms for complex math functions that need to get precise bit patterns from the source (similarly for the transformation of masking off the sign bit -> fabs). It’s also important because if the float happens to “really” be an integer, it’s highly likely we’ll end up zero-flushing it and losing the data.<div><br></div><div>Example:</div><div><br></div><div>a = load float</div><div>b = bitcast a to int</div><div>c = xor b, signbit</div><div>d = bitcast c to float</div><div>store d</div><div><br></div><div>Personally I would feel this is safe if and only if the float is coming from an arithmetic operation — in that case, we know that doing another arithmetic operation on it should be safe, since it’s already canonalized and can’t be a denorm [if the platform doesn’t support them].</div><div><br></div><div>I say this coming only a few weeks after our team spent literally dozens of human-hours tracking down an extremely obscure bug involving a GL conformance test in which ints were casted to floats, manipulated with float instructions, then sent back to int, resulting in the ints being flushed to zero and the test failing.</div><span><font color="#888888"><div><br></div></font></span><div><span><font color="#888888">—escha</font></span><div><div><br><div><br><div><blockquote type="cite"><div>On Apr 7, 2016, at 9:09 AM, Sanjay Patel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><div><div><div>Hi Carlos -<br><br></div>That sounds like a good patch.<br><br></div>Warning - following the link below may remove some of the educational joy for the immediate task at hand:<br><a href="http://reviews.llvm.org/D13076" target="_blank">http://reviews.llvm.org/D13076</a><br><br></div>...but I wouldn't worry too much, there's plenty more opportunity where that came from. :)<br><div><div><br></div><div>Feel free to post follow-up questions here or via a patch review on Phabricator:<br><a href="http://llvm.org/docs/Phabricator.html" target="_blank">http://llvm.org/docs/Phabricator.html</a><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 7, 2016 at 7:17 AM, Carlos Liam 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I'm interested in implementing an InstCombine optimization that I discovered and verified with Alive-NJ (with the help of the authors of Alive-NJ). The optimization is described in Alive-NJ format as follows:<br>
<br>
Name: xor->fsub<br>
Pre: isSignBit(C)<br>
%x = bitcast %A<br>
%y = xor %x, C<br>
%z = bitcast %y<br>
=><br>
%z = fsub -0.0, %A<br>
<br>
Effectively the optimization targets code that casts a float to an int with the same width, XORs the sign bit, and casts back to float, and replaces it with a subtraction from -0.0.<br>
<br>
I am not very familiar with C++ or the LLVM codebase so I would greatly appreciate some help in writing a patch adding this optimization.<br>
<br>
Thanks in advance.<br>
<br>
 - CL<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><br></div>
_______________________________________________<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" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div></div></div></div></div></blockquote></div><br></div></div>