Skip to content

fix: do binary stack scheduling optimizations only for the binary ops (implementing BinaryOp trait) #602

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

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

greenhat
Copy link
Contributor

@greenhat greenhat commented Jul 16, 2025

Close #600

This PR:

  • checks that the op is binary if it implements BinaryOp at HirLowering::schedule_operands();
  • simplifies the test_arg_order test and moves it to the misc module;

Base automatically changed from greenhat/i573-hmerge to next July 16, 2025 07:08
@greenhat greenhat marked this pull request as ready for review July 16, 2025 13:40
@greenhat greenhat requested a review from bitwalker July 16, 2025 13:51
@bitwalker
Copy link
Contributor

Copying my reply from Slack here for visibility:

It's not actually correct though. The conclusion it drew about the original code that swaps the operand order for BinaryOp impls completely ignores the comment that explains the reason why that swap is performed only for BinaryOp impls and not any operation with only two operands.

The later "binary" operand handling has nothing to do with binary operations, but operations where there happen to be only two operands, so the scheduling of those operands can be done very efficiently (i.e. without going through the operand scheduler).

So this change may have caused the test to go green, but for the wrong reason - i.e. it didn't fix the actual bug.

It looks to me like the actual bug here is in the manual implementation of operand scheduling for two operands. The fact that hir.exec doesn't implement BinaryOp is irrelevant - that's not why we're manually handling the binary operand case like that; we're doing so to avoid going through the more expensive operand stack solver which is not optimized for such trivial cases.

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.

Swapped and "frozen" function arguments
2 participants