@@ -676,7 +676,11 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
676
676
default ()
677
677
678
678
let not_ loc x : t =
679
- prim ~primitive: Pnot ~args: [x] loc
679
+ match x with
680
+ | Lprim ({primitive = Pintcomp Cneq } as prim )->
681
+ Lprim {prim with primitive = Pintcomp Ceq }
682
+ | _ ->
683
+ prim ~primitive: Pnot ~args: [x] loc
680
684
681
685
682
686
let has_boolean_type (x : t ) =
@@ -769,6 +773,24 @@ let if_ (a : t) (b : t) (c : t) : t =
769
773
{ body with sw_failaction = Some b; sw_consts_full = false ; })
770
774
| _ -> Lifthenelse (a,b,c)
771
775
end
776
+ | Lprim {primitive = Pisint ; args = [Lvar i];_}
777
+ ->
778
+ begin match b with
779
+ | Lifthenelse (Lprim {primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _]} , _, b_f)
780
+ when Ident. same i j && eq_approx b_f c ->
781
+ b
782
+ | Lprim {primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _]}
783
+ when Ident. same i j && eq_approx false_ c -> b
784
+ | Lifthenelse (Lprim ({primitive = Pintcomp Cneq ; args = [Lvar j; Lconst _]} as b_pred) , b_t, b_f)
785
+ when Ident. same i j && eq_approx b_t c ->
786
+ Lifthenelse (Lprim {b_pred with primitive = Pintcomp Ceq }, b_f, b_t)
787
+ | Lprim ({primitive = Pintcomp Cneq ; args = [Lvar j; Lconst _] as args ; loc} )
788
+ | Lprim (
789
+ {primitive = Pnot ; args = [Lprim {primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _] as args; loc}]})
790
+ when Ident. same i j && eq_approx true_ c
791
+ -> Lprim {primitive = Pintcomp Ceq ; args; loc}
792
+ | _ -> Lifthenelse (a,b,c)
793
+ end
772
794
| _ -> Lifthenelse (a,b,c))
773
795
774
796
0 commit comments