Skip to content

Commit

Permalink
perf: ShrU 31 befor If can be Clz
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreif committed Dec 10, 2024
1 parent ac26d8c commit c2403e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/codegen/instrList.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ let optimize : instr list -> instr list = fun is ->
({it = Const cr; _} as const) :: ({it = Binary opr; _} as op) :: r'
when Option.is_some (combine_shifts const op (opl, cl, opr, cr.it)) ->
go l' (Option.get (combine_shifts const op (opl, cl, opr, cr.it)) @ r')
(* Examining topmost bit *)
| {it = Binary (I32 I32Op.ShrU); _} as shift :: {it = Const {it = I32 31l; _}; _} :: l',
({it = If (res,then_,else_); _} as if_) :: r' ->
go l' ({ shift with it = Unary (I32 I32Op.Clz) } :: { if_ with it = If (res,else_,then_) } :: r')
(* Null shifts can be eliminated *)
| l', {it = Const {it = I32 0l; _}; _} :: {it = Binary (I32 I32Op.(Shl|ShrS|ShrU)); _} :: r' ->
go l' r'
Expand Down
2 changes: 1 addition & 1 deletion test/bench/ok/heap-32.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (50_227, +29_863_068, 723_684_961)
debug.print: (50_227, +29_863_068, 723_584_961)
debug.print: (50_070, +32_992_212, 785_200_313)
ingress Completed: Reply: 0x4449444c0000

0 comments on commit c2403e4

Please sign in to comment.