Skip to content

Commit 6ded72b

Browse files
committed
Run GVN on monomorphic MIR.
1 parent 3024a83 commit 6ded72b

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, TyAndLayout};
88
use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
99
use rustc_middle::{bug, mir, span_bug};
1010
use rustc_mir_transform::{
11-
add_call_guards, dump_mir, pass_manager, remove_unneeded_drops, remove_zsts, simplify,
12-
unreachable_enum_branching, unreachable_prop,
11+
add_call_guards, dead_store_elimination, dump_mir, gvn, pass_manager, remove_unneeded_drops,
12+
remove_zsts, simplify, simplify_branches, unreachable_enum_branching, unreachable_prop,
1313
};
1414
use rustc_target::abi::call::{FnAbi, PassMode};
1515
use tracing::{debug, instrument};
@@ -173,6 +173,11 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
173173
&unreachable_enum_branching::UnreachableEnumBranching,
174174
&unreachable_prop::UnreachablePropagation,
175175
&simplify::SimplifyCfg::AfterUnreachableEnumBranching,
176+
&dead_store_elimination::DeadStoreElimination::Initial,
177+
&gvn::GVN,
178+
&simplify::SimplifyLocals::AfterGVN,
179+
&simplify_branches::SimplifyConstCondition::Final,
180+
&simplify::SimplifyCfg::Final,
176181
// Some cleanup necessary at least for LLVM and potentially other codegen backends.
177182
&add_call_guards::CriticalCallEdges,
178183
// Dump the end result for testing and debugging purposes.

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod coverage;
5959
mod cross_crate_inline;
6060
mod ctfe_limit;
6161
mod dataflow_const_prop;
62-
mod dead_store_elimination;
62+
pub mod dead_store_elimination;
6363
mod deduce_param_attrs;
6464
mod deduplicate_blocks;
6565
mod deref_separator;
@@ -71,7 +71,7 @@ mod elaborate_drops;
7171
mod errors;
7272
mod ffi_unwind_calls;
7373
mod function_item_references;
74-
mod gvn;
74+
pub mod gvn;
7575
pub mod inline;
7676
mod instsimplify;
7777
mod jump_threading;
@@ -97,13 +97,12 @@ mod required_consts;
9797
mod reveal_all;
9898
mod sanity_check;
9999
mod shim;
100-
mod ssa;
101-
// This pass is public to allow external drivers to perform MIR cleanup
102100
pub mod simplify;
103-
mod simplify_branches;
101+
pub mod simplify_branches;
104102
mod simplify_comparison_integral;
105103
mod single_use_consts;
106104
mod sroa;
105+
mod ssa;
107106
pub mod unreachable_enum_branching;
108107
pub mod unreachable_prop;
109108
mod validate;

tests/codegen/intrinsics/transmute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub unsafe fn check_from_empty_array(x: [u32; 0]) -> [u32; 5] {
8585

8686
// CHECK-LABEL: @check_to_uninhabited(
8787
#[no_mangle]
88-
#[custom_mir(dialect = "runtime", phase = "optimized")]
88+
#[custom_mir(dialect = "runtime", phase = "monomorphic")]
8989
pub unsafe fn check_to_uninhabited(x: u16) {
9090
// CHECK-NOT: trap
9191
// CHECK: call void @llvm.trap

tests/codegen/skip-mono-inside-if-false.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ pub fn demo_for_i32() {
1313

1414
// CHECK-LABEL: ; skip_mono_inside_if_false::generic_impl
1515
// CHECK: start:
16-
// CHECK-NEXT: br label %[[ELSE_BRANCH:bb[0-9]+]]
17-
// CHECK: [[ELSE_BRANCH]]:
1816
// CHECK-NEXT: call skip_mono_inside_if_false::small_impl
19-
// CHECK: bb{{[0-9]+}}:
17+
// CHECK-NEXT: call void @{{.*small_impl.*}}()
2018
// CHECK-NEXT: ret void
21-
// CHECK: bb{{[0-9+]}}:
22-
// CHECK-NEXT: unreachable
2319

2420
fn generic_impl<T>() {
2521
trait MagicTrait {

0 commit comments

Comments
 (0)