Add an InstCombine for redundant casts
This commit is contained in:
@@ -30,6 +30,7 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
|
||||
ctx.combine_bool_cmp(&statement.source_info, rvalue);
|
||||
ctx.combine_ref_deref(&statement.source_info, rvalue);
|
||||
ctx.combine_len(&statement.source_info, rvalue);
|
||||
ctx.combine_cast(&statement.source_info, rvalue);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -142,6 +143,14 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn combine_cast(&self, _source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
|
||||
if let Rvalue::Cast(_kind, operand, ty) = rvalue {
|
||||
if operand.ty(self.local_decls, self.tcx) == *ty {
|
||||
*rvalue = Rvalue::Use(operand.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn combine_primitive_clone(
|
||||
&self,
|
||||
terminator: &mut Terminator<'tcx>,
|
||||
|
||||
Reference in New Issue
Block a user