Skip to content

Avoid mutable arguments in CSEToAssignmentMapper#610

Merged
inducer merged 2 commits intomainfrom
do_not_allow_mutable_behavior
May 4, 2022
Merged

Avoid mutable arguments in CSEToAssignmentMapper#610
inducer merged 2 commits intomainfrom
do_not_allow_mutable_behavior

Conversation

@kaushikcfd
Copy link
Collaborator

No description provided.

@kaushikcfd kaushikcfd force-pushed the do_not_allow_mutable_behavior branch from 8616711 to b7f0d1c Compare May 3, 2022 23:15
@kaushikcfd kaushikcfd requested a review from inducer May 3, 2022 23:55
@kaushikcfd
Copy link
Collaborator Author

/cc @isuruf (git-blame shows you had added the earlier version as a perf. improvement).
This patch increases a traversal over the expression but doesn't call the constructor. Do you foresee any issues with this?

Comment on lines +1446 to +1447
new_expression = cseam(insn.expression, frozenset())
if contains_cse(insn.expression):
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this condition could just become if new_expression is not insn.expression, with no need for another traversal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think IdentityMapper is generous about returning identical expression objects.

Copy link
Collaborator

@isuruf isuruf May 4, 2022

Choose a reason for hiding this comment

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

It should be though. There are 2 options I think,

  1. check for identical obejcts as @inducer said and make sure identity mapper return identical objects.
  2. instead of passing a found object in the call to the mapper, store in the mapper as an attribute and query it after traversal.

Copy link
Owner

Choose a reason for hiding this comment

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

I think I strongly prefer option 1.

Copy link
Collaborator Author

@kaushikcfd kaushikcfd May 4, 2022

Choose a reason for hiding this comment

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

I don't think IdentityMapper is generous about returning identical expression objects.

Turns out I was wrong, it was already quite mature in preserving objects whenever possible.

Yep, went with option 1.

Thanks for the suggestions!

Copy link
Owner

Choose a reason for hiding this comment

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

it was already quite mature in preserving objects whenever possible.

I seem to recall @isuruf did a lot of work towards that goal, so I had a feeling it was worth a shot. Good to hear!

@kaushikcfd kaushikcfd force-pushed the do_not_allow_mutable_behavior branch from b7f0d1c to 6f1c948 Compare May 4, 2022 04:36
@inducer inducer enabled auto-merge (rebase) May 4, 2022 04:47
@inducer
Copy link
Owner

inducer commented May 4, 2022

LGTM, thanks!

@inducer inducer disabled auto-merge May 4, 2022 05:12
@kaushikcfd kaushikcfd force-pushed the do_not_allow_mutable_behavior branch from 6f1c948 to e1cefa2 Compare May 4, 2022 05:20
@inducer inducer enabled auto-merge (rebase) May 4, 2022 05:21
@inducer inducer force-pushed the do_not_allow_mutable_behavior branch from e1cefa2 to 35a7324 Compare May 4, 2022 05:34
@inducer inducer merged commit befa5cb into main May 4, 2022
@inducer inducer deleted the do_not_allow_mutable_behavior branch May 4, 2022 06:21
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