Skip to content

Disable sign extension in SignExtLowering.cpp - #5676

Merged
tlively merged 2 commits into
mainfrom
signext-lowering-feature
Apr 19, 2023
Merged

Disable sign extension in SignExtLowering.cpp#5676
tlively merged 2 commits into
mainfrom
signext-lowering-feature

Conversation

@tlively

@tlively tlively commented Apr 19, 2023

Copy link
Copy Markdown
Member

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

tlively commented Apr 19, 2023

Copy link
Copy Markdown
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

}

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

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

kripken commented Apr 19, 2023

Copy link
Copy Markdown
Member

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

kripken commented Apr 19, 2023

Copy link
Copy Markdown
Member

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

@tlively

tlively commented Apr 19, 2023

Copy link
Copy Markdown
Member Author

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

tlively commented Apr 19, 2023

Copy link
Copy Markdown
Member Author

I've now updated the pass description.

@kripken

kripken commented Apr 19, 2023

Copy link
Copy Markdown
Member

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

tlively commented Apr 19, 2023

Copy link
Copy Markdown
Member Author

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

@tlively

tlively commented Apr 19, 2023

Copy link
Copy Markdown
Member Author

@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

tlively commented Apr 19, 2023

Copy link
Copy Markdown
Member Author

@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