<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 - __finite math calls generated prevents optimizations."
   href="https://bugs.llvm.org/show_bug.cgi?id=48317">48317</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__finite math calls generated prevents optimizations.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>opt
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>venkataramanan.kumar.llvm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I am on Ubuntu 18 machine and it has finite math header <bits/math-finite.h>.
This header is included by the glibc 2.27. This header has this following
definition.

extern double log (double) asm ("" "log_finite") attribute__ ((nothrow ));

Consider the following test case

#include <math.h>
double mylog (double d) {

return log(d);
}


Recently clang started supporting asm labels. 
Ref: <a href="https://reviews.llvm.org/D88712">https://reviews.llvm.org/D88712</a> 


Before this patch clang generates the below LLVM IR for -O2 -ffast-math
--Snip--
; Function Attrs: nounwind readnone uwtable
define dso_local double @mlog(double %d) local_unnamed_addr #0 {
entry:

%0 = tail call fast double @llvm.log.f64(double %d)
ret double %0
}
---Snip--

After this patch for -O2 -ffast-math, clang generates

--Snip--
; Function Attrs: nounwind readnone uwtable
define dso_local double @mlog(double %d) local_unnamed_addr #0 {
entry:

%call = tail call fast double @__log_finite(double %d) #2
ret double %call
}
--Snip--

Note on latest Ubuntu 20.04.1 LTS with Glibc 2.31 <bits/math-finite.h> header
is not present.  It is removed by glibc. so there I see the @llvm.log.f64
intrinsic calls.

So on machines with lesser glibc versions where the header file is present this
will be a problem as it generates finite calls now. 

Note the LLVM "opt" does optimizations like vectorization only on the
intrinsic, but fails to do so in the presence of calls to @__log_finite.

Example <a href="https://llvm.godbolt.org/z/765We8">https://llvm.godbolt.org/z/765We8</a>

Older glibc versions are still supported OS distros. We are seeing performance
issues due to this finite calls.</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>