Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the Solidity→MLIR lowering to cover additional expression forms used by the MLIR codegen backend, adding support for logical not (!), bitwise not (~), and conditional (ternary) expressions (c ? a : b), along with updated lit/semantic tests to validate the new lowering.
Changes:
- Add lowering for unary logical not and bitwise not in
SolidityToMLIRPass::genExpr(UnaryOperation). - Add lowering for conditional (ternary) expressions via
scf.ifyielding results, and wire it into expression dispatch. - Update MLIR codegen lit tests and semantic tests to exercise
!,~, and ternary expressions.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/lit/mlirCodegen/logical.sol | Extend logical test to include !a and update FileCheck output. |
| test/lit/mlirCodegen/if.sol | Add ternary function and expected MLIR (scf.if) checks. |
| test/lit/mlirCodegen/arith.sol | Add ~a usage and update expected IR patterns. |
| test/lit/mlirCodegen/EVM/logical.sol | Mirror logical-not coverage for the EVM pipeline checks. |
| test/lit/mlirCodegen/EVM/literals.sol | Update location/IR expectations after regen. |
| test/lit/mlirCodegen/EVM/if.sol | Mirror ternary coverage for the EVM pipeline checks. |
| test/libsolidity/semanticTests/mlir/logical.sol | Add semantic test coverage for ! on bool. |
| test/libsolidity/semanticTests/mlir/cf.sol | Add semantic test coverage for ternary expression. |
| test/libsolidity/semanticTests/mlir/arith.sol | Add semantic test coverage for ~ on uint. |
| libsolidity/codegen/mlir/SolidityToMLIR.cpp | Implement new lowering for !, ~, and ternary expressions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
3161354 to
0f9626c
Compare
b4c09cf to
e549422
Compare
vladimirradosavljevic
approved these changes
Mar 19, 2026
Contributor
vladimirradosavljevic
left a comment
There was a problem hiding this comment.
LGTM.
Could you please add these two lit tests:
function tern_tuple(bool c, uint a, uint b, uint x, uint y) public pure returns (uint, uint) {
return c ? (a, b) : (x, y);
}
function tern_const(bool c) public pure returns (uint) {
return c ? 1 : 2;
}
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.
Requires matter-labs/solx-llvm#33