Skip to content

Commit 05ff58e

Browse files
authored
Rollup merge of #79101 - tmiasko:lower-func-type, r=jonas-schievink
Don't special case constant operands when lowering intrinsics
2 parents 552d8c5 + 2b7ffec commit 05ff58e

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

compiler/rustc_mir/src/transform/lower_intrinsics.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ pub struct LowerIntrinsics;
1111

1212
impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
1313
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
14-
for block in body.basic_blocks_mut() {
14+
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
15+
for block in basic_blocks {
1516
let terminator = block.terminator.as_mut().unwrap();
16-
if let TerminatorKind::Call {
17-
func: Operand::Constant(box Constant { literal: ty::Const { ty: func_ty, .. }, .. }),
18-
args,
19-
destination,
20-
..
21-
} = &mut terminator.kind
22-
{
17+
if let TerminatorKind::Call { func, args, destination, .. } = &mut terminator.kind {
18+
let func_ty = func.ty(local_decls, tcx);
2319
let (intrinsic_name, substs) = match resolve_rust_intrinsic(tcx, func_ty) {
2420
None => continue,
2521
Some(it) => it,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
- // MIR for `non_const` before LowerIntrinsics
2+
+ // MIR for `non_const` after LowerIntrinsics
3+
4+
fn non_const() -> usize {
5+
let mut _0: usize; // return place in scope 0 at $DIR/lower_intrinsics.rs:55:26: 55:31
6+
let _1: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}; // in scope 0 at $DIR/lower_intrinsics.rs:57:9: 57:18
7+
let mut _2: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}; // in scope 0 at $DIR/lower_intrinsics.rs:58:5: 58:14
8+
scope 1 {
9+
debug size_of_t => _1; // in scope 1 at $DIR/lower_intrinsics.rs:57:9: 57:18
10+
}
11+
12+
bb0: {
13+
StorageLive(_1); // scope 0 at $DIR/lower_intrinsics.rs:57:9: 57:18
14+
_1 = std::intrinsics::size_of::<T>; // scope 0 at $DIR/lower_intrinsics.rs:57:21: 57:51
15+
// mir::Constant
16+
// + span: $DIR/lower_intrinsics.rs:57:21: 57:51
17+
// + literal: Const { ty: extern "rust-intrinsic" fn() -> usize {std::intrinsics::size_of::<T>}, val: Value(Scalar(<ZST>)) }
18+
StorageLive(_2); // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:14
19+
_2 = _1; // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:14
20+
- _0 = move _2() -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:16
21+
+ _0 = SizeOf(T); // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:16
22+
+ goto -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:58:5: 58:16
23+
}
24+
25+
bb1: {
26+
StorageDead(_2); // scope 1 at $DIR/lower_intrinsics.rs:58:15: 58:16
27+
StorageDead(_1); // scope 0 at $DIR/lower_intrinsics.rs:59:1: 59:2
28+
return; // scope 0 at $DIR/lower_intrinsics.rs:59:2: 59:2
29+
}
30+
}
31+

src/test/mir-opt/lower_intrinsics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ pub fn f_zst<T>(t: T) {
5050

5151
#[inline(never)]
5252
pub fn f_non_zst<T>(t: T) {}
53+
54+
// EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff
55+
pub fn non_const<T>() -> usize {
56+
// Check that lowering works with non-const operand as a func.
57+
let size_of_t = core::intrinsics::size_of::<T>;
58+
size_of_t()
59+
}

0 commit comments

Comments
 (0)