-
Notifications
You must be signed in to change notification settings - Fork 83
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
base: main
Are you sure you want to change the base?
Conversation
Array.length gets compiled worse now, i need to fix that
the latter doesn't turn into a |
3468a12
to
529a6d8
Compare
This will be used by a future pr to simplify casting without impacting performance as much
2d05f61
to
e1c12d7
Compare
cd768b1
to
93513c0
Compare
array length looks strictly better now, the only problems are in cmm-scalar-type, which i'll fix in yet another PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should be good to merge once comment have been adressed/answered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few comments/questions, but as far as code semantics goes, we should be good !
| Cop (Csubi, [c; Cconst_int (x, _)], _) when Misc.no_overflow_sub n x -> | ||
add_const c (n - x) dbg | ||
| c -> Cop (Caddi, [c; Cconst_int (n, dbg)], dbg) | ||
map_tail1 c ~f:(fun c -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you encounter cases where the map_tail1
was important ? if so it would be nice to document them (at least some of the general shape/conditions when it can happen)
| Cop (Caddi, [c1; Cconst_int (n1, _)], _), c2 -> | ||
add_const (sub_int c1 c2 dbg) n1 dbg | ||
| c1, c2 -> Cop (Csubi, [c1; c2], dbg) | ||
map_tail2 c1 c2 ~f:(fun c1 c2 -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question as above: if only for curiosity/better understanding, what kind of situations lead to map_tail2
being needed/useful ?
add_const (add_int c1 c2 dbg) n2 dbg | ||
| c1, Cop (Cor, [c2; Cconst_int (n2, _)], _) | ||
when can_interchange_add_with_or c2 n2 -> | ||
add_const (add_int c1 c2 dbg) n2 dbg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be simpler in this case to call prefer_add
on c1
and c2
before the match ?
| Cop (Cxor, [x; ((Cconst_int _ | Cconst_natint _) as y)], _) -> | ||
xor_int (lsl_int x c2 dbg) (lsl_int y c2 dbg) dbg | ||
| c1 -> Cop (Clsl, [c1; c2], dbg))) | ||
| Cop (Clsl, [x; (Cconst_int (n', _) as y)], z), c2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Cop (Clsl, [x; (Cconst_int (n', _) as y)], z), c2 | |
| Cop (Clsl, [x; (Cconst_int (n', _) as y)], dbg'), c2 |
this code is already tricky as is without having to remember that z
is a debuginfo, contrary to x
and y
, ^^
Cop | ||
(Cor, [asr_int c (Cconst_int (n - 1, dbg)) dbg; Cconst_int (1, dbg)], dbg) | ||
| c -> incr_int (lsl_int c (Cconst_int (1, dbg)) dbg) dbg | ||
or_const (asr_const c (n - 1) dbg) 1n dbg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check whether is_defined_shift n
here ? This code is correct regardless , so it might deserve a comment to explain/explicit that it doesn't matter here.
or_const (asr_const c (n - 1) dbg) 1n dbg | ||
| Cop (Clsr, [c; Cconst_int (n, _)], _) when n > 0 -> | ||
or_const (lsr_const c (n - 1) dbg) 1n dbg | ||
| c -> incr_int (lsl_const c 1 dbg) dbg | ||
|
||
let untag_int i dbg = | ||
match i with | ||
| Cconst_int (n, _) -> Cconst_int (n asr 1, dbg) | ||
| Cop (Cor, [Cop (Casr, [c; Cconst_int (n, _)], _); Cconst_int (1, _)], _) | ||
when n > 0 && n < (size_int * 8) - 1 -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when n > 0 && n < (size_int * 8) - 1 -> | |
when n > 0 && is_defined_shift (n + 1) -> |
might be simpler and more consistent ?
or_int (sign_extend ~bits x ~dbg) (sign_extend ~bits y ~dbg) dbg | ||
| Cop (Cxor, [x; y], _) when is_constant y -> | ||
xor_int (sign_extend ~bits x ~dbg) (sign_extend ~bits y ~dbg) dbg | ||
| Cop (((Casr | Clsr) as op), [inner; Cconst_int (n, _)], _) as e | ||
when 0 <= n && n < arch_bits -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when 0 <= n && n < arch_bits -> | |
when (is_defined_shift n) -> |
add some optimizations for shifts and tags in preparation for cmm-scalar-type, which needs these to keep decent performance