Skip to content

[mlir] Lower logical not, bitwise not and ternary expressions#75

Merged
abinavpp merged 1 commit intomainfrom
app-expr
Mar 19, 2026
Merged

[mlir] Lower logical not, bitwise not and ternary expressions#75
abinavpp merged 1 commit intomainfrom
app-expr

Conversation

@abinavpp
Copy link
Copy Markdown
Contributor

@abinavpp abinavpp commented Mar 10, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.if yielding 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.

@abinavpp abinavpp force-pushed the app-expr branch 2 times, most recently from 3161354 to 0f9626c Compare March 10, 2026 11:40
@abinavpp abinavpp force-pushed the app-expr branch 2 times, most recently from b4c09cf to e549422 Compare March 10, 2026 21:45
Copy link
Copy Markdown
Contributor

@vladimirradosavljevic vladimirradosavljevic left a comment

Choose a reason for hiding this comment

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

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;
  }

Copy link
Copy Markdown
Contributor

@PavelKopyl PavelKopyl left a comment

Choose a reason for hiding this comment

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

LGTM.

@abinavpp abinavpp merged commit 7c16530 into main Mar 19, 2026
2 checks passed
@abinavpp abinavpp deleted the app-expr branch March 19, 2026 14:28
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.

4 participants