Auto merge of #122610 - saethlin:assume-const, r= · rust-lang/rust@04d1404 (original) (raw)
`@@ -6,9 +6,15 @@ use super::FunctionCx;
`
6
6
`use super::LocalRef;
`
7
7
`use crate::traits::*;
`
8
8
``
``
9
`+
use std::ops::ControlFlow;
`
``
10
+
9
11
`impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
`
10
12
`#[instrument(level = "debug", skip(self, bx))]
`
11
``
`-
pub fn codegen_statement(&mut self, bx: &mut Bx, statement: &mir::Statement<'tcx>) {
`
``
13
`+
pub fn codegen_statement(
`
``
14
`+
&mut self,
`
``
15
`+
bx: &mut Bx,
`
``
16
`+
statement: &mir::Statement<'tcx>,
`
``
17
`+
) -> ControlFlow<()> {
`
12
18
`self.set_debug_loc(bx, statement.source_info);
`
13
19
`match statement.kind {
`
14
20
` mir::StatementKind::Assign(box (ref place, ref rvalue)) => {
`
`@@ -70,7 +76,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
`
70
76
` mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => {
`
71
77
`if !matches!(bx.tcx().sess.opts.optimize, OptLevel::No | OptLevel::Less) {
`
72
78
`let op_val = self.codegen_operand(bx, op);
`
73
``
`-
bx.assume(op_val.immediate());
`
``
79
`+
let imm = op_val.immediate();
`
``
80
`+
if let Some(value) = bx.const_to_opt_uint(imm) {
`
``
81
`+
if value == 0 {
`
``
82
`+
bx.unreachable();
`
``
83
`+
return ControlFlow::Break(());
`
``
84
`+
}
`
``
85
`+
} else {
`
``
86
`+
bx.assume(imm);
`
``
87
`+
}
`
74
88
`}
`
75
89
`}
`
76
90
` mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(
`
`@@ -97,5 +111,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
`
97
111
` | mir::StatementKind::PlaceMention(..)
`
98
112
` | mir::StatementKind::Nop => {}
`
99
113
`}
`
``
114
`+
ControlFlow::Continue(())
`
100
115
`}
`
101
116
`}
`