Skip to content

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

@Leo0506

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions