Issue |
108722
|
Summary |
Invalid rotate-right codegen on x86_64 (LLVM 18)
|
Labels |
new issue
|
Assignees |
|
Reporter |
dnadlinger
|
The following test program fails on Clang 18.1.0/x86_64 with -O1 and above:
```c
#include <assert.h>
#include <stdint.h>
uint32_t ror(uint32_t val, uint32_t amount) {
return (val >> amount) | (val << (32 - amount));
}
__attribute__((noinline))
uint32_t bytesEqual(uint32_t val) {
return ror(val, 8) == val;
}
int main() {
assert(!bytesEqual(0x12345612));
}
```
See [on the Compiler Explorer here](https://godbolt.org/z/6aG3eh85M).
Clang 17 produces the following correct output:
```asm
bytesEqual(unsigned int):
mov ecx, edi
rol ecx, 24
xor eax, eax
cmp ecx, edi
sete al
ret
```
Clang 18 replaces the computation with a `movzx` copying out the lower bytes, and a `shr` to just take the upper byte, i.e. comparing just those two:
```asm
bytesEqual(unsigned int):
movzx ecx, dil
shr edi, 24
xor eax, eax
cmp ecx, edi
sete al
ret
```
(Reported by "user1234" on the LDC mailing list.)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs