Do not codegen overflow check when not required.

This commit is contained in:
Camille GILLOT 2023-02-08 21:17:29 +00:00
parent 3eb5c4581a
commit 4bd2ebc58b

View File

@ -568,8 +568,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// NOTE: Unlike binops, negation doesn't have its own
// checked operation, just a comparison with the minimum
// value, so we have to check for the assert message.
if !bx.check_overflow() {
if let AssertKind::OverflowNeg(_) = *msg {
if !bx.cx().check_overflow() {
if let AssertKind::OverflowNeg(_)
| AssertKind::Overflow(
mir::BinOp::Add
| mir::BinOp::Sub
| mir::BinOp::Mul
| mir::BinOp::Shl
| mir::BinOp::Shr,
..,
) = *msg
{
const_cond = Some(expected);
}
}