Skip to content

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

@Leo0506

Description

@Leo0506
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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions