Rollup merge of #78198 - tmiasko:assert, r=davidtwco

Simplify assert terminator only if condition evaluates to expected value
This commit is contained in:
Jonas Schievink 2020-10-24 14:12:03 +02:00 committed by GitHub
commit 86c07a4955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,9 +49,10 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranches {
}
TerminatorKind::Assert {
target, cond: Operand::Constant(ref c), expected, ..
} if (c.literal.try_eval_bool(tcx, param_env) == Some(true)) == expected => {
TerminatorKind::Goto { target }
}
} => match c.literal.try_eval_bool(tcx, param_env) {
Some(v) if v == expected => TerminatorKind::Goto { target },
_ => continue,
},
TerminatorKind::FalseEdge { real_target, .. } => {
TerminatorKind::Goto { target: real_target }
}