Additional assumption to elide bounds check
This commit is contained in:
parent
85fbf49ce0
commit
c88b167f15
@ -327,13 +327,29 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||||||
if er.end != er.start
|
if er.end != er.start
|
||||||
&& scalar.valid_range.end() > scalar.valid_range.start()
|
&& scalar.valid_range.end() > scalar.valid_range.start()
|
||||||
{
|
{
|
||||||
// We want `table[e as usize]` to not
|
// We want `table[e as usize ± k]` to not
|
||||||
// have bound checks, and this is the most
|
// have bound checks, and this is the most
|
||||||
// convenient place to put the `assume`.
|
// convenient place to put the `assume`s.
|
||||||
let ll_t_in_const =
|
if *scalar.valid_range.start() > 0 {
|
||||||
|
let enum_value_lower_bound = bx
|
||||||
|
.cx()
|
||||||
|
.const_uint_big(ll_t_in, *scalar.valid_range.start());
|
||||||
|
let cmp_start = bx.icmp(
|
||||||
|
IntPredicate::IntUGE,
|
||||||
|
llval,
|
||||||
|
enum_value_lower_bound,
|
||||||
|
);
|
||||||
|
bx.assume(cmp_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
let enum_value_upper_bound =
|
||||||
bx.cx().const_uint_big(ll_t_in, *scalar.valid_range.end());
|
bx.cx().const_uint_big(ll_t_in, *scalar.valid_range.end());
|
||||||
let cmp = bx.icmp(IntPredicate::IntULE, llval, ll_t_in_const);
|
let cmp_end = bx.icmp(
|
||||||
bx.assume(cmp);
|
IntPredicate::IntULE,
|
||||||
|
llval,
|
||||||
|
enum_value_upper_bound,
|
||||||
|
);
|
||||||
|
bx.assume(cmp_end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user