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 singlepass codegen regression #2787

Merged
merged 8 commits into from Feb 14, 2022
Merged

Conversation

ptitSeb
Copy link
Contributor

@ptitSeb ptitSeb commented Feb 11, 2022

Description

Issue was with the conversion Hash -> vec of the used GPR and SIMD registers before mass Push/Pop. Because a register might be allocated/deallocated in between, the order of the resulting vector might change.
The fix use a simple sort on the vector before push/pop elements, to be sure the order is deterministic.
The PR also contains a few ARM64 machine change, so the test can be run also on Aarch64 Linux & macOS (tested to be working too).

Fixes #2782

@ptitSeb ptitSeb requested review from Amanieu and removed request for syrusakbary February 11, 2022 09:46
@syrusakbary
Copy link
Member

In some tests blockchains were having a lot of arguments in the functions.
In this case I think sorting might become expensive. Rather than that, can we just use a structure that allows for deterministic pop/push without sorting?

@ptitSeb
Copy link
Contributor Author

ptitSeb commented Feb 11, 2022

In some tests blockchains were having a lot of arguments in the functions. In this case I think sorting might become expensive. Rather than that, can we just use a structure that allows for deterministic pop/push without sorting?

The vector only have a handfull of value: less than 10. I don't think it's changes much. But if there is a better structure, why not (but egain, it's a very small set)
note: The vector store used register, not function call aguments.

@syrusakbary
Copy link
Member

Perhaps we can use IndexSet for determinism? (other ideas/crates that you know @Amanieu ?)

https://docs.rs/indexmap/1.6.1/indexmap/set/struct.IndexSet.html

@Amanieu
Copy link
Contributor

Amanieu commented Feb 11, 2022

Since there are never going to be more than 32 elements in the set, just use a bit set. OR to set, AND to clear, trailing_zeros to find an element. You can find an implementation of this here: https://github.com/rust-lang/hashbrown/blob/master/src/raw/bitmask.rs

fn push_used_gpr(&mut self) -> usize {
let mut used_gprs = self.get_used_gprs();
used_gprs.sort();
fn push_used_gpr(&mut self, used_gprs: &Vec<GPR>) -> usize {
for r in used_gprs.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

HashSet still has a randomized iteration order so this makes the codegen of singlepass non-deterministic (but still correct).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but do we need to generate the same code on each run?

Copy link
Contributor

Choose a reason for hiding this comment

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

We do want to have deterministic reproducible builds for a given input. See #2173.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I'll remove the hashmaps

@ptitSeb
Copy link
Contributor Author

ptitSeb commented Feb 11, 2022

bors

@ptitSeb
Copy link
Contributor Author

ptitSeb commented Feb 11, 2022

bors try

bors bot added a commit that referenced this pull request Feb 11, 2022
@bors
Copy link
Contributor

bors bot commented Feb 11, 2022

try

Build failed:

@syrusakbary
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Feb 12, 2022
@bors
Copy link
Contributor

bors bot commented Feb 12, 2022

@ptitSeb
Copy link
Contributor Author

ptitSeb commented Feb 14, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 14, 2022

@bors bors bot merged commit 2b396e0 into master Feb 14, 2022
@bors bors bot deleted the fix_singlepass_codegen_regression branch February 14, 2022 19:37
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.

OOB table access with singlepass backend
3 participants