Skip to content

Commit cb2b3ea

Browse files
committed
Use size of recv instead of constant 32
1 parent 7008cce commit cb2b3ea

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

compiler/rustc_mir_transform/src/simplify_pow_of_two.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ impl<'tcx> MirPass<'tcx> for SimplifyPowOfTwo {
103103
);
104104

105105
let num_shl = tcx.mk_place_field(checked_mul.into(), FieldIdx::from_u32(0), exp_ty);
106-
let mul_result =
107-
tcx.mk_place_field(checked_mul.into(), FieldIdx::from_u32(1), Ty::new_bool(tcx));
106+
let mul_result = tcx.mk_place_field(
107+
checked_mul.into(),
108+
FieldIdx::from_u32(1),
109+
Ty::new_bool(tcx),
110+
);
108111
let shl_result = patch.new_temp(Ty::new_bool(tcx), span);
109112

110113
// Whether the shl will overflow, if so we return 0
@@ -118,7 +121,10 @@ impl<'tcx> MirPass<'tcx> for SimplifyPowOfTwo {
118121
Operand::Constant(Box::new(Constant {
119122
span,
120123
user_ty: None,
121-
literal: ConstantKind::Val(ConstValue::from_u32(32), exp_ty),
124+
literal: ConstantKind::Val(
125+
ConstValue::from_u32(recv_int.size().bits() as u32),
126+
exp_ty,
127+
),
122128
})),
123129
)),
124130
),
@@ -171,11 +177,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyPowOfTwo {
171177
patch.add_assign(
172178
loc,
173179
shl.into(),
174-
Rvalue::Cast(
175-
CastKind::IntToInt,
176-
Operand::Copy(shl_exp_ty.into()),
177-
recv_ty,
178-
),
180+
Rvalue::Cast(CastKind::IntToInt, Operand::Copy(shl_exp_ty.into()), recv_ty),
179181
);
180182

181183
patch.add_assign(
@@ -221,7 +223,10 @@ impl<'tcx> MirPass<'tcx> for SimplifyPowOfTwo {
221223
overflowed.into(),
222224
Rvalue::BinaryOp(
223225
BinOp::BitAnd,
224-
Box::new((Operand::Copy(shl_eq_shr.into()), Operand::Copy(shl_result.into()))),
226+
Box::new((
227+
Operand::Copy(shl_eq_shr.into()),
228+
Operand::Copy(shl_result.into()),
229+
)),
225230
),
226231
);
227232

@@ -237,7 +242,10 @@ impl<'tcx> MirPass<'tcx> for SimplifyPowOfTwo {
237242
Operand::Constant(Box::new(Constant {
238243
span,
239244
user_ty: None,
240-
literal: ConstantKind::Val(ConstValue::Scalar(Scalar::from_u32(1)), exp_ty),
245+
literal: ConstantKind::Val(
246+
ConstValue::Scalar(Scalar::from_u32(1)),
247+
exp_ty,
248+
),
241249
})),
242250
Operand::Copy(num_shl.into()),
243251
)),

0 commit comments

Comments
 (0)