abstract-equal-symbol.js 3.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax --opt --noalways-opt

// Known symbols abstract equality.
(function() {
  const a = Symbol("a");
  const b = Symbol("b");

  function foo() { return a == b; }

14
  %PrepareFunctionForOptimization(foo);
15 16 17 18 19 20 21 22 23 24 25 26 27
  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

// Known symbols abstract in-equality.
(function() {
  const a = Symbol("a");
  const b = Symbol("b");

  function foo() { return a != b; }

28
  %PrepareFunctionForOptimization(foo);
29 30 31 32 33 34 35 36 37 38 39 40 41 42
  assertTrue(foo());
  assertTrue(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo());
})();

// Known symbol on one side abstract equality.
(function() {
  const a = Symbol("a");
  const b = Symbol("b");

  function foo(a) { return a == b; }

  // Warmup
43
  %PrepareFunctionForOptimization(foo);
44 45 46 47 48 49
  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
50 51 52
  // Re-prepare the function immediately to make sure type feedback isn't
  // cleared by untimely gc, as re-optimization on new feedback is tested below
  %PrepareFunctionForOptimization(foo);
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  assertFalse(foo(a));
  assertOptimized(foo);

  // Make optimized code bail out
  assertFalse(foo("a"));
  assertUnoptimized(foo);

  // Make sure TurboFan learns the new feedback
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo("a"));
  assertOptimized(foo);
})();

// Known symbol on one side abstract in-equality.
(function() {
  const a = Symbol("a");
  const b = Symbol("b");

  function foo(a) { return a != b; }

  // Warmup
74
  %PrepareFunctionForOptimization(foo);
75 76 77 78 79 80 81 82 83 84 85 86 87
  assertFalse(foo(b));
  assertTrue(foo(a));
  assertFalse(foo(b));
  assertTrue(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(b));
  assertTrue(foo(a));

  // Make optimized code bail out
  assertTrue(foo("a"));
  assertUnoptimized(foo);

  // Make sure TurboFan learns the new feedback
88
  %PrepareFunctionForOptimization(foo);
89 90 91 92 93 94 95 96 97 98 99 100 101
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo("a"));
  assertOptimized(foo);
})();

// Feedback based symbol abstract equality.
(function() {
  const a = Symbol("a");
  const b = Symbol("b");

  function foo(a, b) { return a == b; }

  // Warmup
102
  %PrepareFunctionForOptimization(foo);
103 104 105 106 107 108 109 110 111 112 113 114 115
  assertTrue(foo(b, b));
  assertFalse(foo(a, b));
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));

  // Make optimized code bail out
  assertFalse(foo("a", b));
  assertUnoptimized(foo);

  // Make sure TurboFan learns the new feedback
116
  %PrepareFunctionForOptimization(foo);
117 118 119 120 121 122 123 124 125 126 127 128
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo("a", b));
  assertOptimized(foo);
})();

// Feedback based symbol abstract in-equality.
(function() {
  const a = Symbol("a");
  const b = Symbol("b");

  function foo(a, b) { return a != b; }

129
  %PrepareFunctionForOptimization(foo);
130 131 132 133 134 135 136 137 138 139 140 141 142
  assertFalse(foo(b, b));
  assertTrue(foo(a, b));
  assertFalse(foo(a, a));
  assertTrue(foo(b, a));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(a, a));
  assertTrue(foo(b, a));

  // Make optimized code bail out
  assertTrue(foo("a", b));
  assertUnoptimized(foo);

  // Make sure TurboFan learns the new feedback
143
  %PrepareFunctionForOptimization(foo);
144 145 146 147
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo("a", b));
  assertOptimized(foo);
})();