Skip to content

Commit 3e5c468

Browse files
committed
Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends implementing it
1 parent e0d67ae commit 3e5c468

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
757757
ret.write_cvalue(fx, val);
758758
}
759759

760-
sym::ptr_guaranteed_cmp => {
761-
intrinsic_args!(fx, args => (a, b); intrinsic);
762-
763-
let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b).load_scalar(fx);
764-
ret.write_cvalue(fx, CValue::by_val(val, fx.layout_of(fx.tcx.types.u8)));
765-
}
766-
767760
sym::caller_location => {
768761
intrinsic_args!(fx, args => (); intrinsic);
769762

Diff for: 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;
@@ -456,12 +455,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
456455
return Ok(());
457456
}
458457

459-
sym::ptr_guaranteed_cmp => {
460-
let a = args[0].immediate();
461-
let b = args[1].immediate();
462-
bx.icmp(IntPredicate::IntEQ, a, b)
463-
}
464-
465458
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
466459
let ty = fn_args.type_at(0);
467460
let pointee_size = bx.layout_of(ty).size;

Diff for: compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub fn check_intrinsic_type(
441441

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

Diff for: 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)