llvm / llvm/llvm-project

Missed Optimization: fold smax(a, -b) + b into smax(a + b, 0)

Open
#166,878 4 comments 0 reactions 1 assignee Claimed by @NullSpaceBoy View on GitHub
llvm:instcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
define i32 @src(i32 %arg0, i32 %arg1) {
%v0 = sub nsw i32 0, %arg1
%v1 = call i32 @llvm.smax.i32(i32 %arg0, i32 %v0)
%v2 = add nuw nsw i32 %v1, %arg1
ret i32 %v2
}

define i32 @tgt(i32 %arg0, i32 %arg1) {
%v0 = add i32 %arg0, %arg1
%v1 = call i32 @llvm.smax.i32(i32 %v0, i32 0)
ret i32 %v1
}
```
alive2: https://alive2.llvm.org/ce/z/qqiS7X
godbolt: https://godbolt.org/z/s67Tea5j6
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/ffmpeg/optimized/ftr.ll

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.