mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Rollup merge of #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.
This commit is contained in:
commit
5460f92a0f
@ -475,9 +475,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
sym::unchecked_add
|
||||
| sym::unchecked_sub
|
||||
| sym::unchecked_mul
|
||||
| sym::unchecked_div
|
||||
| sym::exact_div
|
||||
| sym::unchecked_rem
|
||||
| sym::unchecked_shl
|
||||
| sym::unchecked_shr => {
|
||||
intrinsic_args!(fx, args => (x, y); intrinsic);
|
||||
@ -487,8 +485,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
sym::unchecked_add => BinOp::Add,
|
||||
sym::unchecked_sub => BinOp::Sub,
|
||||
sym::unchecked_mul => BinOp::Mul,
|
||||
sym::unchecked_div | sym::exact_div => BinOp::Div,
|
||||
sym::unchecked_rem => BinOp::Rem,
|
||||
sym::exact_div => BinOp::Div,
|
||||
sym::unchecked_shl => BinOp::Shl,
|
||||
sym::unchecked_shr => BinOp::Shr,
|
||||
_ => unreachable!(),
|
||||
|
@ -211,8 +211,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
args[1].val.unaligned_volatile_store(bx, dst);
|
||||
return;
|
||||
}
|
||||
| sym::unchecked_div
|
||||
| sym::unchecked_rem
|
||||
| sym::unchecked_shl
|
||||
| sym::unchecked_shr
|
||||
| sym::unchecked_add
|
||||
@ -229,20 +227,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
bx.exactudiv(args[0].immediate(), args[1].immediate())
|
||||
}
|
||||
}
|
||||
sym::unchecked_div => {
|
||||
if signed {
|
||||
bx.sdiv(args[0].immediate(), args[1].immediate())
|
||||
} else {
|
||||
bx.udiv(args[0].immediate(), args[1].immediate())
|
||||
}
|
||||
}
|
||||
sym::unchecked_rem => {
|
||||
if signed {
|
||||
bx.srem(args[0].immediate(), args[1].immediate())
|
||||
} else {
|
||||
bx.urem(args[0].immediate(), args[1].immediate())
|
||||
}
|
||||
}
|
||||
sym::unchecked_shl => bx.shl(args[0].immediate(), args[1].immediate()),
|
||||
sym::unchecked_shr => {
|
||||
if signed {
|
||||
|
@ -238,9 +238,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
| sym::unchecked_shr
|
||||
| sym::unchecked_add
|
||||
| sym::unchecked_sub
|
||||
| sym::unchecked_mul
|
||||
| sym::unchecked_div
|
||||
| sym::unchecked_rem => {
|
||||
| sym::unchecked_mul => {
|
||||
let l = self.read_immediate(&args[0])?;
|
||||
let r = self.read_immediate(&args[1])?;
|
||||
let bin_op = match intrinsic_name {
|
||||
@ -249,8 +247,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
sym::unchecked_add => BinOp::Add,
|
||||
sym::unchecked_sub => BinOp::Sub,
|
||||
sym::unchecked_mul => BinOp::Mul,
|
||||
sym::unchecked_div => BinOp::Div,
|
||||
sym::unchecked_rem => BinOp::Rem,
|
||||
_ => bug!(),
|
||||
};
|
||||
let (val, overflowed, _ty) = self.overflowing_binary_op(bin_op, &l, &r)?;
|
||||
|
@ -1273,13 +1273,18 @@ pub enum BinOp {
|
||||
Mul,
|
||||
/// The `/` operator (division)
|
||||
///
|
||||
/// Division by zero is UB, because the compiler should have inserted checks
|
||||
/// prior to this.
|
||||
/// For integer types, division by zero is UB, as is `MIN / -1` for signed.
|
||||
/// The compiler should have inserted checks prior to this.
|
||||
///
|
||||
/// Floating-point division by zero is safe, and does not need guards.
|
||||
Div,
|
||||
/// The `%` operator (modulus)
|
||||
///
|
||||
/// Using zero as the modulus (second operand) is UB, because the compiler
|
||||
/// should have inserted checks prior to this.
|
||||
/// For integer types, using zero as the modulus (second operand) is UB,
|
||||
/// as is `MIN % -1` for signed.
|
||||
/// The compiler should have inserted checks prior to this.
|
||||
///
|
||||
/// Floating-point remainder by zero is safe, and does not need guards.
|
||||
Rem,
|
||||
/// The `^` operator (bitwise xor)
|
||||
BitXor,
|
||||
|
@ -82,30 +82,35 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
||||
drop(args);
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::wrapping_add | sym::wrapping_sub | sym::wrapping_mul => {
|
||||
if let Some(target) = *target {
|
||||
let lhs;
|
||||
let rhs;
|
||||
{
|
||||
let mut args = args.drain(..);
|
||||
lhs = args.next().unwrap();
|
||||
rhs = args.next().unwrap();
|
||||
}
|
||||
let bin_op = match intrinsic_name {
|
||||
sym::wrapping_add => BinOp::Add,
|
||||
sym::wrapping_sub => BinOp::Sub,
|
||||
sym::wrapping_mul => BinOp::Mul,
|
||||
_ => bug!("unexpected intrinsic"),
|
||||
};
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
*destination,
|
||||
Rvalue::BinaryOp(bin_op, Box::new((lhs, rhs))),
|
||||
))),
|
||||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
sym::wrapping_add
|
||||
| sym::wrapping_sub
|
||||
| sym::wrapping_mul
|
||||
| sym::unchecked_div
|
||||
| sym::unchecked_rem => {
|
||||
let target = target.unwrap();
|
||||
let lhs;
|
||||
let rhs;
|
||||
{
|
||||
let mut args = args.drain(..);
|
||||
lhs = args.next().unwrap();
|
||||
rhs = args.next().unwrap();
|
||||
}
|
||||
let bin_op = match intrinsic_name {
|
||||
sym::wrapping_add => BinOp::Add,
|
||||
sym::wrapping_sub => BinOp::Sub,
|
||||
sym::wrapping_mul => BinOp::Mul,
|
||||
sym::unchecked_div => BinOp::Div,
|
||||
sym::unchecked_rem => BinOp::Rem,
|
||||
_ => bug!("unexpected intrinsic"),
|
||||
};
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
*destination,
|
||||
Rvalue::BinaryOp(bin_op, Box::new((lhs, rhs))),
|
||||
))),
|
||||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
|
||||
if let Some(target) = *target {
|
||||
|
@ -7,7 +7,7 @@
|
||||
bb0: {
|
||||
- _0 = std::intrinsics::min_align_of::<T>() -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:42
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:21:5: 21:40
|
||||
- // + span: $DIR/lower_intrinsics.rs:27:5: 27:40
|
||||
- // + literal: Const { ty: extern "rust-intrinsic" fn() -> usize {std::intrinsics::min_align_of::<T>}, val: Value(<ZST>) }
|
||||
+ _0 = AlignOf(T); // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:42
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:42
|
||||
|
@ -11,7 +11,7 @@
|
||||
StorageLive(_1); // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38
|
||||
- _1 = std::intrinsics::assume(const true) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:106:9: 106:32
|
||||
- // + span: $DIR/lower_intrinsics.rs:112:9: 112:32
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(bool) {std::intrinsics::assume}, val: Value(<ZST>) }
|
||||
+ assume(const true); // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38
|
||||
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:38
|
||||
|
@ -31,7 +31,7 @@
|
||||
_3 = &(*_4); // scope 0 at $DIR/lower_intrinsics.rs:+1:42: +1:44
|
||||
- _2 = discriminant_value::<T>(move _3) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:45
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:82:5: 82:41
|
||||
- // + span: $DIR/lower_intrinsics.rs:88:5: 88:41
|
||||
- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a T) -> <T as DiscriminantKind>::Discriminant {discriminant_value::<T>}, val: Value(<ZST>) }
|
||||
+ _2 = discriminant((*_3)); // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:45
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:45
|
||||
@ -46,13 +46,13 @@
|
||||
StorageLive(_7); // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
|
||||
_19 = const _; // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
|
||||
// mir::Constant
|
||||
// + span: $DIR/lower_intrinsics.rs:83:42: 83:44
|
||||
// + span: $DIR/lower_intrinsics.rs:89:42: 89:44
|
||||
// + literal: Const { ty: &i32, val: Unevaluated(discriminant, [T], Some(promoted[2])) }
|
||||
_7 = &(*_19); // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
|
||||
_6 = &(*_7); // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
|
||||
- _5 = discriminant_value::<i32>(move _6) -> [return: bb2, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+2:5: +2:45
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:83:5: 83:41
|
||||
- // + span: $DIR/lower_intrinsics.rs:89:5: 89:41
|
||||
- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a i32) -> <i32 as DiscriminantKind>::Discriminant {discriminant_value::<i32>}, val: Value(<ZST>) }
|
||||
+ _5 = discriminant((*_6)); // scope 0 at $DIR/lower_intrinsics.rs:+2:5: +2:45
|
||||
+ goto -> bb2; // scope 0 at $DIR/lower_intrinsics.rs:+2:5: +2:45
|
||||
@ -67,13 +67,13 @@
|
||||
StorageLive(_11); // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
|
||||
_18 = const _; // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
|
||||
// mir::Constant
|
||||
// + span: $DIR/lower_intrinsics.rs:84:42: 84:45
|
||||
// + span: $DIR/lower_intrinsics.rs:90:42: 90:45
|
||||
// + literal: Const { ty: &(), val: Unevaluated(discriminant, [T], Some(promoted[1])) }
|
||||
_11 = &(*_18); // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
|
||||
_10 = &(*_11); // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
|
||||
- _9 = discriminant_value::<()>(move _10) -> [return: bb3, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+3:5: +3:46
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:84:5: 84:41
|
||||
- // + span: $DIR/lower_intrinsics.rs:90:5: 90:41
|
||||
- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a ()) -> <() as DiscriminantKind>::Discriminant {discriminant_value::<()>}, val: Value(<ZST>) }
|
||||
+ _9 = discriminant((*_10)); // scope 0 at $DIR/lower_intrinsics.rs:+3:5: +3:46
|
||||
+ goto -> bb3; // scope 0 at $DIR/lower_intrinsics.rs:+3:5: +3:46
|
||||
@ -88,13 +88,13 @@
|
||||
StorageLive(_15); // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
|
||||
_17 = const _; // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
|
||||
// mir::Constant
|
||||
// + span: $DIR/lower_intrinsics.rs:85:42: 85:47
|
||||
// + span: $DIR/lower_intrinsics.rs:91:42: 91:47
|
||||
// + literal: Const { ty: &E, val: Unevaluated(discriminant, [T], Some(promoted[0])) }
|
||||
_15 = &(*_17); // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
|
||||
_14 = &(*_15); // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
|
||||
- _13 = discriminant_value::<E>(move _14) -> [return: bb4, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+4:5: +4:48
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:85:5: 85:41
|
||||
- // + span: $DIR/lower_intrinsics.rs:91:5: 91:41
|
||||
- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a E) -> <E as DiscriminantKind>::Discriminant {discriminant_value::<E>}, val: Value(<ZST>) }
|
||||
+ _13 = discriminant((*_14)); // scope 0 at $DIR/lower_intrinsics.rs:+4:5: +4:48
|
||||
+ goto -> bb4; // scope 0 at $DIR/lower_intrinsics.rs:+4:5: +4:48
|
||||
|
@ -49,7 +49,7 @@
|
||||
StorageDead(_9); // scope 3 at $DIR/lower_intrinsics.rs:+4:90: +4:91
|
||||
- _3 = copy_nonoverlapping::<i32>(move _4, move _8, const 0_usize) -> [return: bb1, unwind unreachable]; // scope 3 at $DIR/lower_intrinsics.rs:+4:9: +4:95
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:99:9: 99:28
|
||||
- // + span: $DIR/lower_intrinsics.rs:105:9: 105:28
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const i32, *mut i32, usize) {copy_nonoverlapping::<i32>}, val: Value(<ZST>) }
|
||||
+ copy_nonoverlapping(dst = move _8, src = move _4, count = const 0_usize); // scope 3 at $DIR/lower_intrinsics.rs:+4:9: +4:95
|
||||
+ goto -> bb1; // scope 3 at $DIR/lower_intrinsics.rs:+4:9: +4:95
|
||||
|
@ -11,7 +11,7 @@
|
||||
_2 = move _1; // scope 0 at $DIR/lower_intrinsics.rs:+1:30: +1:31
|
||||
- _0 = std::intrinsics::forget::<T>(move _2) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:32
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:26:5: 26:29
|
||||
- // + span: $DIR/lower_intrinsics.rs:32:5: 32:29
|
||||
- // + literal: Const { ty: extern "rust-intrinsic" fn(T) {std::intrinsics::forget::<T>}, val: Value(<ZST>) }
|
||||
+ _0 = const (); // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:32
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:32
|
||||
|
@ -13,7 +13,7 @@
|
||||
StorageLive(_1); // scope 0 at $DIR/lower_intrinsics.rs:+2:9: +2:18
|
||||
_1 = std::intrinsics::size_of::<T>; // scope 0 at $DIR/lower_intrinsics.rs:+2:21: +2:51
|
||||
// mir::Constant
|
||||
// + span: $DIR/lower_intrinsics.rs:37:21: 37:51
|
||||
// + span: $DIR/lower_intrinsics.rs:43:21: 43:51
|
||||
// + literal: Const { ty: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}, val: Value(<ZST>) }
|
||||
StorageLive(_2); // scope 1 at $DIR/lower_intrinsics.rs:+3:5: +3:14
|
||||
_2 = _1; // scope 1 at $DIR/lower_intrinsics.rs:+3:5: +3:14
|
||||
|
@ -24,7 +24,7 @@
|
||||
_4 = &raw const (*_1); // scope 1 at $DIR/lower_intrinsics.rs:+2:55: +2:56
|
||||
- _3 = option_payload_ptr::<usize>(move _4) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+2:18: +2:57
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:137:18: 137:54
|
||||
- // + span: $DIR/lower_intrinsics.rs:143:18: 143:54
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const Option<usize>) -> *const usize {option_payload_ptr::<usize>}, val: Value(<ZST>) }
|
||||
+ _3 = &raw const (((*_4) as Some).0: usize); // scope 1 at $DIR/lower_intrinsics.rs:+2:18: +2:57
|
||||
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+2:18: +2:57
|
||||
@ -37,7 +37,7 @@
|
||||
_6 = &raw const (*_2); // scope 2 at $DIR/lower_intrinsics.rs:+3:55: +3:56
|
||||
- _5 = option_payload_ptr::<String>(move _6) -> [return: bb2, unwind unreachable]; // scope 2 at $DIR/lower_intrinsics.rs:+3:18: +3:57
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:138:18: 138:54
|
||||
- // + span: $DIR/lower_intrinsics.rs:144:18: 144:54
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const Option<String>) -> *const String {option_payload_ptr::<String>}, val: Value(<ZST>) }
|
||||
+ _5 = &raw const (((*_6) as Some).0: std::string::String); // scope 2 at $DIR/lower_intrinsics.rs:+3:18: +3:57
|
||||
+ goto -> bb2; // scope 2 at $DIR/lower_intrinsics.rs:+3:18: +3:57
|
||||
|
@ -15,7 +15,7 @@
|
||||
_4 = _2; // scope 0 at $DIR/lower_intrinsics.rs:+1:33: +1:34
|
||||
- _0 = offset::<*const i32, isize>(move _3, move _4) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:35
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:144:5: 144:29
|
||||
- // + span: $DIR/lower_intrinsics.rs:150:5: 150:29
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const i32, isize) -> *const i32 {offset::<*const i32, isize>}, val: Value(<ZST>) }
|
||||
+ _0 = Offset(move _3, move _4); // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:35
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:35
|
||||
|
@ -13,7 +13,7 @@
|
||||
_2 = &raw const (*_1); // scope 1 at $DIR/lower_intrinsics.rs:+1:46: +1:47
|
||||
- _0 = read_via_copy::<i32>(move _2) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:119:14: 119:45
|
||||
- // + span: $DIR/lower_intrinsics.rs:125:14: 125:45
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const i32) -> i32 {read_via_copy::<i32>}, val: Value(<ZST>) }
|
||||
+ _0 = (*_2); // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
|
||||
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
|
||||
|
@ -13,7 +13,7 @@
|
||||
_2 = &raw const (*_1); // scope 1 at $DIR/lower_intrinsics.rs:+1:46: +1:47
|
||||
- _0 = read_via_copy::<Never>(move _2) -> unwind unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:124:14: 124:45
|
||||
- // + span: $DIR/lower_intrinsics.rs:130:14: 130:45
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*const Never) -> Never {read_via_copy::<Never>}, val: Value(<ZST>) }
|
||||
+ unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:48
|
||||
}
|
||||
|
@ -11,6 +11,12 @@ pub fn wrapping(a: i32, b: i32) {
|
||||
let _z = core::intrinsics::wrapping_mul(a, b);
|
||||
}
|
||||
|
||||
// EMIT_MIR lower_intrinsics.unchecked.LowerIntrinsics.diff
|
||||
pub unsafe fn unchecked(a: i32, b: i32) {
|
||||
let _x = core::intrinsics::unchecked_div(a, b);
|
||||
let _y = core::intrinsics::unchecked_rem(a, b);
|
||||
}
|
||||
|
||||
// EMIT_MIR lower_intrinsics.size_of.LowerIntrinsics.diff
|
||||
pub fn size_of<T>() -> usize {
|
||||
core::intrinsics::size_of::<T>()
|
||||
|
@ -7,7 +7,7 @@
|
||||
bb0: {
|
||||
- _0 = std::intrinsics::size_of::<T>() -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:37
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:16:5: 16:35
|
||||
- // + span: $DIR/lower_intrinsics.rs:22:5: 22:35
|
||||
- // + literal: Const { ty: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}, val: Value(<ZST>) }
|
||||
+ _0 = SizeOf(T); // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:37
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:37
|
||||
|
@ -13,7 +13,7 @@
|
||||
_2 = _1; // scope 1 at $DIR/lower_intrinsics.rs:+1:34: +1:35
|
||||
- _0 = transmute::<std::cmp::Ordering, i8>(move _2) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:36
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:43:14: 43:33
|
||||
- // + span: $DIR/lower_intrinsics.rs:49:14: 49:33
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(std::cmp::Ordering) -> i8 {transmute::<std::cmp::Ordering, i8>}, val: Value(<ZST>) }
|
||||
+ _0 = move _2 as i8 (Transmute); // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:36
|
||||
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:36
|
||||
|
@ -13,7 +13,7 @@
|
||||
_2 = _1; // scope 1 at $DIR/lower_intrinsics.rs:+1:34: +1:35
|
||||
- _0 = transmute::<&T, *const T>(move _2) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:36
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:53:14: 53:33
|
||||
- // + span: $DIR/lower_intrinsics.rs:59:14: 59:33
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&T) -> *const T {transmute::<&T, *const T>}, val: Value(<ZST>) }
|
||||
+ _0 = move _2 as *const T (Transmute); // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:36
|
||||
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:36
|
||||
|
@ -12,7 +12,7 @@
|
||||
StorageLive(_1); // scope 0 at $DIR/lower_intrinsics.rs:+1:9: +1:10
|
||||
- _1 = transmute::<usize, Box<Never>>(const 1_usize) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:25: +1:52
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:70:25: 70:44
|
||||
- // + span: $DIR/lower_intrinsics.rs:76:25: 76:44
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(usize) -> Box<Never> {transmute::<usize, Box<Never>>}, val: Value(<ZST>) }
|
||||
+ _1 = const 1_usize as std::boxed::Box<Never> (Transmute); // scope 0 at $DIR/lower_intrinsics.rs:+1:25: +1:52
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:25: +1:52
|
||||
|
@ -12,7 +12,7 @@
|
||||
StorageLive(_1); // scope 0 at $DIR/lower_intrinsics.rs:+1:9: +1:10
|
||||
- _1 = transmute::<usize, &mut Never>(const 1_usize) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:25: +1:52
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:64:25: 64:44
|
||||
- // + span: $DIR/lower_intrinsics.rs:70:25: 70:44
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(usize) -> &mut Never {transmute::<usize, &mut Never>}, val: Value(<ZST>) }
|
||||
+ _1 = const 1_usize as &mut Never (Transmute); // scope 0 at $DIR/lower_intrinsics.rs:+1:25: +1:52
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:25: +1:52
|
||||
|
@ -12,7 +12,7 @@
|
||||
StorageLive(_1); // scope 0 at $DIR/lower_intrinsics.rs:+1:9: +1:10
|
||||
- _1 = transmute::<usize, &Never>(const 1_usize) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:21: +1:48
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:58:21: 58:40
|
||||
- // + span: $DIR/lower_intrinsics.rs:64:21: 64:40
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(usize) -> &Never {transmute::<usize, &Never>}, val: Value(<ZST>) }
|
||||
+ _1 = const 1_usize as &Never (Transmute); // scope 0 at $DIR/lower_intrinsics.rs:+1:21: +1:48
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:21: +1:48
|
||||
|
@ -13,7 +13,7 @@
|
||||
_2 = _1; // scope 1 at $DIR/lower_intrinsics.rs:+1:47: +1:48
|
||||
- _0 = transmute::<(), Never>(move _2) -> unwind unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:49
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:48:14: 48:46
|
||||
- // + span: $DIR/lower_intrinsics.rs:54:14: 54:46
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(()) -> Never {transmute::<(), Never>}, val: Value(<ZST>) }
|
||||
+ _0 = move _2 as Never (Transmute); // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:49
|
||||
+ unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:49
|
||||
|
@ -0,0 +1,60 @@
|
||||
- // MIR for `unchecked` before LowerIntrinsics
|
||||
+ // MIR for `unchecked` after LowerIntrinsics
|
||||
|
||||
fn unchecked(_1: i32, _2: i32) -> () {
|
||||
debug a => _1; // in scope 0 at $DIR/lower_intrinsics.rs:+0:25: +0:26
|
||||
debug b => _2; // in scope 0 at $DIR/lower_intrinsics.rs:+0:33: +0:34
|
||||
let mut _0: (); // return place in scope 0 at $DIR/lower_intrinsics.rs:+0:41: +0:41
|
||||
let _3: i32; // in scope 0 at $DIR/lower_intrinsics.rs:+1:9: +1:11
|
||||
let mut _4: i32; // in scope 0 at $DIR/lower_intrinsics.rs:+1:46: +1:47
|
||||
let mut _5: i32; // in scope 0 at $DIR/lower_intrinsics.rs:+1:49: +1:50
|
||||
let mut _7: i32; // in scope 0 at $DIR/lower_intrinsics.rs:+2:46: +2:47
|
||||
let mut _8: i32; // in scope 0 at $DIR/lower_intrinsics.rs:+2:49: +2:50
|
||||
scope 1 {
|
||||
debug _x => _3; // in scope 1 at $DIR/lower_intrinsics.rs:+1:9: +1:11
|
||||
let _6: i32; // in scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:11
|
||||
scope 2 {
|
||||
debug _y => _6; // in scope 2 at $DIR/lower_intrinsics.rs:+2:9: +2:11
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_3); // scope 0 at $DIR/lower_intrinsics.rs:+1:9: +1:11
|
||||
StorageLive(_4); // scope 0 at $DIR/lower_intrinsics.rs:+1:46: +1:47
|
||||
_4 = _1; // scope 0 at $DIR/lower_intrinsics.rs:+1:46: +1:47
|
||||
StorageLive(_5); // scope 0 at $DIR/lower_intrinsics.rs:+1:49: +1:50
|
||||
_5 = _2; // scope 0 at $DIR/lower_intrinsics.rs:+1:49: +1:50
|
||||
- _3 = unchecked_div::<i32>(move _4, move _5) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:51
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:16:14: 16:45
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(i32, i32) -> i32 {unchecked_div::<i32>}, val: Value(<ZST>) }
|
||||
+ _3 = Div(move _4, move _5); // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:51
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:51
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_5); // scope 0 at $DIR/lower_intrinsics.rs:+1:50: +1:51
|
||||
StorageDead(_4); // scope 0 at $DIR/lower_intrinsics.rs:+1:50: +1:51
|
||||
StorageLive(_6); // scope 1 at $DIR/lower_intrinsics.rs:+2:9: +2:11
|
||||
StorageLive(_7); // scope 1 at $DIR/lower_intrinsics.rs:+2:46: +2:47
|
||||
_7 = _1; // scope 1 at $DIR/lower_intrinsics.rs:+2:46: +2:47
|
||||
StorageLive(_8); // scope 1 at $DIR/lower_intrinsics.rs:+2:49: +2:50
|
||||
_8 = _2; // scope 1 at $DIR/lower_intrinsics.rs:+2:49: +2:50
|
||||
- _6 = unchecked_rem::<i32>(move _7, move _8) -> [return: bb2, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:51
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:17:14: 17:45
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(i32, i32) -> i32 {unchecked_rem::<i32>}, val: Value(<ZST>) }
|
||||
+ _6 = Rem(move _7, move _8); // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:51
|
||||
+ goto -> bb2; // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:51
|
||||
}
|
||||
|
||||
bb2: {
|
||||
StorageDead(_8); // scope 1 at $DIR/lower_intrinsics.rs:+2:50: +2:51
|
||||
StorageDead(_7); // scope 1 at $DIR/lower_intrinsics.rs:+2:50: +2:51
|
||||
_0 = const (); // scope 0 at $DIR/lower_intrinsics.rs:+0:41: +3:2
|
||||
StorageDead(_6); // scope 1 at $DIR/lower_intrinsics.rs:+3:1: +3:2
|
||||
StorageDead(_3); // scope 0 at $DIR/lower_intrinsics.rs:+3:1: +3:2
|
||||
return; // scope 0 at $DIR/lower_intrinsics.rs:+3:2: +3:2
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
StorageLive(_2); // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:45
|
||||
- _2 = std::intrinsics::unreachable() -> unwind unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:45
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:31:14: 31:43
|
||||
- // + span: $DIR/lower_intrinsics.rs:37:14: 37:43
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn() -> ! {std::intrinsics::unreachable}, val: Value(<ZST>) }
|
||||
+ unreachable; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:45
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
_5 = _2; // scope 0 at $DIR/lower_intrinsics.rs:+1:53: +1:54
|
||||
- _3 = add_with_overflow::<i32>(move _4, move _5) -> [return: bb1, unwind unreachable]; // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:55
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:112:14: 112:49
|
||||
- // + span: $DIR/lower_intrinsics.rs:118:14: 118:49
|
||||
- // + literal: Const { ty: extern "rust-intrinsic" fn(i32, i32) -> (i32, bool) {add_with_overflow::<i32>}, val: Value(<ZST>) }
|
||||
+ _3 = CheckedAdd(move _4, move _5); // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:55
|
||||
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:14: +1:55
|
||||
@ -48,7 +48,7 @@
|
||||
_8 = _2; // scope 1 at $DIR/lower_intrinsics.rs:+2:53: +2:54
|
||||
- _6 = sub_with_overflow::<i32>(move _7, move _8) -> [return: bb2, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:55
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:113:14: 113:49
|
||||
- // + span: $DIR/lower_intrinsics.rs:119:14: 119:49
|
||||
- // + literal: Const { ty: extern "rust-intrinsic" fn(i32, i32) -> (i32, bool) {sub_with_overflow::<i32>}, val: Value(<ZST>) }
|
||||
+ _6 = CheckedSub(move _7, move _8); // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:55
|
||||
+ goto -> bb2; // scope 1 at $DIR/lower_intrinsics.rs:+2:14: +2:55
|
||||
@ -64,7 +64,7 @@
|
||||
_11 = _2; // scope 2 at $DIR/lower_intrinsics.rs:+3:53: +3:54
|
||||
- _9 = mul_with_overflow::<i32>(move _10, move _11) -> [return: bb3, unwind unreachable]; // scope 2 at $DIR/lower_intrinsics.rs:+3:14: +3:55
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:114:14: 114:49
|
||||
- // + span: $DIR/lower_intrinsics.rs:120:14: 120:49
|
||||
- // + literal: Const { ty: extern "rust-intrinsic" fn(i32, i32) -> (i32, bool) {mul_with_overflow::<i32>}, val: Value(<ZST>) }
|
||||
+ _9 = CheckedMul(move _10, move _11); // scope 2 at $DIR/lower_intrinsics.rs:+3:14: +3:55
|
||||
+ goto -> bb3; // scope 2 at $DIR/lower_intrinsics.rs:+3:14: +3:55
|
||||
|
@ -17,7 +17,7 @@
|
||||
_4 = move _2; // scope 1 at $DIR/lower_intrinsics.rs:+1:50: +1:51
|
||||
- _0 = write_via_move::<String>(move _3, move _4) -> [return: bb1, unwind unreachable]; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:52
|
||||
- // mir::Constant
|
||||
- // + span: $DIR/lower_intrinsics.rs:129:14: 129:46
|
||||
- // + span: $DIR/lower_intrinsics.rs:135:14: 135:46
|
||||
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(*mut String, String) {write_via_move::<String>}, val: Value(<ZST>) }
|
||||
+ (*_3) = move _4; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:52
|
||||
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:+1:14: +1:52
|
||||
|
Loading…
Reference in New Issue
Block a user