Don't commute negation with float comparison (#1470)

Floating-point comparisons such as `<` and `>=` are always false when one of their arguments is NaN.  For this reason, it is incorrect to simplify `not (x < y)` as `x >= y` if this is a FP comparison.
This wrong optimization was introduced in 4.06.0 and is being reverted by this commit.
master
Leo White 2017-11-21 17:38:18 +00:00 committed by Xavier Leroy
parent 7f5f82dc9c
commit c6f3a00b31
4 changed files with 10 additions and 2 deletions

View File

@ -80,6 +80,9 @@ Working version
(Luc Maranget, review by Thomas Refis and Gabriel Scherer, report
by Abdelraouf Ouadjaout and Thibault Suzanne)
- GPR#1470: Don't commute negation with float comparison
(Leo White, review by Xavier Leroy)
OCaml 4.06.0 (3 Nov 2017):
--------------------------

View File

@ -292,8 +292,6 @@ let mk_not dbg cmm =
tag_int (Cop(Ccmpi (negate_comparison cmp), [c1; c2], dbg'')) dbg'
| Cop(Ccmpa cmp, [c1; c2], dbg'') ->
tag_int (Cop(Ccmpa (negate_comparison cmp), [c1; c2], dbg'')) dbg'
| Cop(Ccmpf cmp, [c1; c2], dbg'') ->
tag_int (Cop(Ccmpf (negate_comparison cmp), [c1; c2], dbg'')) dbg'
| _ ->
(* 0 -> 3, 1 -> 1 *)
Cop(Csubi, [Cconst_int 3; Cop(Clsl, [c; Cconst_int 1], dbg)], dbg)

View File

@ -0,0 +1,6 @@
let compare_nan () =
not (nan < 0.0)
[@@inline never]
let x = print_endline (string_of_bool (compare_nan ()))

View File

@ -0,0 +1 @@
true