Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 28 | // Flags: --nofull-compiler --nofast-compiler |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 30 | // Test paths in the code generator where values in specific registers |
| 31 | // get moved around. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | function identity(x) { |
| 33 | return x; |
| 34 | } |
| 35 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 36 | function lookup(w, a) { |
| 37 | // This function tests a code path in the generation of a keyed load IC |
| 38 | // where the key and the value are both in the same register. |
| 39 | a = a; |
| 40 | w[a] = a; |
| 41 | } |
| 42 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 43 | function cover_codegen_paths() { |
| 44 | var x = 1; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 45 | |
| 46 | // This test depends on the fixed order of register allocation. We try to |
| 47 | // get values in specific registers (ia32, x64): |
| 48 | var a; // Register eax, rax. |
| 49 | var b; // Register ebx, rbx. |
| 50 | var c; // Register ecx, rcx. |
| 51 | var d; // Register edx, rdx. |
| 52 | var di; // Register edi, rdi. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 53 | |
| 54 | while (x == 1) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 55 | // The call will spill registers and leave x in {eax,rax}. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 56 | x = identity(1); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 57 | // The add will spill x and reuse {eax,rax} for the result. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 58 | a = x + 1; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 59 | // A fresh register {ebx,rbx} will be allocated for x, then reused for |
| 60 | // the result. |
| 61 | b = x + 1; |
| 62 | // Et cetera. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 63 | c = x + 1; |
| 64 | d = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 65 | di = x + 1; |
| 66 | // Locals are in the corresponding registers here. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 67 | assertEquals(8, c << a); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 68 | |
| 69 | x = identity(1); |
| 70 | a = x + 1; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 71 | b = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 72 | c = x + 1; |
| 73 | d = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 74 | di = x + 1; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 75 | assertEquals(8, a << c); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 76 | |
| 77 | x = identity(1); |
| 78 | a = x + 1; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 79 | b = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 80 | c = x + 1; |
| 81 | d = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | di = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 83 | c = 0; // Free register ecx. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 84 | assertEquals(8, a << d); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 85 | |
| 86 | x = identity(1); |
| 87 | a = x + 1; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 88 | b = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 89 | c = x + 1; |
| 90 | d = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 91 | di = x + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 92 | b = 0; // Free register ebx. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 93 | assertEquals(8, a << d); |
| 94 | |
| 95 | // Test the non-commutative subtraction operation with a smi on the |
| 96 | // left, all available registers on the right, and a non-smi result. |
| 97 | x = identity(-1073741824); // Least (31-bit) smi. |
| 98 | a = x + 1; // Still a smi, the greatest smi negated. |
| 99 | b = x + 1; |
| 100 | c = x + 1; |
| 101 | d = x + 1; |
| 102 | di = x + 1; |
| 103 | // Subtraction should overflow the 31-bit smi range. The result |
| 104 | // (1073741824) is outside the 31-bit smi range so it doesn't hit the |
| 105 | // "unsafe smi" code that spills a register. |
| 106 | assertEquals(1073741824, 1 - a); |
| 107 | |
| 108 | x = identity(-1073741824); |
| 109 | a = x + 1; |
| 110 | b = x + 1; |
| 111 | c = x + 1; |
| 112 | d = x + 1; |
| 113 | di = x + 1; |
| 114 | assertEquals(1073741824, 1 - b); |
| 115 | |
| 116 | x = identity(-1073741824); |
| 117 | a = x + 1; |
| 118 | b = x + 1; |
| 119 | c = x + 1; |
| 120 | d = x + 1; |
| 121 | di = x + 1; |
| 122 | assertEquals(1073741824, 1 - c); |
| 123 | |
| 124 | x = identity(-1073741824); |
| 125 | a = x + 1; |
| 126 | b = x + 1; |
| 127 | c = x + 1; |
| 128 | d = x + 1; |
| 129 | di = x + 1; |
| 130 | assertEquals(1073741824, 1 - d); |
| 131 | |
| 132 | x = identity(-1073741824); |
| 133 | a = x + 1; |
| 134 | b = x + 1; |
| 135 | c = x + 1; |
| 136 | d = x + 1; |
| 137 | di = x + 1; |
| 138 | assertEquals(1073741824, 1 - di); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 139 | |
| 140 | x = 3; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 141 | var w = { }; |
| 142 | lookup(w, x); |
| 143 | lookup(w, x); |
| 144 | lookup(w, x); |
| 145 | |
| 146 | x = 3; // Terminate while loop. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | cover_codegen_paths(); |