Skip to content

Commit

Permalink
Reorder a phase, improves code quality a bunch
Browse files Browse the repository at this point in the history
  • Loading branch information
msprotz committed Oct 2, 2023
1 parent 15aef89 commit d1d94a4
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/Simplify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,6 @@ let count_and_remove_locals final = object (self)
let e1 = self#visit_expr_w env0 e1 in
self#remove_trivial_let (ELet (b, e1, e2))

method! visit_EBufSub env e1 e2 =
(* This creates more opportunities for values to be eliminated if unused.
* Also, AstToCStar emits BufSub (e, 0) as just e, so we need the value
* check to be in agreement on both sides. *)
match e2.node with
| EConstant (_, "0") ->
(self#visit_expr env e1).node
| _ ->
EBufSub (self#visit_expr env e1, self#visit_expr env e2)

method! visit_DFunction env cc flags n ret name binders body =
if not final then
super#visit_DFunction env cc flags n ret name binders body
Expand Down Expand Up @@ -926,6 +916,15 @@ let misc_cosmetic = object (self)
| _ ->
EBufWrite (e1, e2, e3)

method! visit_EBufSub env e1 e2 =
(* AstToCStar emits BufSub (e, 0) as just e, so we need the value
* check to be in agreement on both sides. *)
match e2.node with
| EConstant (_, "0") ->
(self#visit_expr env e1).node
| _ ->
EBufSub (self#visit_expr env e1, self#visit_expr env e2)

(* renumber uu's to have a stable numbering scheme that minimizes the diff
* from one code generation to another *)
method! visit_decl env decl =
Expand Down

0 comments on commit d1d94a4

Please sign in to comment.