Auto merge of #2218 - Nilstrieb:faster-tag-partial-eq, r=RalfJung
Optimize `SbTag::eq` The code before generated really bad code with a branch. This nudges LLVM towards being smarter and simply comparing the integers. See https://github.com/rust-lang/miri/pull/2214#issuecomment-1150124617
This commit is contained in:
commit
4d6eca1c08
@ -17,6 +17,7 @@
|
||||
clippy::single_match,
|
||||
clippy::useless_format,
|
||||
clippy::derive_partial_eq_without_eq,
|
||||
clippy::derive_hash_xor_eq,
|
||||
clippy::too_many_arguments
|
||||
)]
|
||||
|
||||
|
@ -27,12 +27,30 @@ pub type CallId = NonZeroU64;
|
||||
pub type AllocExtra = Stacks;
|
||||
|
||||
/// Tracking pointer provenance
|
||||
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
|
||||
#[derive(Copy, Clone, Hash, Eq)]
|
||||
pub enum SbTag {
|
||||
Tagged(PtrId),
|
||||
Untagged,
|
||||
}
|
||||
|
||||
impl SbTag {
|
||||
fn as_u64(self) -> u64 {
|
||||
match self {
|
||||
SbTag::Tagged(id) => id.get(),
|
||||
SbTag::Untagged => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for SbTag {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
// The codegen for the derived Partialeq is bad here and includes a branch.
|
||||
// Since this code is extremely hot, this is optimized here.
|
||||
// https://github.com/rust-lang/rust/issues/49892
|
||||
self.as_u64() == other.as_u64()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SbTag {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user