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

Disable sign extension in SignExtLowering.cpp #5676

Merged
merged 2 commits into from
Apr 19, 2023
Merged

Conversation

tlively
Copy link
Member

@tlively tlively commented Apr 19, 2023

The sign extension lowering pass would previously lower away the sign extension
instructions, but it wouldn't disable the sign extension feature, so follow-on
passes such as optimize-instructions could reintroduce sign extension
instructions.

Fix the pass to disable the sign extension feature to prevent sign extension
instructions from being reintroduced later.

The sign extension lowering pass would previously lower away the sign extension
instructions, but it wouldn't disable the sign extension feature, so follow-on
passes such as optimize-instructions could reintroduce sign extension
instructions.

Fix the pass to disable the sign extension feature to prevent sign extension
instructions from being reintroduced later.
@tlively tlively requested review from kripken and sbc100 April 19, 2023 15:10
@tlively
Copy link
Member Author

tlively commented Apr 19, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@@ -68,6 +68,14 @@ struct SignExtLowering : public WalkerPass<PostWalker<SignExtLowering>> {
}
}
}

void run(Module* module) override {
if (!module->features.has(FeatureSet::SignExt)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible the module could contain sign ext instructions but this feature not be enabled? (I guess in that case it would not validate?)

Copy link
Member

Choose a reason for hiding this comment

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

I also wonder why the test we have in emscripten for this was passing.. investigating.

Copy link
Member

Choose a reason for hiding this comment

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

The emscripten test merely checks that --signext-lowering is part of the wasm-opt command line .. I didn't both to actually decompile the module to verify binaryen was actually doing the right thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it possible the module could contain sign ext instructions but this feature not be enabled? (I guess in that case it would not validate?)

Right, in this case the module would not validate and Binaryen would produce an error.

@PrintessEditor
Copy link

Wow! Thank you very much for this fast fix! :)

@tlively tlively enabled auto-merge (squash) April 19, 2023 15:26
@kripken
Copy link
Member

kripken commented Apr 19, 2023

Is there some context for this? I'm confused as to how it occurs.

Depending on the context, perhaps it makes sense to have a new pass to remove the feature? I'm not sure we always want to do the two operations together.

@kripken
Copy link
Member

kripken commented Apr 19, 2023

If we do want to bundle the operations, it might also be good to document that in the pass description perhaps.

@tlively
Copy link
Member Author

tlively commented Apr 19, 2023

Context is emscripten-core/emscripten#19121. Basically this pass didn't do what it was supposed to when run before other passes like optimize-instructions.

When would we ever want to lower away the sign extension instructions but allow them to be reintroduced later?

@tlively tlively disabled auto-merge April 19, 2023 15:35
@tlively
Copy link
Member Author

tlively commented Apr 19, 2023

I've now updated the pass description.

@kripken
Copy link
Member

kripken commented Apr 19, 2023

I can imagine testing/fuzzing situations where we might want to lower certain instructions but maybe generate more of them later (could be more efficient than otherwise). In particular, the fuzzer assumes features stay the same throughout the pipeline, though I don't know if there is any danger to that assumption changing. And I agree that the obvious use case is to lower and disable the feature.

Looks like in existing lowering passes we do that in MultiMemory, for the reason of avoiding the feature appearing in the features section later, but we don't do it for Memory64. We should probably make a general decision and be consistent about it. I don't have strong feelings so we could separately adjust Memory64 as well to disable the feature.

@tlively
Copy link
Member Author

tlively commented Apr 19, 2023

I agree we should be consistent. I can update the Memory64 lowering pass as well.

@tlively
Copy link
Member Author

tlively commented Apr 19, 2023

@tlively queued this pull request to merge with Graphite.

@tlively tlively merged commit 1e2e89b into main Apr 19, 2023
@tlively tlively deleted the signext-lowering-feature branch April 19, 2023 23:56
@tlively
Copy link
Member Author

tlively commented Apr 19, 2023

@tlively queued this pull request to merge with Graphite.

radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
* Disable sign extension in SignExtLowering.cpp

The sign extension lowering pass would previously lower away the sign extension
instructions, but it wouldn't disable the sign extension feature, so follow-on
passes such as optimize-instructions could reintroduce sign extension
instructions.

Fix the pass to disable the sign extension feature to prevent sign extension
instructions from being reintroduced later.

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

Successfully merging this pull request may close these issues.

4 participants