Add peephole optimizations for CFG blocks.#1666
Conversation
…ded are:
* remove_useless_mov which treats the case:
mov r1, r2
mov r2, r1
In this case the second move can be deleted
* fold_intop_imm which treats the case:
op1 r, imm1
op2 r, imm2
We can rewrite this as:
op1 r, (imm1 op2 imm2)
Iff op1 and op2 are associative and the result (imm1 op2 imm2) does not overflow.
Added the following extra functionality for the Flambda_backend.Doubly_linked_list data structure:
* next cell -> get the next cell
* hd_cell t -> get a cell to the first element in the list
* last_cell t -> get a cell to the last element of the list
* delete_curr/delete_after/delete_before cell -> delete the current element, the one after or before a cell. asserts if there is no cell to delete (i.e. we try to delete before the first element or after the last)
* extra functionlity for inserting and getting back the newly inserted cell in a Doubly_linked_list
Added:
* Flags for enabling peephole optimizations (-cfg-peephole-optimize)
* A generic CSV data structure
7594cff to
a9a9939
Compare
A couple of small simplifications that are obvious by themselves but would have made #1666 a bit harder to review: * `Env.sign_of_cmi` is only called via `read_sign_of_cmi` with `~freshen:true`, so just rename `sign_of_cmi` to `read_sign_of_cmi` and freshen unconditionally * `Persistent_env.save_pers_struct` requires a `pers_struct` but doesn't use all of it, so just inline it into its only call site
…hub.com:GabiTulba/flambda-backend into backend-peephole-optimizations-without-tracking
xclerc
left a comment
There was a problem hiding this comment.
Looks pretty good; most of the suggested
changes are about unused elements and
typos.
Did not put a comment on the diff, but I
think it would make sense to use the
same set of warnings in all files. With
one possible exception: the "fragile
pattern" warning, but maybe we can
disable it locally rather than at the
top of some files.
gretay-js
left a comment
There was a problem hiding this comment.
Can you add some tests, including overflow tests?
Additionally, there should be a check to guarantee termination of rewriting (e.g., if one pattern removes instruction and another adds it back). Currently, patterns only remove instructions so this is implicit, but may worth a comment somewhere.
Separate architectural constraints into a helper function, and leave refactoring it into target specific folder to another PR.
Co-authored-by: Greta Yorsh <45005955+gretay-js@users.noreply.github.com>
Co-authored-by: Greta Yorsh <45005955+gretay-js@users.noreply.github.com>
…hub.com:GabiTulba/flambda-backend into backend-peephole-optimizations-without-tracking
The optimizations added are as follows:
remove_useless_mov which treats the case:
fold_intop_imm which treats the case:
Added the following extra functionality for the
Flambda_backend.Doubly_linked_listdata structure:next cell-> get the next cellhd_cell t-> get a cell to the first element in the listlast_cell t-> get a cell to the last element of the listdelete_curr/delete_after/delete_before cell-> delete the current element, the one after or before a cell. asserts if there is no cell to delete (i.e. we try to delete before the first element or after the last)Doubly_linked_listAdded:
-cfg-peephole-optimize)This was benchmarked on the following libraries with the following results:
Base:
414548171.54 sec171.84 sec.ofile size reduction from optimizations:2288 bytesCore:
4473951177.83 sec177.43 sec.ofile size reduction from optimizations:5968 bytes