Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion jscomp/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,11 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
default ()

let not_ loc x : t =
prim ~primitive:Pnot ~args:[x] loc
match x with
| Lprim ({primitive = Pintcomp Cneq } as prim)->
Lprim {prim with primitive = Pintcomp Ceq}
| _ ->
prim ~primitive:Pnot ~args:[x] loc


let has_boolean_type (x : t) =
Expand Down Expand Up @@ -769,6 +773,24 @@ let if_ (a : t) (b : t) (c : t) : t =
{ body with sw_failaction = Some b; sw_consts_full = false; })
| _ -> Lifthenelse(a,b,c)
end
| Lprim{primitive = Pisint; args = [Lvar i];_}
->
begin match b with
| Lifthenelse(Lprim{primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _]} , _, b_f)
when Ident.same i j && eq_approx b_f c ->
b
| Lprim{primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _]}
when Ident.same i j && eq_approx false_ c -> b
| Lifthenelse(Lprim({primitive = Pintcomp Cneq ; args = [Lvar j; Lconst _]} as b_pred) , b_t, b_f)
when Ident.same i j && eq_approx b_t c ->
Lifthenelse(Lprim{b_pred with primitive = Pintcomp Ceq}, b_f, b_t)
| Lprim({primitive = Pintcomp Cneq ; args = [Lvar j; Lconst _] as args ; loc} )
| Lprim(
{primitive = Pnot ; args = [Lprim{primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _] as args; loc}]})
when Ident.same i j && eq_approx true_ c
-> Lprim{primitive = Pintcomp Ceq; args; loc}
| _ -> Lifthenelse(a,b,c)
end
| _ -> Lifthenelse (a,b,c))


Expand Down
1 change: 1 addition & 0 deletions jscomp/test/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ o test/gpr_4494_test.cmi test/gpr_4494_test.cmj : cc test/gpr_4494_test.ml | $st
o test/gpr_4519_test.cmi test/gpr_4519_test.cmj : cc test/gpr_4519_test.ml | test/mt.cmj $stdlib
o test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
o test/gpr_4639_test.cmi test/gpr_4639_test.cmj : cc test/gpr_4639_test.ml | $stdlib
o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.ml | $stdlib
o test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib
o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib
o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.ml | $stdlib
Expand Down
Loading