Skip to content

Commit 1e45fee

Browse files
Auto merge of #143333 - cjgillot:local-value-numbering, r=<try>
[TOY] Extend GVN to perform local value numbering.
2 parents c5a6a7b + 290a3bc commit 1e45fee

File tree

49 files changed

+1356
-1120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1356
-1120
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4292,6 +4292,7 @@ name = "rustc_mir_transform"
42924292
version = "0.0.0"
42934293
dependencies = [
42944294
"either",
4295+
"hashbrown",
42954296
"itertools",
42964297
"rustc_abi",
42974298
"rustc_arena",

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);

compiler/rustc_mir_transform/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
either = "1"
9+
hashbrown = "0.15"
910
itertools = "0.12"
1011
rustc_abi = { path = "../rustc_abi" }
1112
rustc_arena = { path = "../rustc_arena" }

0 commit comments

Comments
 (0)