[10.0.0]: x64: Remove recursion in to_amode helper #6997
Merged
alexcrichton merged 2 commits intoSep 11, 2023
Merged
Conversation
This commit removes the recursion present in the x64 backend's `to_amode` and `to_amode_add` helpers. The recursion is currently unbounded and controlled by user input meaning it's not too hard to craft user input which triggers stack overflow in the host. By removing recursion there's no need to worry about this since the stack depth will never be hit. The main concern with removing recursion is that code quality may not be quite as good any more. The purpose of the recursion here is to "hunt for constants" and update the immediate `Offset32`, and now without recursion only at most one constant is found and folded instead of an arbitrary number of constants as before. This should continue to produce the same code as before so long as optimizations are enabled, but without optimizations this will produce worse code than before. Note with a hypothetical mid-end optimization that does this constant folding for us the rules here could be further simplified to purely consider the shape of the input `Value` to amode computation without considering constants at all.
cfallin
approved these changes
Sep 11, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a backport of #6968 to the 10.0.0 release branch of Wasmtime. Note that AArch64 is not backported as its recursion is not present on this branch.