Parse ModArith constants as modulus's bit-width#3126
Merged
Conversation
Collaborator
|
Wow, this led me down a bit of rabbit hole. https://github.com/llvm/llvm-project/pull/205947/changes should tighten the bit width upstream, but I still think this code should be defensive and so I will review it now. |
j2kun
approved these changes
Jun 26, 2026
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.
This simple test fails on both lines, for different reasons.
For the first line, 12535824225335233 is a 53-bit constant, but it triggers an error in the ConstantOp verifier that the constant is too big to fit in the modulus. For some reason, MLIR's int parser makes it a 68-bit value.
For the second line, existing code in the ConstantOp parser sets 0 to 4 bits, but this is incompatible with a non-zero constant (of any size other than 4 bits).
This PR fixes these issues by forcing all ModArith constants to have the same bit-width as the modulus (after checking that it in fact fits).
Assisted by AI.