Skip to content

Commit abefc4a

Browse files
committed
Apply CSE on updated primitive
1 parent d9655ec commit abefc4a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

middle_end/flambda/simplify/simplify_primitive.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ let try_cse dacc ~original_prim ~simplified_args_with_tys ~min_name_mode
4848
if not (Name_mode.equal min_name_mode Name_mode.normal) then Not_applied dacc
4949
else
5050
let result_var = VB.var result_var in
51-
match apply_cse dacc ~original_prim with
51+
let args = List.map fst simplified_args_with_tys in
52+
match apply_cse dacc ~original_prim:(P.update_args original_prim args) with
5253
| Some replace_with ->
5354
let named = Named.create_simple replace_with in
5455
let ty = T.alias_type_of (P.result_kind' original_prim) replace_with in
5556
let env_extension = TEE.one_equation (Name.var result_var) ty in
56-
let args = List.map fst simplified_args_with_tys in
5757
let simplified_named =
5858
let cost_metrics =
5959
Cost_metrics.notify_removed

middle_end/flambda/terms/flambda_primitive.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,19 @@ let args t =
16381638
| Ternary (_, x0, x1, x2) -> [x0; x1; x2]
16391639
| Variadic (_, xs) -> xs
16401640

1641+
let update_args t args =
1642+
match t, args with
1643+
| Nullary _, [] -> t
1644+
| Unary (p, _), [x0] -> Unary (p, x0)
1645+
| Binary (p, _, _), [x0; x1] -> Binary (p, x0, x1)
1646+
| Ternary (p, _, _, _), [x0; x1; x2] -> Ternary (p, x0, x1, x2)
1647+
| Variadic (p, l), xs ->
1648+
assert(List.length l = List.length xs);
1649+
Variadic (p, xs)
1650+
| _, _ ->
1651+
Misc.fatal_errorf "Wrong arity for updating primitive %a with arguments %a"
1652+
print t Simple.List.print args
1653+
16411654
let result_kind (t : t) =
16421655
match t with
16431656
| Nullary prim -> result_kind_of_nullary_primitive prim

middle_end/flambda/terms/flambda_primitive.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ include Contains_ids.S with type t := t
334334

335335
val args : t -> Simple.t list
336336

337+
val update_args : t -> Simple.t list -> t
338+
337339
(** Simpler version (e.g. for [Inlining_cost]), where only the actual
338340
primitive matters, not the arguments. *)
339341
module Without_args : sig

0 commit comments

Comments
 (0)