Skip to content

Commit e224bd7

Browse files
committed
Simplify repeat expressions.
1 parent 48925a9 commit e224bd7

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,17 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
499499
ProjectionElem::Field(f, ty)
500500
}
501501
ProjectionElem::Index(idx) => {
502+
if let Value::Repeat(inner, _) = self.get(value) {
503+
return Some(*inner);
504+
}
502505
let idx = self.locals[idx]?;
503506
ProjectionElem::Index(idx)
504507
}
505508
ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
506509
match self.get(value) {
510+
Value::Repeat(inner, _) => {
511+
return Some(*inner);
512+
}
507513
Value::Aggregate(ty, _, operands) if ty.is_array() => {
508514
let offset = if from_end {
509515
operands.len() - offset as usize

tests/mir-opt/gvn.repeated_index.GVN.panic-abort.diff

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141

4242
bb1: {
4343
- _6 = _3[_7];
44-
+ _6 = _3[0 of 1];
45-
_5 = opaque::<T>(move _6) -> [return: bb2, unwind unreachable];
44+
- _5 = opaque::<T>(move _6) -> [return: bb2, unwind unreachable];
45+
+ _6 = _1;
46+
+ _5 = opaque::<T>(_1) -> [return: bb2, unwind unreachable];
4647
}
4748

4849
bb2: {
@@ -63,8 +64,9 @@
6364

6465
bb3: {
6566
- _11 = _3[_12];
66-
+ _11 = _3[_2];
67-
_10 = opaque::<T>(move _11) -> [return: bb4, unwind unreachable];
67+
- _10 = opaque::<T>(move _11) -> [return: bb4, unwind unreachable];
68+
+ _11 = _1;
69+
+ _10 = opaque::<T>(_1) -> [return: bb4, unwind unreachable];
6870
}
6971

7072
bb4: {

tests/mir-opt/gvn.repeated_index.GVN.panic-unwind.diff

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141

4242
bb1: {
4343
- _6 = _3[_7];
44-
+ _6 = _3[0 of 1];
45-
_5 = opaque::<T>(move _6) -> [return: bb2, unwind continue];
44+
- _5 = opaque::<T>(move _6) -> [return: bb2, unwind continue];
45+
+ _6 = _1;
46+
+ _5 = opaque::<T>(_1) -> [return: bb2, unwind continue];
4647
}
4748

4849
bb2: {
@@ -63,8 +64,9 @@
6364

6465
bb3: {
6566
- _11 = _3[_12];
66-
+ _11 = _3[_2];
67-
_10 = opaque::<T>(move _11) -> [return: bb4, unwind continue];
67+
- _10 = opaque::<T>(move _11) -> [return: bb4, unwind continue];
68+
+ _11 = _1;
69+
+ _10 = opaque::<T>(_1) -> [return: bb4, unwind continue];
6870
}
6971

7072
bb4: {

0 commit comments

Comments
 (0)