[llvm-bugs] [Bug 49377] New: Sub-optimial code generation for masking off top bit

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 1 03:22:06 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49377

            Bug ID: 49377
           Summary: Sub-optimial code generation for masking off top bit
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: arichardson.kde at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

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));
}

```
https://godbolt.org/z/33q7Eq

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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210301/888c72d9/attachment-0001.html>


More information about the llvm-bugs mailing list