<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - what is the canonical IR for a fabs operation?"
   href="https://llvm.org/bugs/show_bug.cgi?id=24886">24886</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>what is the canonical IR for a fabs operation?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Another round of "What is canonical IR?" is raised by the test in <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Floating-point "and" not optimized on x86-64"
   href="show_bug.cgi?id=22428">bug 22428</a>:

#include <math.h>
#include <string.h>

double fand1(double x) {
  unsigned long ix;
  memcpy(&ix, &x, 8);
  ix &= 0x7fffffffffffffffUL;
  memcpy(&x, &ix, 8);
  return x;
}

double fand2(double x) {
  return fabs(x);
}

$ ./clang -O2 22428.c -S -o - -emit-llvm
...
define double @fand1(double %x) #0 {
entry:
  %0 = bitcast double %x to i64
  %and = and i64 %0, 9223372036854775807
  %1 = bitcast i64 %and to double
  ret double %1
}

define double @fand2(double %x) #0 {
entry:
  %call = tail call double @fabs(double %x) #2
  ret double %call
}

---------------------------------------------------------------------------

My guess is that neither of these is canonical. We should be transforming both
of these into the LLVM intrinsic, so we have something the backend knows how to
optimize and so we don't have a dependency on an external math lib.

Note: I'm assuming that the format of an LLVM 'double' matches the normal
(IEEE-specified?) format, so the sign bit is the high bit. This isn't actually
specified in the LangRef though:
<a href="http://llvm.org/docs/LangRef.html#floating-point-types">http://llvm.org/docs/LangRef.html#floating-point-types</a>

If that assumption isn't valid, we're in more trouble than I thought. :)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>