[HandshakeOptimizeBitwidths] Fix forward logic for shrui#812
Merged
Conversation
The previous logic for `shrui` for the forward pass did not properly handle sign-extension for `shrui`, resulting in sign-extension of the result often being performed in cases where the shifting should fill in 0 bits. Furthermore, if the constant was larger than the minimal input bitwidth, integer overflow would occur in the implementation causing crashes. This PR fixes that issue by splitting the forward pass for `shrui` out of the common shift pattern and taking both zero-extension and sign-extension of the input into account. I believe the logic of `shrui` and `shrsi` to likely be different enough to require different forwarding patterns. The older generic `ArithShift` pattern remains in use for the backward pass. Fixes #792
f9fdbee to
e3a5d9b
Compare
Jiahui17
reviewed
Mar 26, 2026
Jiahui17
approved these changes
Mar 27, 2026
zero9178
added a commit
that referenced
this pull request
Mar 29, 2026
The previous logic for `shrsi` for the forward pass often crashed in edge cases such as the shift amount was larger than the bitwidth. This PR rewrites the forward logic for `shrsi` into a dedicated pattern. In the case of the input of `shrsi` being zero-extended we just optimize it to a `shrui` and reuse the existing optimization logic there. Fixes #792 Depends on #812
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous logic for
shruifor the forward pass did not properly handle sign-extension forshrui, resulting in sign-extension of the result often being performed in cases where the shifting should fill in 0 bits. Furthermore, if the constant was larger than the minimal input bitwidth, integer overflow would occur in the implementation causing crashes.This PR fixes that issue by splitting the forward pass for
shruiout of the common shift pattern and taking both zero-extension and sign-extension of the input into account. I believe the logic ofshruiandshrsito likely be different enough to require different forwarding patterns. The older genericArithShiftpattern remains in use for the backward pass.Fixes #792
Depends on #802 to function