Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 12a2edd

Browse files
committed
Always propagate into operands.
1 parent 1554942 commit 12a2edd

File tree

50 files changed

+114
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+114
-140
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
810810

811811
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) {
812812
self.super_operand(operand, location);
813-
814-
// Only const prop copies and moves on `mir_opt_level=3` as doing so
815-
// currently slightly increases compile time in some cases.
816-
if self.tcx.sess.mir_opt_level() >= 3 {
817-
self.propagate_operand(operand)
818-
}
813+
self.propagate_operand(operand)
819814
}
820815

821816
fn process_projection_elem(

tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-abort.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
StorageLive(_4);
2727
StorageLive(_5);
2828
- _5 = _1;
29+
- _4 = foo(move _5) -> [return: bb1, unwind unreachable];
2930
+ _5 = const 1_u8;
30-
_4 = foo(move _5) -> [return: bb1, unwind unreachable];
31+
+ _4 = foo(const 1_u8) -> [return: bb1, unwind unreachable];
3132
}
3233

3334
bb1: {

tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-unwind.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
StorageLive(_4);
2727
StorageLive(_5);
2828
- _5 = _1;
29+
- _4 = foo(move _5) -> [return: bb1, unwind continue];
2930
+ _5 = const 1_u8;
30-
_4 = foo(move _5) -> [return: bb1, unwind continue];
31+
+ _4 = foo(const 1_u8) -> [return: bb1, unwind continue];
3132
}
3233

3334
bb1: {

tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-abort.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> () {
2323
StorageLive(_4);
2424
StorageLive(_5);
2525
_5 = const 1_u8;
26-
_4 = foo(move _5) -> [return: bb1, unwind unreachable];
26+
_4 = foo(const 1_u8) -> [return: bb1, unwind unreachable];
2727
}
2828

2929
bb1: {

tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-unwind.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> () {
2323
StorageLive(_4);
2424
StorageLive(_5);
2525
_5 = const 1_u8;
26-
_4 = foo(move _5) -> [return: bb1, unwind continue];
26+
_4 = foo(const 1_u8) -> [return: bb1, unwind continue];
2727
}
2828

2929
bb1: {

tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable];
2424
+ _4 = const 4_usize;
2525
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable];
26+
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable];
2727
}
2828

2929
bb1: {

tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue];
2424
+ _4 = const 4_usize;
2525
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue];
26+
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue];
2727
}
2828

2929
bb1: {

tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable];
2424
+ _4 = const 4_usize;
2525
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable];
26+
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable];
2727
}
2828

2929
bb1: {

tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue];
2424
+ _4 = const 4_usize;
2525
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue];
26+
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue];
2727
}
2828

2929
bb1: {

tests/mir-opt/const_prop/bad_op_div_by_zero.main.ConstProp.panic-abort.diff

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838
+ _5 = const false;
3939
+ _6 = const false;
4040
+ _7 = const false;
41-
+ assert(!const false, "attempt to compute `{} / {}`, which would overflow", const 1_i32, _3) -> [success: bb2, unwind unreachable];
41+
+ assert(!const false, "attempt to compute `{} / {}`, which would overflow", const 1_i32, const 0_i32) -> [success: bb2, unwind unreachable];
4242
}
4343

4444
bb2: {
45-
_2 = Div(const 1_i32, move _3);
45+
- _2 = Div(const 1_i32, move _3);
46+
+ _2 = Div(const 1_i32, const 0_i32);
4647
StorageDead(_3);
4748
_0 = const ();
4849
StorageDead(_2);

0 commit comments

Comments
 (0)