Skip to content

Commit e1059c0

Browse files
Auto merge of #143333 - cjgillot:local-value-numbering, r=<try>
[TOY] Extend GVN to perform local value numbering.
2 parents bea625f + e4e6897 commit e1059c0

32 files changed

+760
-566
lines changed

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,23 @@ impl PlaceContext {
14151415
)
14161416
}
14171417

1418+
/// Returns `true` if this place context may be used to know the address of the given place.
1419+
pub fn may_observe_address(self) -> bool {
1420+
matches!(
1421+
self,
1422+
PlaceContext::NonMutatingUse(
1423+
NonMutatingUseContext::SharedBorrow
1424+
| NonMutatingUseContext::RawBorrow
1425+
| NonMutatingUseContext::FakeBorrow
1426+
) | PlaceContext::MutatingUse(
1427+
MutatingUseContext::Drop
1428+
| MutatingUseContext::Borrow
1429+
| MutatingUseContext::RawBorrow
1430+
| MutatingUseContext::AsmOutput
1431+
)
1432+
)
1433+
}
1434+
14181435
/// Returns `true` if this place context represents a storage live or storage dead marker.
14191436
#[inline]
14201437
pub fn is_storage_marker(self) -> bool {

compiler/rustc_mir_dataflow/src/value_analysis.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet, StdEntry};
66
use rustc_data_structures::stack::ensure_sufficient_stack;
77
use rustc_index::IndexVec;
88
use rustc_index::bit_set::DenseBitSet;
9-
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
9+
use rustc_middle::mir::visit::{PlaceContext, Visitor};
1010
use rustc_middle::mir::*;
1111
use rustc_middle::ty::{self, Ty, TyCtxt};
1212
use tracing::debug;
@@ -917,12 +917,7 @@ pub fn excluded_locals(body: &Body<'_>) -> DenseBitSet<Local> {
917917

918918
impl<'tcx> Visitor<'tcx> for Collector {
919919
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
920-
if (context.is_borrow()
921-
|| context.is_address_of()
922-
|| context.is_drop()
923-
|| context == PlaceContext::MutatingUse(MutatingUseContext::AsmOutput))
924-
&& !place.is_indirect()
925-
{
920+
if context.may_observe_address() && !place.is_indirect() {
926921
// A pointer to a place could be used to access other places with the same local,
927922
// hence we have to exclude the local completely.
928923
self.result.insert(place.local);

0 commit comments

Comments
 (0)