-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lower unchecked_div
/_rem
to MIR's BinOp::Div
/Rem
#112168
Lower unchecked_div
/_rem
to MIR's BinOp::Div
/Rem
#112168
Conversation
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
The MIR comment only mentions 0, not overflow. However the Miri implementation makes div and rem also UB on overflow. We should probably update the MIR comment then. |
This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras |
Updated the comments on |
@bors r+ |
…mpiler-errors Rollup of 6 pull requests Successful merges: - rust-lang#109609 (Separate AnonConst from ConstBlock in HIR.) - rust-lang#112166 (bootstrap: Rename profile = user to profile = dist) - rust-lang#112168 (Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem`) - rust-lang#112183 (Normalize anon consts in new solver) - rust-lang#112211 (pass `--lib` to `x doc`) - rust-lang#112223 (Don't ICE in new solver when auto traits have associated types) r? `@ghost` `@rustbot` modify labels: rollup
…o-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.
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, demo), 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 MIRBinOp::Add
and such, as all these cases turn into ordinaryRvalue::BinaryOp
s.