Skip to content

Commit

Permalink
Simplify Is_null in Flambda2
Browse files Browse the repository at this point in the history
  • Loading branch information
lthls committed Nov 12, 2024
1 parent 1e0be89 commit 08a00b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions middle_end/flambda2/simplify/simplify_unary_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ let simplify_tag_immediate dacc ~original_term ~arg:_ ~arg_ty:naked_number_ty
let dacc = DA.add_variable dacc result_var ty in
SPR.create original_term ~try_reify:true dacc

let simplify_is_int_or_get_tag dacc ~original_term ~scrutinee ~scrutinee_ty:_
let simplify_relational_primitive dacc ~original_term ~scrutinee ~scrutinee_ty:_
~result_var ~make_shape =
(* CR vlaviron: We could use prover functions to simplify but it's probably
not going to help that much.
Expand All @@ -207,7 +207,7 @@ let simplify_is_int ~variant_only dacc ~original_term ~arg:scrutinee
~arg_ty:scrutinee_ty ~result_var =
if variant_only
then
simplify_is_int_or_get_tag dacc ~original_term ~scrutinee ~scrutinee_ty
simplify_relational_primitive dacc ~original_term ~scrutinee ~scrutinee_ty
~result_var ~make_shape:(fun scrutinee ->
T.is_int_for_scrutinee ~scrutinee)
else
Expand All @@ -221,7 +221,7 @@ let simplify_is_int ~variant_only dacc ~original_term ~arg:scrutinee

let simplify_get_tag dacc ~original_term ~arg:scrutinee ~arg_ty:scrutinee_ty
~result_var =
simplify_is_int_or_get_tag dacc ~original_term ~scrutinee ~scrutinee_ty
simplify_relational_primitive dacc ~original_term ~scrutinee ~scrutinee_ty
~result_var ~make_shape:(fun block -> T.get_tag_for_block ~block)

let simplify_array_length _array_kind dacc ~original_term ~arg:_
Expand Down Expand Up @@ -889,8 +889,9 @@ let simplify_mutable_block_load _access_kind ~field:_ ~original_prim dacc
~original_term

(* CR layouts v3: implement a real simplifier. *)
let simplify_is_null dacc ~original_term ~arg:_ ~arg_ty:_ ~result_var =
SPR.create_unknown dacc ~result_var K.naked_immediate ~original_term
let simplify_is_null dacc ~original_term ~arg:scrutinee ~arg_ty:scrutinee_ty ~result_var =
simplify_relational_primitive dacc ~original_term ~scrutinee ~scrutinee_ty
~result_var ~make_shape:(fun scrutinee -> T.is_null ~scrutinee)

let simplify_unary_primitive dacc original_prim (prim : P.unary_primitive) ~arg
~arg_ty dbg ~result_var =
Expand Down
2 changes: 2 additions & 0 deletions middle_end/flambda2/types/flambda2_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ val is_int_for_scrutinee : scrutinee:Simple.t -> t

val get_tag_for_block : block:Simple.t -> t

val is_null : scrutinee:Simple.t -> t

val any_block : t

(** The type of an immutable block with a known tag, size and field types. *)
Expand Down

0 comments on commit 08a00b7

Please sign in to comment.