`memcmp` -> `bcmp` optimization not firing when fed to bitwise or
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Testcase:
```c++
char *p;
bool b;
int main() {
b |= __builtin_memcmp(p, "1234567", 7);
}
```
This produces unnecessarily slow code, which computes not only whether the strings are equal but also whether they are greater or less: https://godbolt.org/z/Tf71qovK3
It looks like the transform from the `memcmp` to `bcmp` lib function is not firing here, though it should be able to.
Contributor guide
Research direction
Start with the provided C++ testcase using __builtin_memcmp in a bitwise-or expression, and reproduce the generated code from the linked Godbolt example. Trace the memcmp-to-bcmp optimization and verify that the completed change makes this case use the bcmp form without computing ordering information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100