Skip to content

Commit 941dfb9

Browse files
authored
Rollup merge of rust-lang#72220 - wesleywiser:const_prop_eval_consts, r=oli-obk
[const-prop] Don't replace Rvalues that are already constants This cleans up a few mir-opt tests which have slight changes to spans for `consts` as a result of replacing them with new Rvalues.
2 parents 89866ce + e84b379 commit 941dfb9

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

src/librustc_mir/transform/const_prop.rs

+7
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
616616
value: OpTy<'tcx>,
617617
source_info: SourceInfo,
618618
) {
619+
if let Rvalue::Use(Operand::Constant(c)) = rval {
620+
if !matches!(c.literal.val, ConstKind::Unevaluated(..)) {
621+
trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c);
622+
return;
623+
}
624+
}
625+
619626
trace!("attepting to replace {:?} with {:?}", rval, value);
620627
if let Err(e) = self.ecx.const_validate_operand(
621628
value,

src/test/mir-opt/const_prop/mutable_variable/rustc.main.ConstProp.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
// + ty: i32
2727
// + val: Value(Scalar(0x00000063))
2828
// mir::Constant
29-
- // + span: $DIR/mutable_variable.rs:6:9: 6:11
30-
+ // + span: $DIR/mutable_variable.rs:6:5: 6:11
29+
// + span: $DIR/mutable_variable.rs:6:9: 6:11
3130
// + literal: Const { ty: i32, val: Value(Scalar(0x00000063)) }
3231
StorageLive(_2); // scope 1 at $DIR/mutable_variable.rs:7:9: 7:10
3332
- _2 = _1; // scope 1 at $DIR/mutable_variable.rs:7:13: 7:14

src/test/mir-opt/const_prop/mutable_variable_aggregate/rustc.main.ConstProp.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
// + ty: i32
3535
// + val: Value(Scalar(0x00000063))
3636
// mir::Constant
37-
- // + span: $DIR/mutable_variable_aggregate.rs:6:11: 6:13
38-
+ // + span: $DIR/mutable_variable_aggregate.rs:6:5: 6:13
37+
// + span: $DIR/mutable_variable_aggregate.rs:6:11: 6:13
3938
// + literal: Const { ty: i32, val: Value(Scalar(0x00000063)) }
4039
StorageLive(_2); // scope 1 at $DIR/mutable_variable_aggregate.rs:7:9: 7:10
4140
- _2 = _1; // scope 1 at $DIR/mutable_variable_aggregate.rs:7:13: 7:14

src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// + ty: i32
1818
// + val: Value(Scalar(0x0000007b))
1919
// mir::Constant
20-
// + span: $DIR/copy_propagation_arg.rs:29:5: 29:12
20+
// + span: $DIR/copy_propagation_arg.rs:29:9: 29:12
2121
// + literal: Const { ty: i32, val: Value(Scalar(0x0000007b)) }
2222
_0 = _2; // scope 1 at $DIR/copy_propagation_arg.rs:30:5: 30:6
2323
StorageDead(_2); // scope 0 at $DIR/copy_propagation_arg.rs:31:1: 31:2

src/test/mir-opt/copy_propagation_arg/rustc.bar.CopyPropagation.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// + ty: u8
2929
// + val: Value(Scalar(0x05))
3030
// mir::Constant
31-
// + span: $DIR/copy_propagation_arg.rs:17:5: 17:10
31+
// + span: $DIR/copy_propagation_arg.rs:17:9: 17:10
3232
// + literal: Const { ty: u8, val: Value(Scalar(0x05)) }
3333
_0 = const (); // scope 0 at $DIR/copy_propagation_arg.rs:15:19: 18:2
3434
// ty::Const

0 commit comments

Comments
 (0)