Skip to content

Commit bbc88ef

Browse files
committed
Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends implementing it
1 parent 0df3d3d commit bbc88ef

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -752,13 +752,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
752752
ret.write_cvalue(fx, val);
753753
}
754754

755-
sym::ptr_guaranteed_cmp => {
756-
intrinsic_args!(fx, args => (a, b); intrinsic);
757-
758-
let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b).load_scalar(fx);
759-
ret.write_cvalue(fx, CValue::by_val(val, fx.layout_of(fx.tcx.types.u8)));
760-
}
761-
762755
sym::caller_location => {
763756
intrinsic_args!(fx, args => (); intrinsic);
764757

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::operand::{OperandRef, OperandValue};
22
use super::place::PlaceRef;
33
use super::FunctionCx;
4-
use crate::common::IntPredicate;
54
use crate::errors;
65
use crate::errors::InvalidMonomorphization;
76
use crate::meth;
@@ -486,12 +485,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
486485
return Ok(());
487486
}
488487

489-
sym::ptr_guaranteed_cmp => {
490-
let a = args[0].immediate();
491-
let b = args[1].immediate();
492-
bx.icmp(IntPredicate::IntEQ, a, b)
493-
}
494-
495488
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
496489
let ty = fn_args.type_at(0);
497490
let pointee_size = bx.layout_of(ty).size;

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub fn check_intrinsic_type(
440440

441441
sym::ptr_guaranteed_cmp => (
442442
1,
443-
0,
443+
1,
444444
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
445445
tcx.types.u8,
446446
),

library/core/src/intrinsics.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -2434,20 +2434,29 @@ extern "rust-intrinsic" {
24342434
#[rustc_nounwind]
24352435
pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
24362436

2437-
/// See documentation of `<*const T>::guaranteed_eq` for details.
2438-
/// Returns `2` if the result is unknown.
2439-
/// Returns `1` if the pointers are guaranteed equal
2440-
/// Returns `0` if the pointers are guaranteed inequal
2441-
///
2442-
/// Note that, unlike most intrinsics, this is safe to call;
2443-
/// it does not require an `unsafe` block.
2444-
/// Therefore, implementations must not require the user to uphold
2445-
/// any safety invariants.
24462437
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
24472438
#[rustc_safe_intrinsic]
24482439
#[rustc_nounwind]
2440+
#[cfg(bootstrap)]
24492441
pub fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8;
2442+
}
24502443

2444+
/// See documentation of `<*const T>::guaranteed_eq` for details.
2445+
/// Returns `2` if the result is unknown.
2446+
/// Returns `1` if the pointers are guaranteed equal
2447+
/// Returns `0` if the pointers are guaranteed inequal
2448+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
2449+
#[unstable(feature = "core_intrinsics", issue = "none")]
2450+
#[rustc_intrinsic]
2451+
#[cfg(not(bootstrap))]
2452+
#[rustc_nounwind]
2453+
#[rustc_do_not_const_check]
2454+
#[inline]
2455+
pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
2456+
(ptr == other) as u8
2457+
}
2458+
2459+
extern "rust-intrinsic" {
24512460
/// Determines whether the raw bytes of the two values are equal.
24522461
///
24532462
/// This is particularly handy for arrays, since it allows things like just

0 commit comments

Comments
 (0)