From f6fc9d6e3e237a32f823342960bdeda6625d533f Mon Sep 17 00:00:00 2001 From: Jakob Gruber Date: Mon, 2 Sep 2019 15:11:57 +0200 Subject: [PATCH] [ia32] Add a root-relative addressing mode .. and use it for generating faster loads of external references. This changes the stack check instruction sequence from mov ecx,0x567651dc // The address of the stack limit. cmp esp,[ecx] to cmp esp,[ebx+0x3c] This addressing mode was likely forgotten when we recently added root register support on ia32. Bug: chromium:998751,v8:9534 Change-Id: I3521519da1e9d373dfcd83831b3e399e0e9c895b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1781056 Reviewed-by: Sigurd Schneider Commit-Queue: Jakob Gruber Cr-Commit-Position: refs/heads/master@{#63508} --- src/compiler/backend/ia32/code-generator-ia32.cc | 5 +++++ .../backend/ia32/instruction-codes-ia32.h | 3 ++- .../backend/ia32/instruction-selector-ia32.cc | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/compiler/backend/ia32/code-generator-ia32.cc b/src/compiler/backend/ia32/code-generator-ia32.cc index d992be4c1b..77b5874b19 100644 --- a/src/compiler/backend/ia32/code-generator-ia32.cc +++ b/src/compiler/backend/ia32/code-generator-ia32.cc @@ -165,6 +165,11 @@ class IA32OperandConverter : public InstructionOperandConverter { Constant ctant = ToConstant(instr_->InputAt(NextOffset(offset))); return Operand(ctant.ToInt32(), ctant.rmode()); } + case kMode_Root: { + Register base = kRootRegister; + int32_t disp = InputInt32(NextOffset(offset)); + return Operand(base, disp); + } case kMode_None: UNREACHABLE(); } diff --git a/src/compiler/backend/ia32/instruction-codes-ia32.h b/src/compiler/backend/ia32/instruction-codes-ia32.h index cfe8271916..c4c4bf502c 100644 --- a/src/compiler/backend/ia32/instruction-codes-ia32.h +++ b/src/compiler/backend/ia32/instruction-codes-ia32.h @@ -393,7 +393,8 @@ namespace compiler { V(M2I) /* [ %r2*2 + K] */ \ V(M4I) /* [ %r2*4 + K] */ \ V(M8I) /* [ %r2*8 + K] */ \ - V(MI) /* [ K] */ + V(MI) /* [ K] */ \ + V(Root) /* [%root + K] */ } // namespace compiler } // namespace internal diff --git a/src/compiler/backend/ia32/instruction-selector-ia32.cc b/src/compiler/backend/ia32/instruction-selector-ia32.cc index d48ff7ee2a..89fa8c6673 100644 --- a/src/compiler/backend/ia32/instruction-selector-ia32.cc +++ b/src/compiler/backend/ia32/instruction-selector-ia32.cc @@ -152,6 +152,21 @@ class IA32OperandGenerator final : public OperandGenerator { AddressingMode GetEffectiveAddressMemoryOperand(Node* node, InstructionOperand inputs[], size_t* input_count) { + { + LoadMatcher m(node); + if (m.index().HasValue() && m.object().HasValue() && + selector()->CanAddressRelativeToRootsRegister(m.object().Value())) { + ptrdiff_t const delta = + m.index().Value() + + TurboAssemblerBase::RootRegisterOffsetForExternalReference( + selector()->isolate(), m.object().Value()); + if (is_int32(delta)) { + inputs[(*input_count)++] = TempImmediate(static_cast(delta)); + return kMode_Root; + } + } + } + BaseWithIndexAndDisplacement32Matcher m(node, AddressOption::kAllowAll); DCHECK(m.matches()); if ((m.displacement() == nullptr || CanBeImmediate(m.displacement()))) {