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: unassignedb...@nondot.org
Reporter: arichardson....@gmail.com
CC: htmldevelo...@gmail.com, llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs