llvm / llvm/llvm-project

[Regression] fail to optimize `x / y - z` into `C - z` with the given range information

Open
#219,130 0 comments 0 reactions 1 assignee Claimed by @el-ev View on GitHub
llvm:instcombine llvm:optimizations missed-optimization regression:21
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/azTjb93EE

C code:
```c
unsigned src(unsigned v0, unsigned v1, unsigned v2) {
if (!((39 <= v0) && (v0 <= 46))) __builtin_unreachable();
if (!((1 <= v1) && (v1 <= 2))) __builtin_unreachable();
if (!((184 <= v2) && (v2 <= 194))) __builtin_unreachable();
unsigned i0 = v2 / v0;
unsigned i1 = i0 - v1;
return i1;
}
```

LLVM trunk -O3:
```assembly
src:
movzx eax, dl
div dil
movzx eax, al
sub eax, esi
ret
```

LLVM 20.1.0 -O3:
```assembly
src:
mov eax, 4
sub 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.