From c2403e4eefc640e63bedea7cb90d538e9ffa8cb8 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 10 Dec 2024 15:43:16 +0100 Subject: [PATCH] perf: `ShrU 31` befor `If` can be `Clz` --- src/codegen/instrList.ml | 4 ++++ test/bench/ok/heap-32.drun-run.ok | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/codegen/instrList.ml b/src/codegen/instrList.ml index 886a103cdd1..3179e698806 100644 --- a/src/codegen/instrList.ml +++ b/src/codegen/instrList.ml @@ -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' diff --git a/test/bench/ok/heap-32.drun-run.ok b/test/bench/ok/heap-32.drun-run.ok index 8ae164a705f..5d3d216fe42 100644 --- a/test/bench/ok/heap-32.drun-run.ok +++ b/test/bench/ok/heap-32.drun-run.ok @@ -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