<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>This doesn't seem like a good idea to me. There are many architectures where those bitcasts are free operations and the xor will be executed in a shorter pipe than any FP op would. Cell SPU, for example.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">This could introduce new FP exceptions. It's also likely to be much worse on platforms with no FPU like early MIPS.<br><br>Alex</div><div><br>On Apr 7, 2016, at 9:43 AM, via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8">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 class=""><br class=""></div><div class="">Example:</div><div class=""><br class=""></div><div class="">a = load float</div><div class="">b = bitcast a to int</div><div class="">c = xor b, signbit</div><div class="">d = bitcast c to float</div><div class="">store d</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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><div class=""><br class=""></div><div class="">—escha<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 7, 2016, at 9:09 AM, Sanjay Patel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">Hi Carlos -<br class=""><br class=""></div>That sounds like a good patch.<br class=""><br class=""></div>Warning - following the link below may remove some of the educational joy for the immediate task at hand:<br class=""><a href="http://reviews.llvm.org/D13076" class="">http://reviews.llvm.org/D13076</a><br class=""><br class=""></div>...but I wouldn't worry too much, there's plenty more opportunity where that came from. :)<br class=""><div class=""><div class=""><br class=""></div><div class="">Feel free to post follow-up questions here or via a patch review on Phabricator:<br class=""><a href="http://llvm.org/docs/Phabricator.html" class="">http://llvm.org/docs/Phabricator.html</a><br class=""></div><div class=""><br class=""></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Apr 7, 2016 at 7:17 AM, Carlos Liam via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="">
<br class="">
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 class="">
<br class="">
Name: xor->fsub<br class="">
Pre: isSignBit(C)<br class="">
%x = bitcast %A<br class="">
%y = xor %x, C<br class="">
%z = bitcast %y<br class="">
=><br class="">
%z = fsub -0.0, %A<br class="">
<br class="">
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 class="">
<br class="">
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 class="">
<br class="">
Thanks in advance.<br class="">
<br class="">
- CL<br class="">
<br class="">
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div><br class=""></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>LLVM Developers mailing list</span><br><span><a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a></span><br><span><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></span><br></div></blockquote></body></html>