Skip to content

Commit 31a7586

Browse files
xclercd-kalinichenko
authored andcommitted
Disable lsl optimizations in sign extension (cmm) (#4494)
Disable `lsl` optimizations in sign extension (cmm).
1 parent b82534d commit 31a7586

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

backend/cmm_helpers.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ and asr_const c n dbg = asr_int c (Cconst_int (n, dbg)) dbg
726726

727727
and lsr_const c n dbg = lsr_int c (Cconst_int (n, dbg)) dbg
728728

729+
let lsl_const0 c n dbg = Cop (Clsl, [c; Cconst_int (n, dbg)], dbg)
730+
729731
let is_power2 n = n = 1 lsl Misc.log2 n
730732

731733
and mult_power2 c n dbg = lsl_int c (Cconst_int (Misc.log2 n, dbg)) dbg
@@ -1579,7 +1581,7 @@ let rec low_bits ~bits ~dbg x =
15791581
when 0 <= right && right <= left && left <= unused_bits ->
15801582
(* these sign-extensions can be replaced with a left shift since we
15811583
don't care about the high bits that it changed *)
1582-
low_bits ~bits (lsl_const x (left - right) dbg) ~dbg
1584+
low_bits ~bits (lsl_const0 x (left - right) dbg) ~dbg
15831585
| x -> (
15841586
match get_const_bitmask x with
15851587
| Some (x, bitmask) when does_mask_keep_low_bits bitmask ->
@@ -1618,7 +1620,7 @@ let rec sign_extend ~bits ~dbg e =
16181620
assert (0 < bits && bits <= arch_bits);
16191621
let unused_bits = arch_bits - bits in
16201622
let sign_extend_via_shift e =
1621-
asr_const (lsl_const e unused_bits dbg) unused_bits dbg
1623+
asr_const (lsl_const0 e unused_bits dbg) unused_bits dbg
16221624
in
16231625
if bits = arch_bits
16241626
then e
@@ -1646,7 +1648,7 @@ let rec sign_extend ~bits ~dbg e =
16461648
(* sign-extension is a no-op since the top n bits already match *)
16471649
e
16481650
else
1649-
let e = lsl_const inner (unused_bits - n) dbg in
1651+
let e = lsl_const0 inner (unused_bits - n) dbg in
16501652
asr_const e unused_bits dbg
16511653
| Cop (Cload { memory_chunk; mutability; is_atomic }, args, dbg) as e
16521654
-> (

0 commit comments

Comments
 (0)