Fix validating wasm stores of boolean vector results#3202
Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom Aug 18, 2021
Merged
Fix validating wasm stores of boolean vector results#3202alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton merged 1 commit intobytecodealliance:mainfrom
Conversation
Previously cranelift's wasm code generator would emit a raw `store` instruction for all wasm types, regardless of what the cranelift operand type was. Cranelift's `store` instruction, however, isn't valid for boolean vector types. This commit fixes this issue by inserting a bitcast specifically for the store instruction if a boolean vector type is being stored, continuing to avoid the bitcast for all other vector types. Closes bytecodealliance#3099
bjorn3
reviewed
Aug 18, 2021
| // bitcast them to a vector type which is compatible with the store | ||
| // instruction. | ||
| if val_ty.is_vector() && val_ty.lane_type().is_bool() { | ||
| val = builder.ins().raw_bitcast(I8X16, val); |
Contributor
There was a problem hiding this comment.
Should we instead define that boolean vectors can be stored using store directly and are stored as all-zero or all-one lanes?
Member
There was a problem hiding this comment.
That is a good approach but I don't mind what @alexcrichton tried here because:
- vector translation already involves a lot of bitcasting so this doesn't make the problem worse; if we want to solve the bitcasting we should just solve all of it and close Too many raw_bitcasts in SIMD code #1147
- changing
loadandstoreto allow boolean vectors but not boolean scalars seems like it might cause errors somewhere; this fix would immediately fix a fuzz bug - I wouldn't mind settling the general issue about
loads andstores with booleans once for all: I've seen mention recently of setting a memory representation for boolean scalars... If we settle it once for all (do we have an issue for this?) and document it then it might make sense to avoid the bitcast (if that's what is decided).
Member
There was a problem hiding this comment.
I just created #3205 for this. Agreed that for now, the immediate fuzzbug fix is fine.
Member
Author
There was a problem hiding this comment.
Ok I'm gonna go ahead and merge this fix for now and defer to #3205 for future updates.
Member
Author
|
@abrown oh I don't want to step on any toes, I was mostly just curious myself to see how involved this might be (turns out not much) |
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.
Previously cranelift's wasm code generator would emit a raw
storeinstruction for all wasm types, regardless of what the cranelift operand
type was. Cranelift's
storeinstruction, however, isn't valid forboolean vector types. This commit fixes this issue by inserting a
bitcast specifically for the store instruction if a boolean vector type
is being stored, continuing to avoid the bitcast for all other vector types.
Closes #3099