]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir/src/transform/simplify_comparison_integral.rs
Rollup merge of #80327 - PankajChaudhary5:PankajChaudhary, r=GuillaumeGomez
[rust.git] / compiler / rustc_mir / src / transform / simplify_comparison_integral.rs
index 6372f8960ddb66f8f0aa64cbd4b03b6f1cf3adbe..ea56080c75216c96971ff01385e26fa4285c89a4 100644 (file)
 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;