Skip to content

Commit

Permalink
do not merge(perf): reduce llvm stress
Browse files Browse the repository at this point in the history
by not make llvm de-duplicates arrays between promote temp pass and gvn.
  • Loading branch information
tesuji committed Jul 14, 2024
1 parent a275a8f commit c15eb60
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 9 additions & 0 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,15 @@ impl<'tcx> VnState<'_, 'tcx> {

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

// Ignore promoted arrays. Promoted arrays are already placed in `.rodata`.
// Which is what we try to archive for running gvn on constant local arrays.
if let Either::Left(mplace) = op.as_mplace_or_imm()
&& mplace.layout.ty.is_array()
&& let Value::Projection(_index, ProjectionElem::Deref) = self.get(index)
{
return None;
}

let value = op_to_prop_const(&mut self.ecx, op)?;

// Check that we do not leak a pointer.
Expand Down
4 changes: 1 addition & 3 deletions tests/mir-opt/const_array_locals.main.GVN.diff
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
_17 = const main::promoted[0];
_7 = &(*_17);
- _6 = (*_7);
+ _6 = const [254_i32, 42_i32, 15_i32, 39_i32, 62_i32];
+ _6 = (*_17);
StorageDead(_7);
StorageLive(_9);
StorageLive(_10);
Expand Down Expand Up @@ -124,6 +124,4 @@
+ ALLOC8 (size: 20, align: 4) { .. }
+
+ ALLOC9 (size: 20, align: 4) { .. }
+
+ ALLOC10 (size: 20, align: 4) { .. }

2 changes: 1 addition & 1 deletion tests/mir-opt/const_array_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn main() {
// CHECK{LITERAL}: const [[178_i32, 9_i32, 4_i32, 56_i32, 221_i32], [193_i32, 164_i32, 194_i32, 197_i32, 6_i32]];
let _foo = [[178, 9, 4, 56, 221], [193, 164, 194, 197, 6]];
// CHECK: [[PROMOTED:_[0-9]+]] = const main::promoted[0];
// CHECK: [[_darr]] = const [254_i32, 42_i32, 15_i32, 39_i32, 62_i32];
// CHECK: [[_darr]] = (*[[PROMOTED]]);
let _darr = *&[254, 42, 15, 39, 62];

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

0 comments on commit c15eb60

Please sign in to comment.