Skip to content

Commit 104168a

Browse files
committed
Generalize the Assume intrinsic statement to a general Intrinsic statement
1 parent 088e03f commit 104168a

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/base.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -791,25 +791,34 @@ fn codegen_stmt<'tcx>(
791791
| StatementKind::Nop
792792
| StatementKind::FakeRead(..)
793793
| StatementKind::Retag { .. }
794-
// We ignore `assume` intrinsics, they are only useful for optimizations
795-
| StatementKind::Assume(..)
796794
| StatementKind::AscribeUserType(..) => {}
797795

798796
StatementKind::Coverage { .. } => fx.tcx.sess.fatal("-Zcoverage is unimplemented"),
799-
StatementKind::CopyNonOverlapping(inner) => {
800-
let dst = codegen_operand(fx, &inner.dst);
801-
let pointee = dst
802-
.layout()
803-
.pointee_info_at(fx, rustc_target::abi::Size::ZERO)
804-
.expect("Expected pointer");
805-
let dst = dst.load_scalar(fx);
806-
let src = codegen_operand(fx, &inner.src).load_scalar(fx);
807-
let count = codegen_operand(fx, &inner.count).load_scalar(fx);
808-
let elem_size: u64 = pointee.size.bytes();
809-
let bytes =
810-
if elem_size != 1 { fx.bcx.ins().imul_imm(count, elem_size as i64) } else { count };
811-
fx.bcx.call_memcpy(fx.target_config, dst, src, bytes);
812-
}
797+
StatementKind::Intrinsic(ref intrinsic) => match &**intrinsic {
798+
// We ignore `assume` intrinsics, they are only useful for optimizations
799+
NonDivergingIntrinsic::Assume(_) => {}
800+
NonDivergingIntrinsic::CopyNonOverlapping(mir::CopyNonOverlapping {
801+
src,
802+
dst,
803+
count,
804+
}) => {
805+
let dst = codegen_operand(fx, dst);
806+
let pointee = dst
807+
.layout()
808+
.pointee_info_at(fx, rustc_target::abi::Size::ZERO)
809+
.expect("Expected pointer");
810+
let dst = dst.load_scalar(fx);
811+
let src = codegen_operand(fx, src).load_scalar(fx);
812+
let count = codegen_operand(fx, count).load_scalar(fx);
813+
let elem_size: u64 = pointee.size.bytes();
814+
let bytes = if elem_size != 1 {
815+
fx.bcx.ins().imul_imm(count, elem_size as i64)
816+
} else {
817+
count
818+
};
819+
fx.bcx.call_memcpy(fx.target_config, dst, src, bytes);
820+
}
821+
},
813822
}
814823
}
815824

src/constant.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,12 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
536536
{
537537
return None;
538538
}
539-
StatementKind::CopyNonOverlapping(_) => {
540-
return None;
541-
} // conservative handling
539+
StatementKind::Intrinsic(ref intrinsic) => match **intrinsic {
540+
NonDivergingIntrinsic::CopyNonOverlapping(..) => return None,
541+
NonDivergingIntrinsic::Assume(..) => {}
542+
},
543+
// conservative handling
542544
StatementKind::Assign(_)
543-
| StatementKind::Assume(_)
544545
| StatementKind::FakeRead(_)
545546
| StatementKind::SetDiscriminant { .. }
546547
| StatementKind::Deinit(_)

0 commit comments

Comments
 (0)