Skip to content

IRC: logic error in the second call to rewrite#774

Merged
xclerc merged 3 commits intomainfrom
irc-bugfix-rewrite-precond
Sep 6, 2022
Merged

IRC: logic error in the second call to rewrite#774
xclerc merged 3 commits intomainfrom
irc-bugfix-rewrite-precond

Conversation

@xclerc
Copy link
Copy Markdown
Contributor

@xclerc xclerc commented Aug 18, 2022

The rewrite function expects the registers it gets to
be spilled (technically to have their irc_work_list
field set to Spilled). Before this pull request, it is
not the case with the second call to rewrite (the
one from run). I have not been able to produce
a miscompilation, but I think there is the potential
for one, in particular if the register ends up in the
list because because it is in res but not in arg.

@xclerc xclerc requested a review from gretay-js as a code owner August 18, 2022 15:11
@xclerc xclerc added bug Something isn't working cfg backend labels Aug 18, 2022
Copy link
Copy Markdown
Contributor

@gretay-js gretay-js left a comment

Choose a reason for hiding this comment

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

Cfg_irc_state is maintaining an invariant of representation between Reg.irc_work_list and
state.spilled_nodes. It would be better to use State.add_spilled_nodes in run and then rely on rewrite to call State.clear_spilled_nodes.

Copy link
Copy Markdown
Contributor

@gretay-js gretay-js left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

If rewrite used State.get_spilled_nodes instead of taking the spilled_nodes as a parameter, we would have avoided the bug. Another improvement is to call State.add_spilled_nodes directly instead of constructing spilling_because_split and spilling_because_split_or_unused lists. Then, the code in main and run that checks the length of the list could perhaps be factored out. This refactoring can be done as a follow-up PR, and probably after PR#794.

@gretay-js gretay-js mentioned this pull request Sep 6, 2022
@xclerc
Copy link
Copy Markdown
Contributor Author

xclerc commented Sep 6, 2022

Discussed off-line, just for the record: hijacking
rewrite like that is inelegant at best , and eventually
the preprocessing phase and rewrite itself should
call another routine with the common functionality
(rewrite would then be called only by main, as it
should). I think overall it is worth waiting to see
exactly what the needs of the preprocessing phase
will be.

@xclerc xclerc merged commit a264eb3 into main Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working cfg

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants