Dereference immutable borrows in GVN.

This commit is contained in:
Camille GILLOT 2024-01-05 21:52:58 +00:00
parent 73db12a223
commit 9b846d4637
10 changed files with 87 additions and 47 deletions

View File

@ -724,6 +724,14 @@ fn simplify_place_value(
// Invariant: `value` holds the value up-to the `index`th projection excluded.
let mut value = self.locals[place.local]?;
for (index, proj) in place.projection.iter().enumerate() {
if let Value::Projection(pointer, ProjectionElem::Deref) = *self.get(value)
&& let Value::Address { place: mut pointee, kind, .. } = *self.get(pointer)
&& let AddressKind::Ref(BorrowKind::Shared) = kind
&& let Some(v) = self.simplify_place_value(&mut pointee, location)
{
value = v;
place_ref = pointee.project_deeper(&place.projection[index..], self.tcx).as_ref();
}
if let Some(local) = self.try_as_local(value, location) {
// Both `local` and `Place { local: place.local, projection: projection[..index] }`
// hold the same value. Therefore, following place holds the value in the original
@ -735,6 +743,14 @@ fn simplify_place_value(
value = self.project(base, value, proj)?;
}
if let Value::Projection(pointer, ProjectionElem::Deref) = *self.get(value)
&& let Value::Address { place: mut pointee, kind, .. } = *self.get(pointer)
&& let AddressKind::Ref(BorrowKind::Shared) = kind
&& let Some(v) = self.simplify_place_value(&mut pointee, location)
{
value = v;
place_ref = pointee.project_deeper(&[], self.tcx).as_ref();
}
if let Some(new_local) = self.try_as_local(value, location) {
place_ref = PlaceRef { local: new_local, projection: &[] };
}

View File

@ -1,12 +1,12 @@
Function name: issue_83601::main
Raw bytes (21): 0x[01, 01, 01, 05, 09, 03, 01, 06, 01, 02, 1c, 05, 03, 09, 01, 1c, 02, 02, 05, 03, 02]
Raw bytes (21): 0x[01, 01, 01, 05, 00, 03, 01, 06, 01, 02, 1c, 05, 03, 09, 01, 1c, 02, 02, 05, 03, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 1
- expression 0 operands: lhs = Counter(1), rhs = Counter(2)
- expression 0 operands: lhs = Counter(1), rhs = Zero
Number of file 0 mappings: 3
- Code(Counter(0)) at (prev + 6, 1) to (start + 2, 28)
- Code(Counter(1)) at (prev + 3, 9) to (start + 1, 28)
- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 3, 2)
= (c1 - c2)
= (c1 - Zero)

View File

@ -77,22 +77,22 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 167, 9) to (start + 2, 10)
Function name: issue_84561::test3
Raw bytes (436): 0x[01, 01, 41, 05, 09, 0d, 00, 15, 19, 12, 00, 15, 19, 21, 00, 1e, 00, 21, 00, 31, 00, 3d, 41, 2e, 45, 3d, 41, 42, 49, 45, 00, 3f, 51, 42, 49, 45, 00, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 92, 01, 55, 51, 00, 8f, 01, 5d, 92, 01, 55, 51, 00, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 82, 01, 65, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, 00, fe, 01, 82, 02, 00, 69, 6d, 69, 6d, 82, 02, 00, 69, 6d, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, ee, 01, 00, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, 33, 01, 08, 01, 03, 1c, 05, 04, 09, 01, 1c, 02, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 06, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 12, 02, 05, 00, 1f, 0e, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 1e, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 1a, 04, 09, 05, 06, 31, 06, 05, 03, 06, 22, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 2e, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 2a, 05, 09, 03, 0a, 3f, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 3a, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 87, 01, 03, 05, 00, 0f, 8f, 01, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 8a, 01, 02, 0d, 00, 13, 82, 01, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 7e, 02, 0d, 00, 13, f3, 01, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 75, 04, 0d, 00, 13, fb, 01, 02, 0d, 00, 17, 82, 02, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, fe, 01, 02, 15, 00, 1b, f6, 01, 04, 0d, 00, 13, 7d, 03, 09, 00, 19, ee, 01, 02, 05, 00, 0f, ea, 01, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02]
Raw bytes (436): 0x[01, 01, 41, 05, 00, 0d, 00, 15, 00, 12, 00, 15, 00, 21, 00, 1e, 00, 21, 00, 31, 00, 3d, 00, 2e, 45, 3d, 00, 42, 49, 45, 00, 3f, 51, 42, 49, 45, 00, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 92, 01, 55, 51, 00, 8f, 01, 5d, 92, 01, 55, 51, 00, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 82, 01, 65, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, 00, fe, 01, 82, 02, 00, 69, 6d, 69, 6d, 82, 02, 00, 69, 6d, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, ee, 01, 00, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, 33, 01, 08, 01, 03, 1c, 05, 04, 09, 01, 1c, 02, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 06, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 12, 02, 05, 00, 1f, 0e, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 1e, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 1a, 04, 09, 05, 06, 31, 06, 05, 03, 06, 22, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 2e, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 2a, 05, 09, 03, 0a, 3f, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 3a, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 87, 01, 03, 05, 00, 0f, 8f, 01, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 8a, 01, 02, 0d, 00, 13, 82, 01, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 7e, 02, 0d, 00, 13, f3, 01, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 75, 04, 0d, 00, 13, fb, 01, 02, 0d, 00, 17, 82, 02, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, fe, 01, 02, 15, 00, 1b, f6, 01, 04, 0d, 00, 13, 7d, 03, 09, 00, 19, ee, 01, 02, 05, 00, 0f, ea, 01, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 65
- expression 0 operands: lhs = Counter(1), rhs = Counter(2)
- expression 0 operands: lhs = Counter(1), rhs = Zero
- expression 1 operands: lhs = Counter(3), rhs = Zero
- expression 2 operands: lhs = Counter(5), rhs = Counter(6)
- expression 2 operands: lhs = Counter(5), rhs = Zero
- expression 3 operands: lhs = Expression(4, Sub), rhs = Zero
- expression 4 operands: lhs = Counter(5), rhs = Counter(6)
- expression 4 operands: lhs = Counter(5), rhs = Zero
- expression 5 operands: lhs = Counter(8), rhs = Zero
- expression 6 operands: lhs = Expression(7, Sub), rhs = Zero
- expression 7 operands: lhs = Counter(8), rhs = Zero
- expression 8 operands: lhs = Counter(12), rhs = Zero
- expression 9 operands: lhs = Counter(15), rhs = Counter(16)
- expression 9 operands: lhs = Counter(15), rhs = Zero
- expression 10 operands: lhs = Expression(11, Sub), rhs = Counter(17)
- expression 11 operands: lhs = Counter(15), rhs = Counter(16)
- expression 11 operands: lhs = Counter(15), rhs = Zero
- expression 12 operands: lhs = Expression(16, Sub), rhs = Counter(18)
- expression 13 operands: lhs = Counter(17), rhs = Zero
- expression 14 operands: lhs = Expression(15, Add), rhs = Counter(20)
@ -150,15 +150,15 @@ Number of file 0 mappings: 51
- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 28)
- Code(Counter(1)) at (prev + 4, 9) to (start + 1, 28)
- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 4, 31)
= (c1 - c2)
= (c1 - Zero)
- Code(Counter(3)) at (prev + 5, 5) to (start + 0, 31)
- Code(Expression(1, Sub)) at (prev + 1, 5) to (start + 0, 31)
= (c3 - Zero)
- Code(Counter(5)) at (prev + 1, 9) to (start + 1, 28)
- Code(Expression(4, Sub)) at (prev + 2, 5) to (start + 0, 31)
= (c5 - c6)
= (c5 - Zero)
- Code(Expression(3, Sub)) at (prev + 1, 5) to (start + 0, 15)
= ((c5 - c6) - Zero)
= ((c5 - Zero) - Zero)
- Code(Zero) at (prev + 0, 32) to (start + 0, 48)
- Code(Counter(8)) at (prev + 1, 5) to (start + 3, 15)
- Code(Zero) at (prev + 3, 32) to (start + 0, 48)
@ -176,10 +176,10 @@ Number of file 0 mappings: 51
= (c12 - Zero)
- Code(Counter(15)) at (prev + 4, 9) to (start + 4, 6)
- Code(Expression(11, Sub)) at (prev + 5, 8) to (start + 0, 15)
= (c15 - c16)
= (c15 - Zero)
- Code(Counter(17)) at (prev + 1, 9) to (start + 3, 10)
- Code(Expression(10, Sub)) at (prev + 5, 9) to (start + 3, 10)
= ((c15 - c16) - c17)
= ((c15 - Zero) - c17)
- Code(Expression(15, Add)) at (prev + 5, 8) to (start + 0, 15)
= ((c17 - Zero) + c18)
- Code(Counter(20)) at (prev + 1, 9) to (start + 0, 19)

View File

@ -18,7 +18,8 @@
}
bb2: {
_0 = opaque::<u32>((*_3)) -> [return: bb3, unwind unreachable];
- _0 = opaque::<u32>((*_3)) -> [return: bb3, unwind unreachable];
+ _0 = opaque::<u32>(_1) -> [return: bb3, unwind unreachable];
}
bb3: {

View File

@ -18,7 +18,8 @@
}
bb2: {
_0 = opaque::<u32>((*_3)) -> [return: bb3, unwind continue];
- _0 = opaque::<u32>((*_3)) -> [return: bb3, unwind continue];
+ _0 = opaque::<u32>(_1) -> [return: bb3, unwind continue];
}
bb3: {

View File

@ -730,7 +730,7 @@ fn borrowed(x: u32) {
// CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<u32>(_1)
// CHECK: bb2: {
// CHECK-NEXT: _0 = opaque::<u32>((*_3))
// CHECK-NEXT: _0 = opaque::<u32>(_1)
mir!(
{
let a = x;

View File

@ -111,8 +111,9 @@
StorageLive(_7);
StorageLive(_8);
- StorageLive(_9);
- StorageLive(_10);
+ nop;
+ nop;
StorageLive(_10);
StorageLive(_11);
_11 = &(*_1);
_10 = core::str::<impl str>::as_ptr(move _11) -> [return: bb3, unwind unreachable];
@ -122,8 +123,9 @@
StorageDead(_11);
_9 = &_10;
- StorageLive(_12);
- StorageLive(_13);
+ nop;
+ nop;
StorageLive(_13);
StorageLive(_14);
- _14 = &(*_4);
+ _14 = &(*_1);
@ -148,11 +150,12 @@
StorageLive(_17);
StorageLive(_18);
- _18 = (*_15);
+ _18 = (*_9);
+ _18 = _10;
StorageLive(_19);
- _19 = (*_16);
+ _19 = (*_12);
_17 = Eq(move _18, move _19);
- _17 = Eq(move _18, move _19);
+ _19 = _13;
+ _17 = Eq(_10, _13);
switchInt(move _17) -> [0: bb6, otherwise: bb5];
}
@ -163,8 +166,10 @@
StorageDead(_17);
StorageDead(_16);
StorageDead(_15);
StorageDead(_13);
StorageDead(_10);
- StorageDead(_13);
- StorageDead(_10);
+ nop;
+ nop;
StorageDead(_8);
StorageDead(_7);
- StorageLive(_29);
@ -213,8 +218,9 @@
StorageLive(_33);
StorageLive(_34);
- StorageLive(_35);
- StorageLive(_36);
+ nop;
+ nop;
StorageLive(_36);
StorageLive(_37);
_37 = &(*_1);
_36 = core::str::<impl str>::as_ptr(move _37) -> [return: bb8, unwind unreachable];
@ -224,8 +230,9 @@
StorageDead(_37);
_35 = &_36;
- StorageLive(_38);
- StorageLive(_39);
+ nop;
+ nop;
StorageLive(_39);
StorageLive(_40);
_40 = &(*_29);
_39 = core::slice::<impl [u8]>::as_ptr(move _40) -> [return: bb9, unwind unreachable];
@ -249,11 +256,12 @@
StorageLive(_43);
StorageLive(_44);
- _44 = (*_41);
+ _44 = (*_35);
+ _44 = _36;
StorageLive(_45);
- _45 = (*_42);
+ _45 = (*_38);
_43 = Eq(move _44, move _45);
- _43 = Eq(move _44, move _45);
+ _45 = _39;
+ _43 = Eq(_36, _39);
switchInt(move _43) -> [0: bb11, otherwise: bb10];
}
@ -264,8 +272,10 @@
StorageDead(_43);
StorageDead(_42);
StorageDead(_41);
StorageDead(_39);
StorageDead(_36);
- StorageDead(_39);
- StorageDead(_36);
+ nop;
+ nop;
StorageDead(_34);
StorageDead(_33);
_0 = const ();

View File

@ -111,8 +111,9 @@
StorageLive(_7);
StorageLive(_8);
- StorageLive(_9);
- StorageLive(_10);
+ nop;
+ nop;
StorageLive(_10);
StorageLive(_11);
_11 = &(*_1);
_10 = core::str::<impl str>::as_ptr(move _11) -> [return: bb3, unwind continue];
@ -122,8 +123,9 @@
StorageDead(_11);
_9 = &_10;
- StorageLive(_12);
- StorageLive(_13);
+ nop;
+ nop;
StorageLive(_13);
StorageLive(_14);
- _14 = &(*_4);
+ _14 = &(*_1);
@ -148,11 +150,12 @@
StorageLive(_17);
StorageLive(_18);
- _18 = (*_15);
+ _18 = (*_9);
+ _18 = _10;
StorageLive(_19);
- _19 = (*_16);
+ _19 = (*_12);
_17 = Eq(move _18, move _19);
- _17 = Eq(move _18, move _19);
+ _19 = _13;
+ _17 = Eq(_10, _13);
switchInt(move _17) -> [0: bb6, otherwise: bb5];
}
@ -163,8 +166,10 @@
StorageDead(_17);
StorageDead(_16);
StorageDead(_15);
StorageDead(_13);
StorageDead(_10);
- StorageDead(_13);
- StorageDead(_10);
+ nop;
+ nop;
StorageDead(_8);
StorageDead(_7);
- StorageLive(_29);
@ -213,8 +218,9 @@
StorageLive(_33);
StorageLive(_34);
- StorageLive(_35);
- StorageLive(_36);
+ nop;
+ nop;
StorageLive(_36);
StorageLive(_37);
_37 = &(*_1);
_36 = core::str::<impl str>::as_ptr(move _37) -> [return: bb8, unwind continue];
@ -224,8 +230,9 @@
StorageDead(_37);
_35 = &_36;
- StorageLive(_38);
- StorageLive(_39);
+ nop;
+ nop;
StorageLive(_39);
StorageLive(_40);
_40 = &(*_29);
_39 = core::slice::<impl [u8]>::as_ptr(move _40) -> [return: bb9, unwind continue];
@ -249,11 +256,12 @@
StorageLive(_43);
StorageLive(_44);
- _44 = (*_41);
+ _44 = (*_35);
+ _44 = _36;
StorageLive(_45);
- _45 = (*_42);
+ _45 = (*_38);
_43 = Eq(move _44, move _45);
- _43 = Eq(move _44, move _45);
+ _45 = _39;
+ _43 = Eq(_36, _39);
switchInt(move _43) -> [0: bb11, otherwise: bb10];
}
@ -264,8 +272,10 @@
StorageDead(_43);
StorageDead(_42);
StorageDead(_41);
StorageDead(_39);
StorageDead(_36);
- StorageDead(_39);
- StorageDead(_36);
+ nop;
+ nop;
StorageDead(_34);
StorageDead(_33);
_0 = const ();

View File

@ -17,7 +17,8 @@
StorageLive(_3);
_5 = const f::promoted[0];
_3 = &(*_5);
_2 = ((*_3).1: E);
- _2 = ((*_3).1: E);
+ _2 = ((*_5).1: E);
StorageLive(_1);
- _1 = ((_2 as A).1: u32);
+ _1 = const 0_u32;

View File

@ -17,7 +17,8 @@
StorageLive(_3);
_5 = const f::promoted[0];
_3 = &(*_5);
_2 = ((*_3).1: E);
- _2 = ((*_3).1: E);
+ _2 = ((*_5).1: E);
StorageLive(_1);
- _1 = ((_2 as A).1: u32);
+ _1 = const 0_u32;