fold strlen after strcmp(a, b) == 0
Open
constant-folding
missed-optimization
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
[GCC bug link](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92112)
[Clang 22.0 godbolt](https://godbolt.org/z/fWx66xdW3)
Compiling this C code with -O2 does not transform f () and g () to ret void:
```
extern char a[], b[];
void f (void)
{
if (__builtin_strcmp (a, b) != 0)
return;
if (__builtin_strlen (a) != __builtin_strlen (b)) // can be folded to false
__builtin_abort ();
}
void g (void)
{
if (__builtin_strlen (a) < 7)
return;
if (__builtin_strcmp (a, b) != 0)
return;
if (__builtin_strlen (b) < 7) // can be folded to false
__builtin_abort ();
}
```
Contributor guide
Assessment
This issue has not been assessed yet.