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:
commit
4658210565
5 changed files with 80 additions and 0 deletions
|
@ -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>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue