Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize cmm shifts and tags #3669

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
8 changes: 7 additions & 1 deletion backend/amd64/selection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class selector =
method! select_operation op args dbg =
match op with
(* Recognize the LEA instruction *)
| Caddi | Caddv | Cadda | Csubi -> (
| Caddi | Caddv | Cadda | Csubi | Cor -> (
match self#select_addressing Word_int (Cop (op, args, dbg)) with
| Iindexed _, _ | Iindexed2 0, _ -> super#select_operation op args dbg
| ( ((Iindexed2 _ | Iscaled _ | Iindexed2scaled _ | Ibased _) as addr),
Expand Down Expand Up @@ -258,6 +258,12 @@ class selector =
Ispecific Isextend32, [k]
| _ -> super#select_operation op args dbg)
(* Recognize zero extension *)
| Clsr -> (
match args with
| [Cop (Clsl, [k; Cconst_int (32, _)], _); Cconst_int (32, _)] ->
Ispecific Izextend32, [k]
| _ -> super#select_operation op args dbg)
(* Recognize zero extension again *)
| Cand -> (
match args with
| [arg; Cconst_int (0xffff_ffff, _)]
Expand Down
7 changes: 7 additions & 0 deletions backend/amd64/selection_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ let rec select_addr exp =
| ( ((Asymbol _ | Aadd (_, _) | Ascaledadd (_, _, _)), _),
((Asymbol _ | Alinear _ | Aadd (_, _) | Ascaledadd (_, _, _)), _) ) ->
Aadd (arg1, arg2), 0)
| Cmm.Cop (Cor, [arg; Cconst_int (1, _)], _)
| Cmm.Cop (Cor, [Cconst_int (1, _); arg], _) -> (
(* optimize tagging integers *)
match select_addr arg with
| Ascale (e, scale), off when scale mod 2 = 0 ->
Ascale (e, scale), off lor 1
| _ -> default)
| _ -> default

(* Special constraints on operand and result registers *)
Expand Down
Loading