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

Instcombine incorrectly optimizes `fcmp uno`

Open DaniilSuchkov opened this issue 3 years ago • 2 comments

After this commit: https://github.com/llvm/llvm-project/commit/e47b76a82a0300900dbf3c2d3a50552a76305a8c running opt -passes=instcombine on the following IR:

define i1 @test(i64 %arg) {
  %sitofp = sitofp i64 %arg to float
  %fmul = fmul float %sitofp, 0x7FF0000000000000
  %fcmp = fcmp uno float %fmul, 0.000000e+00
  ret i1 %fcmp
}

results in

define i1 @test(i64 %arg) {
  ret i1 false
}

That's not correct because fcmp uno returns true if either argument is NaN and by IEEE-754 multiplication of infinity (aka 0x7FF0000000000000) and 0 (sitofp i64 %arg to float with %arg == 0) is NaN. Alive2 points out exactly this case: https://alive2.llvm.org/ce/z/5rPFgH

DaniilSuchkov avatar Jun 14 '23 18:06 DaniilSuchkov

https://reviews.llvm.org/D152957

arsenm avatar Jun 14 '23 20:06 arsenm

Not sure why it didn't auto-close after the commit

arsenm avatar Jun 15 '23 13:06 arsenm