[codegen] equivalent bit manipulation code produces different assembly
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
On godbolt: https://godbolt.org/z/ebj8rhqja
The following two options:
```c++
std::uint32_t option1(std::uint8_t vecHeader) {
vecHeader >>= 4;
if (vecHeader != 0xF) [[likely]] {
return vecHeader;
} else {
return foo();
}
}
std::uint32_t option2(std::uint8_t vecHeader) {
if ((vecHeader & 0xF0) != 0xF0) [[likely]] {
return vecHeader >> 4;
} else {
return foo();
}
}
```
should result in the same assembly but they don't
Contributor guide
Research direction
Start with the Godbolt reproducer at https://godbolt.org/z/ebj8rhqja and compare the assembly produced for option1 and option2. Trace the relevant compiler code-generation or optimization path for these C++ bit-manipulation forms. Done means equivalent options produce the same assembly without changing the observed behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100