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

[InferReadWrite] Add heuristic to infer unmasked memory #6790

Merged
merged 4 commits into from
Mar 14, 2024

Conversation

prithayan
Copy link
Contributor

This PR updates the heuristic to infer an unmasked memory.
If all the bits of a masked memory are exactly the same, then it can be replaced with an unmasked memory.
This is an attempt to fix a use case, in which firtool introduces masked memory for an aggregate data type when the user expected an unmasked one.

// If we can infer that all the bits of the mask are always assigned
// the same value, then the memory is unmasked.
if (auto maskVal = getConnectSrc(sf)) {
SmallVector<Value> bits;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's reasonable to use Value to represent bit precise states. I think llvm::KnownBits would be right better fit here. You may want to refer the similar analysis for comb

/// constant" always returns zeros for the zero bits in a constant.
. Also note that it will cause compile time regression if we don't set a recursion depth limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @uenoku , the analysis is very similar, but seems like its only trying to figure out the 1s and 0s in the bits.
But in this PR, the analysis is different.

  1. In general the mask value is going to be constructed by concat of few 1 bit values, which may not be constants.
  2. If the same Value is used to mask each field of an aggregate memory data, then each bit of the mask can be traced back to that Value.
  3. So, this unmasked inference analysis is only trying to follow the dataflow into each of the bits of an Value to a source Value and then check if the source value is same for each bit.
    I agree about the recursion depth, I will make this an iterative algorithm.

@prithayan prithayan marked this pull request as ready for review March 12, 2024 21:34
@prithayan
Copy link
Contributor Author

@seldridge , @debs-sifive This PR updates the heuristic to infer an unmasked memory, ready for a review.

Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

I'm not familiar here either but I think this change seems reasonable.

@prithayan prithayan merged commit a25a583 into main Mar 14, 2024
4 checks passed
@prithayan prithayan deleted the dev/pbarua/infer-unmasked branch March 14, 2024 20:14
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