• Jakob Gruber's avatar
    [compiler] Widen optimization for external reference loads · 33e1a6e9
    Jakob Gruber authored
    Turbofan applies the following optimization to external reference
    loads on arm64 and x64: if the root-relative offset to an external
    reference's address is known to be constant (and the root register has
    been initialized), calculate the external reference as |kRootRegister
    + <offset>| instead of loading it from the external reference table.
    
    There are two main cases to consider:
    
    1. External references to arbitrary addresses in the native address
    space, e.g. libc_memcpy. These kinds of external references have a
    fixed address within the same running process, but may (and likely
    will) change between processes (e.g.: mksnapshot and later chromium),
    and the root-relative offset is different for each Isolate within the
    same process.
    
    These kinds of external references can be optimized as above when
    *not* generating code which will later be serialized, and *not*
    generating isolate-independent code.
    
    2. External references to addresses within the fixed-size region of
    the Isolate (essentially: within IsolateData). Since these move with
    the Isolate, their root-relative offset is guaranteed to be constant
    at all times.
    
    The optimization can always be applied to these cases as long as the
    root register has been initialized.
    
    Prior to this CL, we only recognized and optimized for case 1. This CL
    additionally adds support for 2.
    
    An example of improved code generated due to this CL:
    
    Before:
    // r13 is the kRootRegister on x64.
    // 0x3010 is the root-relative offset to Isolate::context_address.
    leaq rdx, [r13+0x3010]
    movq r8, [rdx]
    
    After:
    movq rdx, [r13+0x3010]
    
    Bug: v8:9534
    Change-Id: Idfcca751e98a56c0e5ead2c701c12a677df75399
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1748727
    Commit-Queue: Jakob Gruber <jgruber@chromium.org>
    Auto-Submit: Jakob Gruber <jgruber@chromium.org>
    Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#63158}
    33e1a6e9
instruction-selector.h 32.3 KB