Rollup merge of #108246 - saethlin:instcombine-redundant-casts, r=compiler-errors

Add an InstCombine for redundant casts

`@rustbot` label +A-mir-opt
This commit is contained in:
Guillaume Gomez 2023-02-22 10:35:09 +01:00 committed by GitHub
commit 4658210565
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 0 deletions

View file

@ -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>,