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

add chance of reverse chain assignment in perm_temp_for_expr #138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

snuffysasa
Copy link
Contributor

This was complicated to implement and took me awhile, and probably only limited benefit.

If its too much work to get it merged in, or don't like it, I may just end up using it on my fork for a while and see how it goes

@simonlindholm
Copy link
Owner

can you give an example of what this aims to do?

@snuffysasa
Copy link
Contributor Author

Yep,

in perm_temp_for_expr, sometimes it will introduce a new_var and assign it in the first expression it's used. Like so:

current_coins = new_var = player->current_coins;

This adds a 50/50 chance to do the assignment like this:

new_var = current_coins = player->current_coins;

which fixes some regswaps

@snuffysasa snuffysasa force-pushed the reverse_chain_assign_w_new_var branch from dd23629 to eadec51 Compare June 28, 2022 00:01
@snuffysasa
Copy link
Contributor Author

rebased to latest main branch and resolved merge conflicts

ready for more review, but not a big priority.

@snuffysasa snuffysasa marked this pull request as ready for review July 1, 2022 23:04
@simonlindholm
Copy link
Owner

Yep,

in perm_temp_for_expr, sometimes it will introduce a new_var and assign it in the first expression it's used. Like so:

current_coins = new_var = player->current_coins;

This adds a 50/50 chance to do the assignment like this:

new_var = current_coins = player->current_coins;

which fixes some regswaps

Sorry, I'm failing to line this description up with the code. It seems to do something else, involving changing which expression gets replaced. Or maybe I'm just misunderstanding the code, in which I need comments on it explaining what each thing does... (this may be good in either case) Until then I can't give a proper review.

Copy link
Owner

@simonlindholm simonlindholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor nits)

ast_util.for_nested_blocks(stmt, rec)
return None

rec(block)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simpler to use a visitor for this rather than explicit recursion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I think it was not possible to use a visitor here. I'll explain what the issue was when I get back to this

if place is None and not should_make_ptr:
stmt = find_assignment_stmt_by_rvalue(fn.body, expr)
if stmt and random_bool(random, 0.5):
assert isinstance(stmt, ca.Assignment)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assert shouldn't be needed

@@ -712,18 +744,19 @@ def find_duplicates(e: Expression) -> None:
else:
replace_subexprs(fn.body, find_duplicates)

assert orig_expr in replace_cands
replace_cand_set: Set[Expression] = set()
if random_bool(random, PROB_TEMP_REPLACE_ALL):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I changed this part of the code in a recent commit, will need to be updated)

@snuffysasa
Copy link
Contributor Author

Yep,
in perm_temp_for_expr, sometimes it will introduce a new_var and assign it in the first expression it's used. Like so:

current_coins = new_var = player->current_coins;

This adds a 50/50 chance to do the assignment like this:

new_var = current_coins = player->current_coins;

which fixes some regswaps

Sorry, I'm failing to line this description up with the code. It seems to do something else, involving changing which expression gets replaced. Or maybe I'm just misunderstanding the code, in which I need comments on it explaining what each thing does... (this may be good in either case) Until then I can't give a proper review.

Yea makes sense, it was quite tricky to implement this. I will try to make the code more clear with comments in a bit.

@ethteck
Copy link
Contributor

ethteck commented Mar 26, 2023

@snuffysasa did you determine this to be useful / has it been helping you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants