1
Fork 0

Add an InstCombine for redundant casts

This commit is contained in:
Ben Kimock 2023-02-19 15:50:00 -05:00
parent eebdfb55fc
commit 0e05280d75
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>,