• Jaroslav Sevcik's avatar
    [turbofan] Load elimination - use maps to avoid state invalidation. · ea891e87
    Jaroslav Sevcik authored
    Currently, the transition elements kind operation invalidates the
    elements of all other arrays. In particular, if we loop over matrix 
    elements using two nested loops, and do possibly transitioning access 
    a[i][j] in every iteration, we invalidate the load elimination state 
    for the array 'a' because a[i][j] might transition elements kind 
    for the 'a[i]' array. As a result, the 'a[i]' access cannot be 
    hoisted from the inner loop.
    
    With this CL, we figure out that transitioning 'a[i]' cannot affect 'a'
    because we know that 'a' does not have the transition's source map.
    
    In the micro-benchmark below, the time for summing up the elements of
    100x100 matrix improves by factor of 1.7 (from ~340ms to ~190ms).
    
    function matrixSum(a) {
      let s = 0;
      let rowCount = a.length;
      let columnCount = a[0].length;
      for (let i = 0; i < rowCount; i++) {
        for (let j = 0; j < columnCount ; j++) {
          s += a[i][j];
        }
      }
      return s;
    }
    
    // Setup the matrices:
    // Smi elements.
    var ma = [[1, 2], [3, 4]];
    // Holey double elements.
    var b = Array(100);
    for (let i = 0; i < 100; i++) b[i] = 1.1;
    var mb = [];
    for (let i = 0; i < 100; i++) mb[i] = b;
    
    // Warmup.
    matrixSum(mb);
    matrixSum(mb);
    matrixSum(ma);
    matrixSum(mb);
    matrixSum(ma);
    
    %OptimizeFunctionOnNextCall(matrixSum);
    
    function runner(m) {
      let s = 0;
      for (let i = 0; i < 1e4; i++) {
        s += matrixSum(m);
      }
      return s;
    }
    // Make sure the runner does not know the elements kinds.
    %NeverOptimizeFunction(runner);
    
    // Measure.
    console.time("Sum");
    runner(mb);
    console.timeEnd("Sum");
    
    
    Bug: v8:6344
    Change-Id: Ie0642d8693ed63116b1aaed7d2f261fcb64729fe
    Reviewed-on: https://chromium-review.googlesource.com/704634
    Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
    Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#48334}
    ea891e87
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni Loading commit data...
gypfiles Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.editorconfig Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...