[mlir] Fix getAPInt for non-power-of-2 widths and constant-fold ratio trunc/sext/zext#144
Open
PavelKopyl wants to merge 1 commit into
Open
[mlir] Fix getAPInt for non-power-of-2 widths and constant-fold ratio trunc/sext/zext#144PavelKopyl wants to merge 1 commit into
PavelKopyl wants to merge 1 commit into
Conversation
…nal binary expressions
There was a problem hiding this comment.
Pull request overview
This PR improves MLIR codegen’s handling of integer constants by fixing getAPInt for non-power-of-2 bit widths and by constant-folding rational-number binary operations into immediate integer constants, reducing reliance on later folding and eliminating several previously failing semantic tests.
Changes:
- Fix
getAPInt(u256, numBits)to support arbitrary integer widths by parsing into 256 bits and truncating as needed. - Add constant-folding for binary operations whose expression type is a rational number, emitting a
sol.constantdirectly. - Add new lit + semantic tests for non-power-of-2 integer widths and rational folding; update the MLIR semtest failure allowlist to reflect newly passing tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/mlirSemtestFailures.txt | Removes several tests from the known-fail list (now expected to pass). |
| test/lit/mlirCodegen/int-const-fold.sol | Adds FileCheck coverage for init-MLIR constant folding of non-power-of-2 integer widths. |
| test/lit/mlirCodegen/EVM/int-const-fold.sol | Adds FileCheck coverage for EVM-target std-MLIR constant folding of the same cases. |
| test/libsolidity/semanticTests/mlir/int-const-fold.sol | Adds semantic test expectations for MLIR compile path. |
| libsolidity/codegen/mlir/Util.h | Updates getAPInt to correctly handle arbitrary widths via parse+truncate. |
| libsolidity/codegen/mlir/SolidityToMLIR.cpp | Adds rational-number binary-op constant folding in MLIR lowering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1254
to
+1260
| if (binOp.annotation().commonType->category() == | ||
| Type::Category::RationalNumber) { | ||
| auto intTy = mlir::cast<mlir::IntegerType>(argTy); | ||
| u256 val = binOp.annotation().commonType->literalValue(nullptr); | ||
| return b.create<mlir::sol::ConstantOp>( | ||
| loc, b.getIntegerAttr(intTy, getAPInt(val, intTy.getWidth()))); | ||
| } |
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.
No description provided.