<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 - Sub-optimial code generation for masking off top bit"
   href="https://bugs.llvm.org/show_bug.cgi?id=49377">49377</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Sub-optimial code generation for masking off top bit
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>arichardson.kde@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I was looking at the code generated for __builtin_fabs() in soft-float mode and
noticed that Clang generates worse code than GCC:
```
double
fabs(double x)
{
        return (__builtin_fabs(x));
}

```
<a href="https://godbolt.org/z/33q7Eq">https://godbolt.org/z/33q7Eq</a>

For RV64 (but this also affects e.g. MIPS) Clang:
        addi    a1, zero, -1
        slli    a1, a1, 63
        addi    a1, a1, -1
        and     a0, a0, a1
        ret
GCC:
        slli    a0,a0,1
        srli    a0,a0,1
        ret


This integer version could also be folded to the shift sequence to avoid
materializing the awkward constant:
```
unsigned long
fabs_int(unsigned long x)
{
    return x & ~(1ul << 63);
}
```

I think this fold could be beneficial to all targets since it reduces code size
(GCC emits 9 bytes on x86, clang emits 15).</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>