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

Enable egraph-based optimization by default. #5587

Merged
merged 4 commits into from
Jan 19, 2023

Conversation

cfallin
Copy link
Member

@cfallin cfallin commented Jan 18, 2023

This PR follows up on #5382 and #5391, which rebuilt the egraph-based optimization framework to be more performant, by enabling it by default.

Based on performance results in #5382 (my measurements on SpiderMonkey and bjorn3's independent confirmation with cg_clif), it seems that this is reasonable to enable. Now that we have been fuzzing compiler configurations with egraph opts (#5388) for 6 weeks, having fixed a few fuzzbugs that came up (#5409, #5420, #5438) and subsequently received no further reports from OSS-Fuzz, I believe it is stable enough to rely on.

This PR enables use_egraphs, and also normalizes its meaning: previously it forced optimization (it basically meant "turn on the egraph optimization machinery"), now it runs egraph opts if the opt level indicates (it means "use egraphs to optimize if we are going to optimize"). The conditionals in the top-level pass driver are a little subtle, but will get simpler once we can remove the non-egraph path (which we plan to do eventually!).

Fixes #5181

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:meta Everything related to the meta-language. labels Jan 18, 2023
@cfallin
Copy link
Member Author

cfallin commented Jan 18, 2023

Hmm, some issues caused by my reimplementation of #5534 (GVN + idempotency) for egraphs; switching this to draft for now.

@cfallin cfallin marked this pull request as draft January 18, 2023 03:08
@cfallin
Copy link
Member Author

cfallin commented Jan 18, 2023

Pushed updates, but I'll factor out the idempotent-GVN updates for egraphs into a separate PR tomorrow then rebase this.

Also update the pass-driving logic to run egraph optimization only when
optimization is enabled. Previously `use_egraphs` acted as an overall
enable-switch that drove egraph-based optimization, regardless of
`opt_level`.
@cfallin cfallin marked this pull request as ready for review January 19, 2023 19:59
@cfallin
Copy link
Member Author

cfallin commented Jan 19, 2023

Rebased on the idempotency fix; should be ready to review now!

@alexcrichton
Copy link
Member

I think one final location to touch doc-wise would be here too perhaps?

@cfallin
Copy link
Member Author

cfallin commented Jan 19, 2023

I think one final location to touch doc-wise would be here too perhaps?

Ah, yes, updated!

@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime labels Jan 19, 2023
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "cranelift", "cranelift:area:machinst", "cranelift:meta", "wasmtime:api", "wasmtime:config"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@github-actions
Copy link

github-actions bot commented Jan 19, 2023

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

  • If you added a new Config method, you wrote extensive documentation for
    it.

    Our documentation should be of the following form:

    Short, simple summary sentence.
    
    More details. These details can be multiple paragraphs. There should be
    information about not just the method, but its parameters and results as
    well.
    
    Is this method fallible? If so, when can it return an error?
    
    Can this method panic? If so, when does it panic?
    
    # Example
    
    Optional example here.
    
  • If you added a new Config method, or modified an existing one, you
    ensured that this configuration is exercised by the fuzz targets.

    For example, if you expose a new strategy for allocating the next instance
    slot inside the pooling allocator, you should ensure that at least one of our
    fuzz targets exercises that new strategy.

    Often, all that is required of you is to ensure that there is a knob for this
    configuration option in wasmtime_fuzzing::Config (or one
    of its nested structs).

    Rarely, this may require authoring a new fuzz target to specifically test this
    configuration. See our docs on fuzzing for more details.

  • If you are enabling a configuration option by default, make sure that it
    has been fuzzed for at least two weeks before turning it on by default.


To modify this label's message, edit the .github/label-messager/wasmtime-config.md file.

To add new label messages or remove existing label messages, edit the
.github/label-messager.json configuration file.

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

🎉

@cfallin
Copy link
Member Author

cfallin commented Jan 19, 2023

In an extremely amusing twist, adding the deprecation warning for the cranelift_use_egraphs config option makes our fuzz target build throw a warning (because it can configure Cranelift not to use egraphs), and this makes our no-warnings build fail. I'm going to just remove the deprecation warning for now to get this in and am happy to talk about ways to warn while still using it internally in a followup PR.

@cfallin cfallin merged commit 1faff8c into bytecodealliance:main Jan 19, 2023
@cfallin cfallin deleted the enable-egraphs branch January 19, 2023 23:46
@fitzgen
Copy link
Member

fitzgen commented Jan 20, 2023

In an extremely amusing twist, adding the deprecation warning for the cranelift_use_egraphs config option makes our fuzz target build throw a warning (because it can configure Cranelift not to use egraphs), and this makes our no-warnings build fail. I'm going to just remove the deprecation warning for now to get this in and am happy to talk about ways to warn while still using it internally in a followup PR.

You can #[allow(deprecated)] on the specific function that does the deprecated call in the fuzzing infra.

cfallin added a commit to cfallin/wasmtime that referenced this pull request Jan 20, 2023
After bytecodealliance#5587, this is on by default. We are retaining the traditional
(no-egraphs) path for now, selected by setting this option to `false`,
but we eventually plan to delete it assuming that we don't find serious
regressions or issues. This PR adds a deprecation notice to the option.
cfallin added a commit that referenced this pull request Jan 20, 2023
After #5587, this is on by default. We are retaining the traditional
(no-egraphs) path for now, selected by setting this option to `false`,
but we eventually plan to delete it assuming that we don't find serious
regressions or issues. This PR adds a deprecation notice to the option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cranelift: use egraphs by default
3 participants