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

Only enable ConstProp at mir-opt-level >= 2. #109900

Merged
merged 6 commits into from
Apr 15, 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: 1 addition & 7 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct ConstProp;

impl<'tcx> MirPass<'tcx> for ConstProp {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 1
sess.mir_opt_level() >= 2
}

#[instrument(skip(self, tcx), level = "debug")]
Expand Down Expand Up @@ -854,12 +854,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
}
}

fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
trace!("visit_constant: {:?}", constant);
self.super_constant(constant, location);
self.eval_constant(constant);
}

fn visit_assign(
&mut self,
place: &mut Place<'tcx>,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&separate_const_switch::SeparateConstSwitch,
&simplify::SimplifyLocals::new("before-const-prop"),
&copy_prop::CopyProp,
//
// FIXME(#70073): This pass is responsible for both optimization as well as some lints.
&const_prop::ConstProp,
&dataflow_const_prop::DataflowConstProp,
//
Expand Down
3 changes: 0 additions & 3 deletions tests/codegen/optimize-attr-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

// CHECK-LABEL: define{{.*}}i32 @nothing
// CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]]
// NO-OPT: ret i32 4
// SIZE-OPT: ret i32 4
// SPEEC-OPT: ret i32 4
#[no_mangle]
Expand All @@ -18,7 +17,6 @@ pub fn nothing() -> i32 {

// CHECK-LABEL: define{{.*}}i32 @size
// CHECK-SAME: [[SIZE_ATTRS:#[0-9]+]]
// NO-OPT: ret i32 6
// SIZE-OPT: ret i32 6
// SPEED-OPT: ret i32 6
#[optimize(size)]
Expand All @@ -31,7 +29,6 @@ pub fn size() -> i32 {
// NO-OPT-SAME: [[NOTHING_ATTRS]]
// SPEED-OPT-SAME: [[NOTHING_ATTRS]]
// SIZE-OPT-SAME: [[SPEED_ATTRS:#[0-9]+]]
// NO-OPT: ret i32 8
// SIZE-OPT: ret i32 8
// SPEED-OPT: ret i32 8
#[optimize(speed)]
Expand Down
17 changes: 0 additions & 17 deletions tests/mir-opt/div_overflow.const_dividend.PreCodegen.after.mir

This file was deleted.

11 changes: 0 additions & 11 deletions tests/mir-opt/div_overflow.const_divisor.PreCodegen.after.mir

This file was deleted.

19 changes: 0 additions & 19 deletions tests/mir-opt/div_overflow.rs

This file was deleted.

8 changes: 7 additions & 1 deletion tests/run-make/const_fn_mir/dump.mir
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
// and is subject to change without notice. Knock yourself out.
fn foo() -> i32 {
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22
let mut _1: (i32, bool); // in scope 0 at main.rs:5:5: 5:10

bb0: {
_0 = const 11_i32; // scope 0 at main.rs:5:5: 5:10
_1 = CheckedAdd(const 5_i32, const 6_i32); // scope 0 at main.rs:5:5: 5:10
assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> bb1; // scope 0 at main.rs:5:5: 5:10
}

bb1: {
_0 = move (_1.0: i32); // scope 0 at main.rs:5:5: 5:10
return; // scope 0 at main.rs:6:2: 6:2
}
}
Expand Down
8 changes: 0 additions & 8 deletions tests/ui/associated-consts/defaults-not-assumed-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
|
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant used
--> $DIR/defaults-not-assumed-fail.rs:33:5
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
6 changes: 0 additions & 6 deletions tests/ui/consts/const-err-late.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ note: erroneous constant used
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
| ^^^^^^^^^^^^^

note: erroneous constant used
--> $DIR/const-err-late.rs:19:16
|
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
| ^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0080`.
8 changes: 0 additions & 8 deletions tests/ui/consts/const-eval/issue-44578.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant used
--> $DIR/issue-44578.rs:25:20
|
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
6 changes: 0 additions & 6 deletions tests/ui/consts/miri_unleashed/assoc_const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ note: erroneous constant used
LL | let y = <String as Bar<Vec<u32>, String>>::F;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: erroneous constant used
--> $DIR/assoc_const.rs:29:13
|
LL | let y = <String as Bar<Vec<u32>, String>>::F;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: skipping const checks
|
help: skipping check that does not even have a feature gate
Expand Down
6 changes: 0 additions & 6 deletions tests/ui/consts/miri_unleashed/assoc_const_2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ note: erroneous constant used
LL | let y = <String as Bar<String>>::F;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

note: erroneous constant used
--> $DIR/assoc_const_2.rs:27:13
|
LL | let y = <String as Bar<String>>::F;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
6 changes: 0 additions & 6 deletions tests/ui/consts/uninhabited-const-issue-61744.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,6 @@ note: erroneous constant used
LL | dbg!(i32::CONSTANT);
| ^^^^^^^^^^^^^

note: erroneous constant used
--> $DIR/uninhabited-const-issue-61744.rs:18:10
|
LL | dbg!(i32::CONSTANT);
| ^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
8 changes: 0 additions & 8 deletions tests/ui/limits/issue-55878.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant used
--> $DIR/issue-55878.rs:7:26
|
LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.