pub struct SimplifyComparisonIntegral;
impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
- fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
trace!("Running SimplifyComparisonIntegral on {:?}", body.source);
let helper = OptimizationFinder { body };
let opts = helper.find_optimizations();
let mut storage_deads_to_insert = vec![];
let mut storage_deads_to_remove: Vec<(usize, BasicBlock)> = vec![];
+ let param_env = tcx.param_env(body.source.def_id());
for opt in opts {
trace!("SUCCESS: Applying {:?}", opt);
// replace terminator with a switchInt that switches on the integer directly
let bbs = &mut body.basic_blocks_mut();
let bb = &mut bbs[opt.bb_idx];
- // We only use the bits for the untyped, not length checked `values` field. Thus we are
- // not using any of the convenience wrappers here and directly access the bits.
let new_value = match opt.branch_value_scalar {
- Scalar::Raw { data, .. } => data,
+ Scalar::Int(int) => {
+ let layout = tcx
+ .layout_of(param_env.and(opt.branch_value_ty))
+ .expect("if we have an evaluated constant we must know the layout");
+ int.assert_bits(layout.size)
+ }
Scalar::Ptr(_) => continue,
};
const FALSE: u128 = 0;