Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MooreToCore] Add nested moore.conditional support #8125

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

AndreyVV-100
Copy link
Contributor

Hi! This code adds correct lowering for nested ternary operators like this:

module Mod(input a, input b, output logic [1:0] c);
always_comb
    c = a ? b ? 2'd0 : 2'd1 : 2'd2;
endmodule

Comment on lines +1349 to +1448
if (operation->hasTrait<OpTrait::HasRecursiveMemoryEffects>())
return WalkResult::advance();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice one!

Comment on lines 1010 to 1027
%5 = moore.conditional %4 : l1 -> l2 {
%6 = moore.read %b_1 : <l1>
%7 = moore.conditional %6 : l1 -> l2 {
moore.yield %2 : l2
} {
moore.yield %1 : l2
}
moore.yield %7 : l2
} {
moore.yield %0 : l2
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This test uses quite a few other supporting operations (module, nets, variables, procedure, blocking assigns) to test the conditional lowering. Would it be possible to move just the conditionals and the corresponding checks into a func.func, similar to @Conversions just below? It might be possible to even move it inside of @Conversions. That would make the test less brittle if any of the module and procedure lowerings change, which are unrelated to the conditionals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi! I simplified test and rebased branch. Could you check it?

@AndreyVV-100 AndreyVV-100 force-pushed the fix-moore-conditional branch from c7a54ae to ca52474 Compare February 3, 2025 10:08
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks for tackling this 👍

This code adds correct lowering for nested ternary operators like this:

```verilog
module Mod(input a, input b, output logic [1:0] c);
always_comb
    c = a ? b ? 2'd0 : 2'd1 : 2'd2;
endmodule
```
@AndreyVV-100 AndreyVV-100 force-pushed the fix-moore-conditional branch from ce42131 to 982e335 Compare February 4, 2025 09:47
@AndreyVV-100
Copy link
Contributor Author

If there are no remarks, could you merge it? I haven't commit access.

@fabianschuiki
Copy link
Contributor

Sure thing, thanks!

@fabianschuiki fabianschuiki merged commit a9d0048 into llvm:main Feb 4, 2025
5 checks passed
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.

2 participants