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 struct RMW ops in OptimizeInstructions #7225

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update comments
  • Loading branch information
tlively committed Jan 17, 2025
commit cd23371360318416aad28b4fdd3111dbe0dad3e1
15 changes: 9 additions & 6 deletions src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,12 +1874,12 @@ struct OptimizeInstructions

Builder builder(*getModule());

// Even when the access to shared memory, we can optimize out the modify and
// write parts if we know that the modified value is the same as the
// original value. This is valid because reads from writes that don't change
// the in-memory value can be considered to be reads from the previous write
// to the same location instead. That means there is no read that
// necessarily synchronizes with the write.
// Even when the RMW access is to shared memory, we can optimize out the
// modify and write parts if we know that the modified value is the same as
// the original value. This is valid because reads from writes that don't
// change the in-memory value can be considered to be reads from the
// previous write to the same location instead. That means there is no read
// that necessarily synchronizes with the write.
auto* value =
Properties::getFallthrough(curr->value, getPassOptions(), *getModule());
if (Properties::isSingleConstantExpression(value)) {
Expand Down Expand Up @@ -1918,6 +1918,9 @@ struct OptimizeInstructions
// thread can observe an intermediate state in the unshared memory. This
// initially increases code size, but the more basic operations may be
// more optimizable than the original RMW.
Copy link
Member

Choose a reason for hiding this comment

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

How likely are we to succeed? I am somewhat worried that generally the size increase here will stick around, and might also be slower.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure! We can experiment with it once we have real test cases. I figure it will be easier to experimentally disable this optimization than it would be to write the optimization just for an experiment, though. I could imagine in the long run we would want to do this only when optimizing for speed over size.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, sounds good. Perhaps add a TODO for that?

// TODO: Experiment to determine whether this is worthwhile on real code.
// Maybe we should do this optimization only when optimizing for speed over
// size.
auto ref = builder.addVar(getFunction(), curr->ref->type);
auto val = builder.addVar(getFunction(), curr->type);
auto result = builder.addVar(getFunction(), curr->type);
Expand Down
Loading