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

Avoid generating implicit jumps in if statements when they unconditionally return/jump #115

Open
Bananattack opened this issue Feb 8, 2021 · 0 comments

Comments

@Bananattack
Copy link
Collaborator

Currently, there is a small issue of suboptimal code generation when an if statement with an else clause contains a return statement in the if body. This appears to be either a regression, or an oversight, as this used to work in the legacy D versions of Wiz.

The if statement code generation should check if the last statement of the if statement body is an unconditional branch (goto, return, continue, break, etc. without a condition). If so, the if statement should omit any implicit branch at the end of the body:

In other words,

if carry {
    return;
} else {
  // do something
}

should become

    bcc @else
@if
    ret
@else
    ; do something
@end

rather than

    bcc @else
@if
    ret
    jmp @end
@else
    ; do something
@end

This will also fix the 6502_return_on_if_else_path.wiz test included in the block tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant