summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/getelem-bounds-hoist.js
blob: 694da72d6a243dafeab35bd084a9d14c47656b81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var a = [1,2,3,4,5];

// Basic overflow in hoisted condition.
function foo(x, n) {
  var v = 0;
  for (var i = 0; i < n; i++)
    v += x[i];
  return v;
}
for (var i = 0; i < 15; i++)
  assertEq(foo(a, 5), 15);
assertEq(foo(a, 6), NaN);

// Basic underflow in hoisted condition.
function foo2(x, m, n) {
  var v = 0;
  for (var i = m; i < n; i++)
    v += x[i];
  return v;
}
for (var i = 0; i < 15; i++)
  assertEq(foo2(a, 0, 5), 15);
assertEq(foo2(a, -1, 5), NaN);

// Overflow when hoisting consolidated condition.
function foo3(x, m, n) {
  var v = 0;
  for (var i = m; i < n; i++)
    v += x[i] + x[i + 1] + x[i + 2];
  return v;
}
for (var i = 0; i < 15; i++)
  assertEq(foo3(a, 0, 3), 27);
assertEq(foo3(a, 0, 4), NaN);

// Underflow when hoisting consolidated condition.
function foo4(x, m, n) {
  var v = 0;
  for (var i = m; i < n; i++)
    v += x[i] + x[i - 1] + x[i - 2];
  return v;
}
for (var i = 0; i < 15; i++)
  assertEq(foo4(a, 2, 5), 27);
assertEq(foo4(a, 0, 5), NaN);

// Underflow due to decreasing index.
function foo5(x, n) {
  var v = 0;
  for (var i = 0; i < n; i++) {
    v += x[i];
    if (n == 4)
      i -= 2;
    if (i == -5)
      break;
  }
  return v;
}
for (var i = 0; i < 15; i++)
  assertEq(foo5(a, 5), 15);
assertEq(foo5(a, 4), NaN);

// Overflow after access at constant offset.
function foo6(x, m, n) {
  var v = 0;
  for (var i = m; i < n; i++)
    v += x[i + 10];
  return v;
}
for (var i = 0; i < 15; i++)
  assertEq(foo6(a, -10, -5), 15);
assertEq(foo6(a, -10, -4), NaN);

// Underflow after access at constant offset.
function foo7(x, m, n) {
  var v = 0;
  for (var i = m; i < n; i++)
    v += x[i + 10];
  return v;
}
for (var i = 0; i < 15; i++)
  assertEq(foo7(a, -10, -5), 15);
assertEq(foo7(a, -11, -5), NaN);