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

Fix ordering of inserted common subexpressions #403

Merged
merged 8 commits into from
Apr 4, 2024
Merged

Conversation

rihi
Copy link
Collaborator

@rihi rihi commented Mar 20, 2024

The common subexpression elimination stage currently has a bug, where if multiple eliminated subexpressions depend on each other are inserted in the wrong order into a basic block.

This can result in transformation like this:

print("%d", a * 2);
print("%d", a * 2 + 5);
print("%d", a * 2 + 5);

int c0 = c1 + 5;
int c1 = a * 2;
print("%d", c0);
print("%d", c0);
print("%d", c1);

This is caused by us caching the index of each instruction in the CfgInstruction class and not updating it after inserting new definitions. This PR simply changes this so that the index is always calculated instead of being cached. While theoretically this has worse performance, the extend tests runtime only increased from 10:42 to 11:13 on my machine.

@rihi rihi self-assigned this Mar 20, 2024
@ebehner ebehner merged commit 87fe3e3 into main Apr 4, 2024
1 check passed
@ebehner ebehner deleted the fix-cse-ordering branch April 4, 2024 08:17
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.

2 participants