llvm / llvm/llvm-project

[codegen] equivalent bit manipulation code produces different assembly

Open
#179,650 0 comments 0 reactions 0 assignees View on GitHub
llvm:optimizations
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.