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

[WIP] rustc_mir_transform: Add extra ConstProp pass to fold constants at end of MIR-opt #95007

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&o1(simplify::SimplifyCfg::new("final")),
&nrvo::RenameReturnPlace,
&const_debuginfo::ConstDebugInfo,
&const_prop::ConstProp,
&simplify::SimplifyLocals,
&multiple_return_terminators::MultipleReturnTerminators,
&deduplicate_blocks::DeduplicateBlocks,
Expand Down
10 changes: 10 additions & 0 deletions src/test/mir-opt/const_folding_test.f.PreCodegen.after.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// MIR for `f` after PreCodegen

fn f() -> usize {
let mut _0: usize; // return place in scope 0 at $DIR/const_folding_test.rs:3:11: 3:16

bb0: {
_0 = const 2_usize; // scope 0 at $DIR/const_folding_test.rs:4:5: 4:29
return; // scope 0 at $DIR/const_folding_test.rs:5:2: 5:2
}
}
9 changes: 9 additions & 0 deletions src/test/mir-opt/const_folding_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// EMIT_MIR const_folding_test.f.PreCodegen.after.mir

fn f() -> usize {
1 + if true {1} else {2}
}

fn main() {
let _a = f();
}