Skip to content

Missed Optimization: fold fcmp ord + select before fcmp oeq (x, C) into a single fcmp oeq (x, C) #142711

@Cancelll

Description

@Cancelll
define i1 @src(ptr %0) {
  %2 = getelementptr inbounds nuw i8, ptr %0, i64 48
  %3 = load double, ptr %2, align 8
  %4 = getelementptr inbounds nuw i8, ptr %0, i64 24
  %5 = load double, ptr %4, align 8
  %6 = fadd double %3, %5
  %7 = fcmp ord double %6, 0.000000e+00
  %8 = select i1 %7, double %6, double 0.000000e+00
  %9 = fcmp oeq double %8, 1.000000e+00
  ret i1 %9
}

define i1 @tgt(ptr %0) {
  %2 = getelementptr inbounds nuw i8, ptr %0, i64 48
  %3 = load double, ptr %2, align 8
  %4 = getelementptr inbounds nuw i8, ptr %0, i64 24
  %5 = load double, ptr %4, align 8
  %6 = fadd double %3, %5
  %7 = fcmp oeq double %6, 1.000000e+00
  ret i1 %7
}

Alive2: https://alive2.llvm.org/ce/z/2T-D5v

Found this pattern in https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/typst-rs/optimized/4m3ebbqd1xx21e5m.ll

godbolt: https://godbolt.org/z/vMhzj9eP3

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions