llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Missed fcmp(frem, inf) => false

Open 134ARG opened this issue 8 months ago • 1 comments

For the IR pattern:

define i1 @test_frem_fcmp_inf(double %a, double %b) {
entry:
  %rem = frem double %a, %b
  %is.inf = fcmp oeq double %rem, 0x7FF0000000000000 ; INF
  ret i1 %is.inf
}

Since the frem will never return an inf, so it can be optimized into a constant false return as follows:

define i1 @test_frem_fcmp_inf(double %a, double %b) {
entry:
  ret i1 false
}

Currently the LLVM just missed this potential optimization by simply leaving it as is: https://godbolt.org/z/PKfT5M8TY.

The alive2 at Compiler Explorer timed out, so I ran alive2 locally (takes 3m42s):

Image

134ARG avatar Mar 16 '26 08:03 134ARG

I already have a fix for that. Please assign it to me.

134ARG avatar Mar 16 '26 08:03 134ARG