llvm / llvm/llvm-project

[Regression] Missed Optimization at O3

Open
#204,049 0 comments 0 reactions 0 assignees View on GitHub
llvm:optimizations missed-optimization regression:20
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/aEas4aYqP
Description: LLVM (trunk -O3) cannot optimize the following C function annotated with value range information, while LLVM 20.1.0 and GCC (trunk -O3) can.

```c
int src(int v0_u8, int v1_u8) {
if (!((0 <= v0_u8) && (v0_u8 <= 1))) __builtin_unreachable();
if (!((1 <= v1_u8) && (v1_u8 <= 2))) __builtin_unreachable();
int i0_u8 = v0_u8 >> v1_u8;
int i1_u8 = v1_u8 ^ i0_u8;
return i1_u8;
}
```

Clang trunk's O3 output:
```assembly
src:
mov ecx, esi
mov eax, edi
shr eax, cl
xor eax, esi
ret
```

Clang 20.1.0 O3 output:
```assembly
src:
mov eax, esi
ret
```

GCC's O3 output:
```assembly
src:
mov eax, esi
ret
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.