Auto merge of #80475 - simonvandel:fix-77355, r=oli-obk
New mir-opt pass to simplify gotos with const values (reopening #77486) Reopening PR #77486 Fixes #77355 This pass optimizes the following sequence ```rust bb2: { _2 = const true; goto -> bb3; } bb3: { switchInt(_2) -> [false: bb4, otherwise: bb5]; } ``` into ```rust bb2: { _2 = const true; goto -> bb5; } ```
This commit is contained in:
commit
6b56603e35
22 changed files with 652 additions and 374 deletions
|
@ -1518,7 +1518,14 @@ pub enum StatementKind<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> StatementKind<'tcx> {
|
||||
pub fn as_assign_mut(&mut self) -> Option<&mut Box<(Place<'tcx>, Rvalue<'tcx>)>> {
|
||||
pub fn as_assign_mut(&mut self) -> Option<&mut (Place<'tcx>, Rvalue<'tcx>)> {
|
||||
match self {
|
||||
StatementKind::Assign(x) => Some(x),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_assign(&self) -> Option<&(Place<'tcx>, Rvalue<'tcx>)> {
|
||||
match self {
|
||||
StatementKind::Assign(x) => Some(x),
|
||||
_ => None,
|
||||
|
|
|
@ -407,6 +407,22 @@ impl<'tcx> TerminatorKind<'tcx> {
|
|||
| TerminatorKind::FalseUnwind { ref mut unwind, .. } => Some(unwind),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_switch(&self) -> Option<(&Operand<'tcx>, Ty<'tcx>, &SwitchTargets)> {
|
||||
match self {
|
||||
TerminatorKind::SwitchInt { discr, switch_ty, targets } => {
|
||||
Some((discr, switch_ty, targets))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_goto(&self) -> Option<BasicBlock> {
|
||||
match self {
|
||||
TerminatorKind::Goto { target } => Some(*target),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Debug for TerminatorKind<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue