Commit 30dad483 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[x64] Microoptimise comparisons against tagged values

Avoid loading objects with 64-bit movq when they are only being used to
compare against another object with a 32-bit cmp_tagged under pointer
compression.

Change-Id: Ib8ccd093fb49caea3bf1b923b83825626ba0bffc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3760447Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81689}
parent db9e3428
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <cstdint>
#if V8_TARGET_ARCH_X64
#include "src/base/bits.h"
......@@ -185,12 +186,13 @@ void TurboAssembler::CompareRoot(Register with, RootIndex index) {
void TurboAssembler::CompareRoot(Operand with, RootIndex index) {
DCHECK(root_array_available_);
DCHECK(!with.AddressUsesRegister(kScratchRegister));
LoadRoot(kScratchRegister, index);
if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
RootIndex::kLastStrongOrReadOnlyRoot)) {
mov_tagged(kScratchRegister, RootAsOperand(index));
cmp_tagged(with, kScratchRegister);
} else {
// Some smi roots contain system pointer size values like stack limits.
movq(kScratchRegister, RootAsOperand(index));
cmpq(with, kScratchRegister);
}
}
......@@ -1371,6 +1373,8 @@ void TurboAssembler::SmiCompare(Register dst, Smi src) {
void TurboAssembler::Cmp(Register dst, Smi src) {
if (src.value() == 0) {
test_tagged(dst, dst);
} else if (COMPRESS_POINTERS_BOOL) {
cmp_tagged(dst, Immediate(src));
} else {
DCHECK_NE(dst, kScratchRegister);
Register constant_reg = GetSmiConstant(src);
......@@ -1653,7 +1657,9 @@ void MacroAssembler::Cmp(Register dst, Handle<Object> source) {
if (source->IsSmi()) {
Cmp(dst, Smi::cast(*source));
} else {
Move(kScratchRegister, Handle<HeapObject>::cast(source));
Move(kScratchRegister, Handle<HeapObject>::cast(source),
COMPRESS_POINTERS_BOOL ? RelocInfo::COMPRESSED_EMBEDDED_OBJECT
: RelocInfo::FULL_EMBEDDED_OBJECT);
cmp_tagged(dst, kScratchRegister);
}
}
......@@ -1662,7 +1668,9 @@ void MacroAssembler::Cmp(Operand dst, Handle<Object> source) {
if (source->IsSmi()) {
Cmp(dst, Smi::cast(*source));
} else {
Move(kScratchRegister, Handle<HeapObject>::cast(source));
Move(kScratchRegister, Handle<HeapObject>::cast(source),
COMPRESS_POINTERS_BOOL ? RelocInfo::COMPRESSED_EMBEDDED_OBJECT
: RelocInfo::FULL_EMBEDDED_OBJECT);
cmp_tagged(dst, kScratchRegister);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment