Skip to content

Commit

Permalink
Auto merge of #2218 - Nilstrieb:faster-tag-partial-eq, r=RalfJung
Browse files Browse the repository at this point in the history
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 #2214 (comment)
  • Loading branch information
bors committed Jun 8, 2022
2 parents 5a76e9f + 93db9a6 commit 4d6eca1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)]

Expand Down
20 changes: 19 additions & 1 deletion src/stacked_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4d6eca1

Please sign in to comment.