Skip to content

Commit 4ecd45a

Browse files
Rollup merge of rust-lang#112168 - scottmcm:lower-div-rem-unchecked-to-mir, r=oli-obk
Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem` As described in <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BinOp.html#variant.Div>, the ordinary `BinOp`s for these are already UB for division by zero ([or overflow](https://llvm.org/docs/LangRef.html#sdiv-instruction), [demo](https://rust.godbolt.org/z/71e7P7Exh)), as MIR building is responsible for inserting code to panic for those cases regardless of whether the overflow checks are enabled. So we can lower these in the same arm that lowers `wrapping_add` to MIR `BinOp::Add` and such, as all these cases turn into ordinary `Rvalue::BinaryOp`s.
2 parents fcd93ac + 919da2f commit 4ecd45a

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/intrinsics/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
475475
sym::unchecked_add
476476
| sym::unchecked_sub
477477
| sym::unchecked_mul
478-
| sym::unchecked_div
479478
| sym::exact_div
480-
| sym::unchecked_rem
481479
| sym::unchecked_shl
482480
| sym::unchecked_shr => {
483481
intrinsic_args!(fx, args => (x, y); intrinsic);
@@ -487,8 +485,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
487485
sym::unchecked_add => BinOp::Add,
488486
sym::unchecked_sub => BinOp::Sub,
489487
sym::unchecked_mul => BinOp::Mul,
490-
sym::unchecked_div | sym::exact_div => BinOp::Div,
491-
sym::unchecked_rem => BinOp::Rem,
488+
sym::exact_div => BinOp::Div,
492489
sym::unchecked_shl => BinOp::Shl,
493490
sym::unchecked_shr => BinOp::Shr,
494491
_ => unreachable!(),

0 commit comments

Comments
 (0)