11//! Performs various peephole optimizations.
22
33use crate :: transform:: { MirPass , MirSource } ;
4- use rustc_data_structures:: fx:: FxHashMap ;
4+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
5+ use rustc_hir:: Mutability ;
56use rustc_index:: vec:: Idx ;
67use rustc_middle:: mir:: visit:: { MutVisitor , Visitor } ;
78use rustc_middle:: mir:: {
8- Body , Constant , Local , Location , Mutability , Operand , Place , PlaceRef , ProjectionElem , Rvalue ,
9+ Body , Constant , Local , Location , Operand , Place , PlaceRef , ProjectionElem , Rvalue ,
910} ;
1011use rustc_middle:: ty:: { self , TyCtxt } ;
1112use std:: mem;
@@ -39,7 +40,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
3940 }
4041
4142 fn visit_rvalue ( & mut self , rvalue : & mut Rvalue < ' tcx > , location : Location ) {
42- if let Some ( mtbl ) = self . optimizations . and_stars . remove ( & location) {
43+ if self . optimizations . and_stars . remove ( & location) {
4344 debug ! ( "replacing `&*`: {:?}" , rvalue) ;
4445 let new_place = match rvalue {
4546 Rvalue :: Ref ( _, _, place) => {
@@ -57,10 +58,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
5758 }
5859 _ => bug ! ( "Detected `&*` but didn't find `&*`!" ) ,
5960 } ;
60- * rvalue = Rvalue :: Use ( match mtbl {
61- Mutability :: Mut => Operand :: Move ( new_place) ,
62- Mutability :: Not => Operand :: Copy ( new_place) ,
63- } ) ;
61+ * rvalue = Rvalue :: Use ( Operand :: Copy ( new_place) )
6462 }
6563
6664 if let Some ( constant) = self . optimizations . arrays_lengths . remove ( & location) {
@@ -93,8 +91,8 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
9391 {
9492 // The dereferenced place must have type `&_`.
9593 let ty = Place :: ty_from ( local, proj_base, self . body , self . tcx ) . ty ;
96- if let ty:: Ref ( _, _, mtbl ) = ty. kind {
97- self . optimizations . and_stars . insert ( location, mtbl ) ;
94+ if let ty:: Ref ( _, _, Mutability :: Not ) = ty. kind {
95+ self . optimizations . and_stars . insert ( location) ;
9896 }
9997 }
10098 }
@@ -114,6 +112,6 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
114112
115113#[ derive( Default ) ]
116114struct OptimizationList < ' tcx > {
117- and_stars : FxHashMap < Location , Mutability > ,
115+ and_stars : FxHashSet < Location > ,
118116 arrays_lengths : FxHashMap < Location , Constant < ' tcx > > ,
119117}
0 commit comments