summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/bug1331350.js
blob: ea83bfa4fe17526e21db998828760cd817968465 (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
// |jit-test| --ion-eager
function optimize(a, b) {
    a = a | 0;
    b = b | 0;

    if ((a & 3) === 0) {
        a = a + 1 | 0
    }

    if ((a & 7) !== 0) {
        a = a + 1 | 0
    }

    return a + b | 0
}

for (var i=0; i<20; i++) {
    assertEq(optimize(4 | 0, 6 | 0), 12);
    assertEq(optimize(7 | 0, 11 | 0), 19);
}

function not_optimizable(a, b) {
    a = a | 0;
    b = b | 0;

    if ((a & 3) > 0) {
        a = a + 1 | 0
    }

    if ((a & 3) >= 0) {
        a = a + 1 | 0
    }

    if ((a & 7) < 0) {
        a = a + 1 | 0
    }

    if ((a & 7) <= 0) {
        a = a + 1 | 0
    }

    if ((b & 3) === 1) {
        b = b + 1 | 0
    }

    if ((b & 7) !== 3) {
        b = b + 1 | 0
    }

    return a + b | 0
}

for (var i=0; i<20; i++) {
    assertEq(not_optimizable(4 | 0, 6 | 0), 12);
    assertEq(not_optimizable(7 | 0, 11 | 0), 20);
}