Skip to content

Commit e7c502d

Browse files
committed
Auto merge of #109597 - cjgillot:gvn, r=oli-obk
Implement a global value numbering MIR optimization The aim of this pass is to avoid repeated computations by reusing past assignments. It is based on an analysis of SSA locals, in order to perform a restricted form of common subexpression elimination. By opportunity, this pass allows for some simplifications by combining assignments. For instance, this pass could be able to see through projections of aggregates to directly reuse the aggregate field (not in this PR). We handle references by assigning a different "provenance" index to each `Ref`/`AddressOf` rvalue. This ensure that we do not spuriously merge borrows that should not be merged. Meanwhile, we consider all the derefs of an immutable reference to a freeze type to give the same value: ```rust _a = *_b // _b is &Freeze _c = *_b // replaced by _c = _a ```
2 parents 7b4b1b0 + 901be42 commit e7c502d

32 files changed

+7204
-23
lines changed

compiler/rustc_middle/src/mir/syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ pub enum AggregateKind<'tcx> {
13331333
Generator(DefId, GenericArgsRef<'tcx>, hir::Movability),
13341334
}
13351335

1336-
#[derive(Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
1336+
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
13371337
pub enum NullOp<'tcx> {
13381338
/// Returns the size of a value of that type
13391339
SizeOf,

0 commit comments

Comments
 (0)