Skip to content

Commit a0b4d6d

Browse files
committed
Do not normalize constants eagerly.
1 parent 249cf71 commit a0b4d6d

11 files changed

+32
-59
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
773773
location: Location,
774774
) -> Option<VnIndex> {
775775
match *operand {
776-
Operand::Constant(ref mut constant) => {
777-
let const_ = constant.const_.normalize(self.tcx, self.param_env);
778-
self.insert_constant(const_)
779-
}
776+
Operand::Constant(ref constant) => self.insert_constant(constant.const_),
780777
Operand::Copy(ref mut place) | Operand::Move(ref mut place) => {
781778
let value = self.simplify_place_value(place, location)?;
782779
if let Some(const_) = self.try_as_constant(value) {

tests/incremental/hashes/for_loops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ pub fn change_iterable() {
103103
}
104104

105105
#[cfg(not(any(cfail1,cfail4)))]
106-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes, promoted_mir, optimized_mir")]
106+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes, promoted_mir")]
107107
#[rustc_clean(cfg="cfail3")]
108-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, promoted_mir, optimized_mir")]
108+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, promoted_mir")]
109109
#[rustc_clean(cfg="cfail6")]
110110
pub fn change_iterable() {
111111
let mut _x = 0;

tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
StorageLive(_3);
2323
StorageLive(_4);
2424
_9 = const main::promoted[0];
25-
- _4 = _9;
25+
_4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));
28-
+ _4 = const {ALLOC0<imm>: &[u32; 3]};
29-
+ _3 = const {ALLOC0<imm>: &[u32; 3]};
30-
+ _2 = const {ALLOC0<imm>: &[u32; 3]} as &[u32] (PointerCoercion(Unsize));
28+
+ _3 = _9;
29+
+ _2 = _9 as &[u32] (PointerCoercion(Unsize));
3130
StorageDead(_3);
3231
StorageLive(_6);
3332
_6 = const 1_usize;
@@ -50,6 +49,4 @@
5049
return;
5150
}
5251
}
53-
+
54-
+ ALLOC0 (size: 12, align: 4) { .. }
5552

tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
StorageLive(_3);
2323
StorageLive(_4);
2424
_9 = const main::promoted[0];
25-
- _4 = _9;
25+
_4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));
28-
+ _4 = const {ALLOC0<imm>: &[u32; 3]};
29-
+ _3 = const {ALLOC0<imm>: &[u32; 3]};
30-
+ _2 = const {ALLOC0<imm>: &[u32; 3]} as &[u32] (PointerCoercion(Unsize));
28+
+ _3 = _9;
29+
+ _2 = _9 as &[u32] (PointerCoercion(Unsize));
3130
StorageDead(_3);
3231
StorageLive(_6);
3332
_6 = const 1_usize;
@@ -50,6 +49,4 @@
5049
return;
5150
}
5251
}
53-
+
54-
+ ALLOC0 (size: 12, align: 4) { .. }
5552

tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
StorageLive(_3);
2323
StorageLive(_4);
2424
_9 = const main::promoted[0];
25-
- _4 = _9;
25+
_4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));
28-
+ _4 = const {ALLOC0<imm>: &[u32; 3]};
29-
+ _3 = const {ALLOC0<imm>: &[u32; 3]};
30-
+ _2 = const {ALLOC0<imm>: &[u32; 3]} as &[u32] (PointerCoercion(Unsize));
28+
+ _3 = _9;
29+
+ _2 = _9 as &[u32] (PointerCoercion(Unsize));
3130
StorageDead(_3);
3231
StorageLive(_6);
3332
_6 = const 1_usize;
@@ -50,6 +49,4 @@
5049
return;
5150
}
5251
}
53-
+
54-
+ ALLOC0 (size: 12, align: 4) { .. }
5552

tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
StorageLive(_3);
2323
StorageLive(_4);
2424
_9 = const main::promoted[0];
25-
- _4 = _9;
25+
_4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));
28-
+ _4 = const {ALLOC0<imm>: &[u32; 3]};
29-
+ _3 = const {ALLOC0<imm>: &[u32; 3]};
30-
+ _2 = const {ALLOC0<imm>: &[u32; 3]} as &[u32] (PointerCoercion(Unsize));
28+
+ _3 = _9;
29+
+ _2 = _9 as &[u32] (PointerCoercion(Unsize));
3130
StorageDead(_3);
3231
StorageLive(_6);
3332
_6 = const 1_usize;
@@ -50,6 +49,4 @@
5049
return;
5150
}
5251
}
53-
+
54-
+ ALLOC0 (size: 12, align: 4) { .. }
5552

tests/mir-opt/const_prop/slice_len.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
fn main() {
88
// CHECK-LABEL: fn main(
99
// CHECK: debug a => [[a:_.*]];
10-
// CHECK: [[slice:_.*]] = const {{.*}} as &[u32] (PointerCoercion(Unsize));
10+
// CHECK: [[slice:_.*]] = {{.*}} as &[u32] (PointerCoercion(Unsize));
1111
// CHECK: assert(const true,
1212
// CHECK: [[a]] = const 2_u32;
1313
let a = (&[1u32, 2, 3] as &[u32])[1];

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@
7373
StorageLive(_6);
7474
StorageLive(_7);
7575
_9 = const main::promoted[0];
76-
- _7 = _9;
77-
+ _7 = const {ALLOC1<imm>: &std::alloc::Global};
76+
_7 = _9;
7877
StorageLive(_8);
7978
- _8 = _1;
8079
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb4, unwind unreachable];
8180
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
82-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind unreachable];
81+
+ _6 = std::alloc::Global::alloc_impl(_9, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind unreachable];
8382
}
8483

8584
bb4: {
@@ -119,11 +118,9 @@
119118
+ nop;
120119
return;
121120
}
122-
}
121+
+ }
123122
+
124123
+ ALLOC0 (size: 8, align: 4) {
125124
+ 00 00 00 00 __ __ __ __ │ ....░░░░
126-
+ }
127-
+
128-
+ ALLOC1 (size: 0, align: 1) {}
125+
}
129126

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,22 @@
8181
StorageLive(_6);
8282
StorageLive(_7);
8383
_9 = const main::promoted[0];
84-
- _7 = _9;
85-
+ _7 = const {ALLOC1<imm>: &std::alloc::Global};
84+
_7 = _9;
8685
StorageLive(_8);
8786
- _8 = _1;
8887
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb5, unwind continue];
8988
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
90-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
89+
+ _6 = std::alloc::Global::alloc_impl(_9, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
9190
}
9291

9392
bb5: {
9493
StorageDead(_8);
9594
StorageDead(_7);
9695
_5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
9796
}
98-
}
97+
+ }
9998
+
10099
+ ALLOC0 (size: 8, align: 4) {
101100
+ 00 00 00 00 __ __ __ __ │ ....░░░░
102-
+ }
103-
+
104-
+ ALLOC1 (size: 0, align: 1) {}
101+
}
105102

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@
7373
StorageLive(_6);
7474
StorageLive(_7);
7575
_9 = const main::promoted[0];
76-
- _7 = _9;
77-
+ _7 = const {ALLOC1<imm>: &std::alloc::Global};
76+
_7 = _9;
7877
StorageLive(_8);
7978
- _8 = _1;
8079
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb4, unwind unreachable];
8180
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
82-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind unreachable];
81+
+ _6 = std::alloc::Global::alloc_impl(_9, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb4, unwind unreachable];
8382
}
8483

8584
bb4: {
@@ -119,11 +118,9 @@
119118
+ nop;
120119
return;
121120
}
122-
}
121+
+ }
123122
+
124123
+ ALLOC0 (size: 16, align: 8) {
125124
+ 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
126-
+ }
127-
+
128-
+ ALLOC1 (size: 0, align: 1) {}
125+
}
129126

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,22 @@
8181
StorageLive(_6);
8282
StorageLive(_7);
8383
_9 = const main::promoted[0];
84-
- _7 = _9;
85-
+ _7 = const {ALLOC1<imm>: &std::alloc::Global};
84+
_7 = _9;
8685
StorageLive(_8);
8786
- _8 = _1;
8887
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb5, unwind continue];
8988
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
90-
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1<imm>: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
89+
+ _6 = std::alloc::Global::alloc_impl(_9, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
9190
}
9291

9392
bb5: {
9493
StorageDead(_8);
9594
StorageDead(_7);
9695
_5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
9796
}
98-
}
97+
+ }
9998
+
10099
+ ALLOC0 (size: 16, align: 8) {
101100
+ 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
102-
+ }
103-
+
104-
+ ALLOC1 (size: 0, align: 1) {}
101+
}
105102

0 commit comments

Comments
 (0)