<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Patterns for fabs from select in DAGCombiner are folded without regard for sign of zero"
   href="https://bugs.llvm.org/show_bug.cgi?id=36600">36600</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Patterns for fabs from select in DAGCombiner are folded without regard for sign of zero
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mikhail.dvoretckii@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The test case:

-bash-4.2$ cat fabszero.cpp
#include <stdio.h>

int main(int argc, char **argv)
{
  double zero;
  sscanf(argv[1], "%lf", &zero);
  zero = (zero <= 0) ? (-0.0 - zero) : zero;
  printf("%f\n", zero);
  return 0;
}
-bash-4.2$

If compiled with strict FP math, this test case returns -0.0 for the 0.0 input.

-bash-4.2$ clang -O3 fabszero.cpp
-bash-4.2$ ./a.out 0.0
-0.000000
-bash-4.2$

If compiled with a no-NaNs flag, even without the no-signed-zeros flag, the
code is folded into fabs, producing non-negative outputs for all inputs.

-bash-4.2$ clang -O3 -Xclang -menable-no-nans fabszero.cpp
-bash-4.2$ ./a.out 0.0
0.000000
-bash-4.2$

The cause of this is the patterns folded into fabs in SimplifySelectCC is
DAGCombiner.cpp, specifically

select (setg[te] X, +/-0.0), X, fneg(X) -> fabs
select (setl[te] X, +/-0.0), fneg(X), X -> fabs

Since 0.0 and -0.0 evaluate as equal and lead to the same option being
selected, all of these patterns should produce -0.0 on one of the zero inputs
which contradicts fabs semantics. This folding thus changes sign-of-zero
behavior without checking the appropriate flag.</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>