llvm-project
llvm-project copied to clipboard
bswap optimization broken in InstCombine
| Bugzilla Link | 7525 |
| Resolution | LATER |
| Resolved on | Nov 07, 2018 00:22 |
| Version | trunk |
| OS | All |
| CC | @echristo |
Extended Description
Filing this so I don't forget about it.
With this small testcase:
int f(int n) { return (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)); }
We should be getting a 32-bit bswap, but instead are getting the long sequence of ands, ors, and shifts.
movl %esp, %ebp
movl 8(%ebp), %eax
movl %eax, %ecx
sarl $24, %ecx
movl %eax, %edx
shll $24, %edx
orl %ecx, %edx
movl %eax, %ecx
shrl $8, %ecx
andl $65280, %ecx ## imm = 0xFF00
orl %edx, %ecx
shll $8, %eax
andl $16711680, %eax ## imm = 0xFF0000
orl %ecx, %eax
OK. Done.
Please move this to lib/Target/README.txt, there are a couple similar bswap idioms in it.