Add peephold optimization that simplifies Ne(_1, false) and Ne(false, _1) into _1

This was observed emitted from the MatchBranchSimplification pass.
This commit is contained in:
Simon Vandel Sillesen 2020-08-29 14:16:39 +02:00
parent ffaf158608
commit c2693db264
5 changed files with 128 additions and 2 deletions

View file

@ -1954,6 +1954,15 @@ impl<'tcx> Operand<'tcx> {
Operand::Constant(_) => None,
}
}
/// Returns the `Constant` that is the target of this `Operand`, or `None` if this `Operand` is a
/// place.
pub fn constant(&self) -> Option<&Constant<'tcx>> {
match self {
Operand::Constant(x) => Some(&**x),
Operand::Copy(_) | Operand::Move(_) => None,
}
}
}
///////////////////////////////////////////////////////////////////////////