Skip to content

Commit

Permalink
Simplify assert terminator only if condition evaluates to expected value
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Oct 21, 2020
1 parent 22e6b9c commit a9470d0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler/rustc_mir/src/transform/simplify_branches.rs
Expand Up @@ -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 }
}
Expand Down

0 comments on commit a9470d0

Please sign in to comment.