Skip to content

Commit c15eb60

Browse files
committed
do not merge(perf): reduce llvm stress
by not make llvm de-duplicates arrays between promote temp pass and gvn.
1 parent a275a8f commit c15eb60

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,15 @@ impl<'tcx> VnState<'_, 'tcx> {
14511451

14521452
let op = self.evaluated[index].as_ref()?;
14531453

1454+
// Ignore promoted arrays. Promoted arrays are already placed in `.rodata`.
1455+
// Which is what we try to archive for running gvn on constant local arrays.
1456+
if let Either::Left(mplace) = op.as_mplace_or_imm()
1457+
&& mplace.layout.ty.is_array()
1458+
&& let Value::Projection(_index, ProjectionElem::Deref) = self.get(index)
1459+
{
1460+
return None;
1461+
}
1462+
14541463
let value = op_to_prop_const(&mut self.ecx, op)?;
14551464

14561465
// Check that we do not leak a pointer.

tests/mir-opt/const_array_locals.main.GVN.diff

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
_17 = const main::promoted[0];
6060
_7 = &(*_17);
6161
- _6 = (*_7);
62-
+ _6 = const [254_i32, 42_i32, 15_i32, 39_i32, 62_i32];
62+
+ _6 = (*_17);
6363
StorageDead(_7);
6464
StorageLive(_9);
6565
StorageLive(_10);
@@ -124,6 +124,4 @@
124124
+ ALLOC8 (size: 20, align: 4) { .. }
125125
+
126126
+ ALLOC9 (size: 20, align: 4) { .. }
127-
+
128-
+ ALLOC10 (size: 20, align: 4) { .. }
129127

tests/mir-opt/const_array_locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn main() {
2222
// CHECK{LITERAL}: const [[178_i32, 9_i32, 4_i32, 56_i32, 221_i32], [193_i32, 164_i32, 194_i32, 197_i32, 6_i32]];
2323
let _foo = [[178, 9, 4, 56, 221], [193, 164, 194, 197, 6]];
2424
// CHECK: [[PROMOTED:_[0-9]+]] = const main::promoted[0];
25-
// CHECK: [[_darr]] = const [254_i32, 42_i32, 15_i32, 39_i32, 62_i32];
25+
// CHECK: [[_darr]] = (*[[PROMOTED]]);
2626
let _darr = *&[254, 42, 15, 39, 62];
2727

2828
// CHECK: [[ARG:_[0-9]+]] = const [31_u32, 96_u32, 173_u32, 50_u32, 1_u32];

0 commit comments

Comments
 (0)