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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cranelift/codegen/meta/src/shared/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ pub(crate) fn define() -> SettingGroup {
"Enable egraph-based optimization.",
r#"
This enables an optimization phase that converts CLIF to an egraph (equivalence graph)
representation, performs various rewrites, and then converts it back. This can result in
better optimization, but is currently considered experimental.
representation, performs various rewrites, and then converts it back. This should result in
better optimization, but the traditional optimization pass structure is also still
available by setting this to `false`. The `false` setting will eventually be
deprecated and removed.
"#,
false,
true,
);

settings.add_bool(
Expand Down
16 changes: 9 additions & 7 deletions cranelift/codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,20 @@ impl Context {
self.compute_domtree();
self.eliminate_unreachable_code(isa)?;

if isa.flags().use_egraphs() || opt_level != OptLevel::None {
if opt_level != OptLevel::None {
self.dce(isa)?;
}

self.remove_constant_phis(isa)?;

if isa.flags().use_egraphs() {
self.egraph_pass()?;
} else if opt_level != OptLevel::None && isa.flags().enable_alias_analysis() {
for _ in 0..2 {
self.replace_redundant_loads()?;
self.simple_gvn(isa)?;
if opt_level != OptLevel::None {
if isa.flags().use_egraphs() {
self.egraph_pass()?;
} else if isa.flags().enable_alias_analysis() {
for _ in 0..2 {
self.replace_redundant_loads()?;
self.simple_gvn(isa)?;
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions cranelift/codegen/src/machinst/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use crate::machinst::{
ABIArg, ABIArgSlot, InputSourceInst, Lower, LowerBackend, RealReg, Reg, RelocDistance, Sig,
VCodeInst, Writable,
};
pub use crate::settings::TlsModel;
pub use crate::settings::{OptLevel, TlsModel};

pub type Unit = ();
pub type ValueSlice = (ValueList, usize);
Expand Down Expand Up @@ -131,7 +131,9 @@ macro_rules! isle_lower_prelude_methods {
// use. This lowers register pressure. (Only do this if we are
// not using egraph-based compilation; the egraph framework
// more efficiently rematerializes constants where needed.)
if !self.backend.flags().use_egraphs() {
if !(self.backend.flags().use_egraphs()
&& self.backend.flags().opt_level() != OptLevel::None)
{
let inputs = self.lower_ctx.get_value_as_source_or_const(val);
if inputs.constant.is_some() {
let insn = match inputs.inst {
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ probestack_strategy = "outline"
regalloc_checker = false
regalloc_verbose_logs = false
enable_alias_analysis = true
use_egraphs = false
use_egraphs = true
enable_verifier = true
is_pic = false
use_colocated_libcalls = false
Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/algebraic.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=none
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/alias_analysis.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=none
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/basic-gvn.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=none
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/cprop.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=none
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/i128-opts.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=speed_and_size
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/isplit.clif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test interpret
test run
set opt_level=speed_and_size
set opt_level=speed
set use_egraphs=true
set enable_llvm_abi_extensions=true
target x86_64
Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/issue-5405.clif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test interpret
test run
set opt_level=speed_and_size
set opt_level=speed
set use_egraphs=true
target aarch64

Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/egraph/issue-5437.clif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test compile
set opt_level=speed
set use_egraphs=true
target x86_64
target aarch64
Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/licm.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=none
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/misc.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=none
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/egraph/multivalue.clif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test compile precise-output
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/egraph/not_a_load.clif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test compile precise-output
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/remat.clif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test optimize
set opt_level=none
set opt_level=speed
set use_egraphs=true
target x86_64

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
;;!
;;! settings = [
;;! "enable_heap_access_spectre_mitigation=true",
;;! "opt_level=speed_and_size"
;;! "opt_level=speed_and_size",
;;! "use_egraphs=false"
cfallin marked this conversation as resolved.
Show resolved Hide resolved
;;! ]
;;!
;;! [globals.vmctx]
Expand Down Expand Up @@ -112,4 +113,4 @@
;;
;; block1:
;; @006e return v14, v14
;; }
;; }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
;;!
;;! settings = [
;;! "enable_heap_access_spectre_mitigation=true",
;;! "opt_level=speed_and_size"
;;! "opt_level=speed_and_size",
;;! "use_egraphs=false"
;;! ]
;;!
;;! [globals.vmctx]
Expand Down
15 changes: 7 additions & 8 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,14 +832,13 @@ impl Config {
/// Configures the Cranelift code generator to use its
/// "egraph"-based mid-end optimizer.
///
/// This optimizer is intended to replace the compiler's more
/// traditional pipeline of optimization passes with a unified
/// code-rewriting system. It is not yet on by default, but it is
/// intended to become the default in a future version. It may
/// result in faster code, at the cost of slightly more
/// compilation-time work.
///
/// The default value for this is `false`.
/// This optimizer has replaced the compiler's more traditional
/// pipeline of optimization passes with a unified code-rewriting
/// system. It is on by default, but the traditional optimization
/// pass structure is still available for now (it is deprecrated and
/// will be removed in a future version).
///
/// The default value for this is `true`.
cfallin marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(compiler)]
#[cfg_attr(nightlydoc, doc(cfg(feature = "cranelift")))] // see build.rs
pub fn cranelift_use_egraphs(&mut self, enable: bool) -> &mut Self {
Expand Down