[Cranelift] add type-aware imm64 constant folding operations#12826
Draft
bongjunj wants to merge 3 commits intobytecodealliance:mainfrom
Draft
[Cranelift] add type-aware imm64 constant folding operations#12826bongjunj wants to merge 3 commits intobytecodealliance:mainfrom
bongjunj wants to merge 3 commits intobytecodealliance:mainfrom
Conversation
a10f67c to
2722fd3
Compare
Member
This makes sense to me. I wonder if we can or should generate and/or enumerate these |
Contributor
Author
|
@fitzgen I think we should implement |
Member
|
Makes sense to me 👍 |
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 followup of #12764
I'm adding rules that perform constant foldings. However, currently, Cranelift mainly uses
u64/i64_*operations that are meta-generated by https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/codegen/meta/src/gen_isle.rsHowever, those u64/i64 operations are not aware bitwidth specified by type specifier (usually captured by
ty) and signedness of a constant. Thus one cannot easily handle overflow, shift/rotation crossing bitwidth boundaries. Therefore, one has to carefully reason about the bitwidth boundary conditions, but can occasionally fail to write a correct rule. On the other hand,imm64-based constant operations perform computations considering those bitwidth-related semantics. This advantage is observed in the current implementation ofimm64_sdivas it requires the precise view of Cranelift constants to correctly perform "signedness"-aware computation. In addition, usingimm64-based constant operations, the implementation (writingsimplifyrules and more) is more straightforward and convenient since the primary representation of constants in Cranelift isimm64. (u64/i64are Rust representation of constant literals).For these reasons, I'm proposing that we should prioritize
imm64-based approach rather thanuN/iNone to make it easier to develop safe constant folding operations. This PR prepares suchimm64operations for further inclusion of various constant expressions.