llvm / llvm/llvm-project

Missed Optimization: Fold fcmp+select clamp to [-32000, 32000] into maxnum/ minnum pair

Open
#167,094 1 comment 0 reactions 0 assignees View on GitHub
llvm:instcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
define float @src(float %arg0) {
%v0 = fcmp nsz ogt float %arg0, -3.200000e+04
%v1 = select nsz i1 %v0, float %arg0, float -3.200000e+04
%v2 = fcmp nsz ogt float %v1, 3.200000e+04
%v3 = select nsz i1 %v2, float 3.200000e+04, float %v1
ret float %v3
}

define float @tgt(float %arg0) {
%v1 = call float @llvm.maxnum.f32(float %arg0, float -3.200000e+04)
%v3 = call float @llvm.minnum.f32(float %v1, float 3.200000e+04)
ret float %v3
}
```
alive2: https://alive2.llvm.org/ce/z/FYdXs-
godbolt: https://godbolt.org/z/38roe3MhK
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/ffmpeg/optimized/speexdec.ll

Contributor guide

Open the contributing guide

Research direction

Start with the LLVM IR in the issue and compare the source and target through the provided Alive2 link; the pattern is also present in bench/ffmpeg/optimized/speexdec.ll. Done means LLVM recognizes this fcmp/select clamp pattern and produces the equivalent maxnum/minnum pair while preserving the shown semantics.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.