[ARM,MIPS] Skip slow tests
[WebKit-https.git] / JSTests / stress / arith-abs-to-arith-negate-range-optimizaton.js
1 //@ skip if not $jitTests
2 //@ defaultNoEagerRun
3 "use strict";
4
5 // Checked int_min < value < 0
6 function opaqueCheckedBetweenIntMinAndZeroExclusive(arg) {
7     if (arg < 0) {
8         if (arg > (0x80000000|0)) {
9             return Math.abs(arg);
10         }
11     }
12     throw "We should not be here";
13 }
14 noInline(opaqueCheckedBetweenIntMinAndZeroExclusive);
15
16 function testCheckedBetweenIntMinAndZeroExclusive()
17 {
18     for (let i = 1; i < 1e5; ++i) {
19         if (opaqueCheckedBetweenIntMinAndZeroExclusive(-i) !== i) {
20             throw "Failed testCheckedBetweenIntMinAndZeroExclusive()";
21         }
22         if (opaqueCheckedBetweenIntMinAndZeroExclusive(-2147483647) !== 2147483647) {
23             throw "Failed testCheckedBetweenIntMinAndZeroExclusive() on -2147483647";
24         }
25     }
26     if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinAndZeroExclusive) > 1) {
27         throw "Failed optimizing testCheckedBetweenIntMinAndZeroExclusive(). None of the tested case need to OSR Exit.";
28     }
29 }
30 testCheckedBetweenIntMinAndZeroExclusive();
31
32
33 // Checked int_min < value <= 0
34 function opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(arg) {
35     if (arg <= 0) {
36         if (arg > (0x80000000|0)) {
37             return Math.abs(arg);
38         }
39     }
40     throw "We should not be here";
41 }
42 noInline(opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive);
43
44 function testCheckedBetweenIntMinExclusiveAndZeroInclusive()
45 {
46     for (let i = 1; i < 1e5; ++i) {
47         if (opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(-i) !== i) {
48             throw "Failed testCheckedBetweenIntMinExclusiveAndZeroInclusive()";
49         }
50         if (opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(0) !== 0) {
51             throw "Failed testCheckedBetweenIntMinExclusiveAndZeroInclusive() on 0";
52         }
53         if (opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(-2147483647) !== 2147483647) {
54             throw "Failed testCheckedBetweenIntMinExclusiveAndZeroInclusive() on -2147483647";
55         }
56     }
57     if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive) > 1) {
58         throw "Failed optimizing testCheckedBetweenIntMinExclusiveAndZeroInclusive(). None of the tested case need to OSR Exit.";
59     }
60 }
61 testCheckedBetweenIntMinExclusiveAndZeroInclusive();
62
63
64 // Checked int_min <= value < 0
65 function opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(arg) {
66     if (arg < 0) {
67         if (arg >= (0x80000000|0)) {
68             return Math.abs(arg);
69         }
70     }
71     throw "We should not be here";
72 }
73 noInline(opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive);
74
75 function testCheckedBetweenIntMinInclusiveAndZeroExclusive()
76 {
77     for (let i = 1; i < 1e5; ++i) {
78         if (opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-i) !== i) {
79             throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive()";
80         }
81         if (opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483647) !== 2147483647) {
82             throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483647";
83         }
84     }
85     if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive) > 1) {
86         throw "Failed optimizing testCheckedBetweenIntMinInclusiveAndZeroExclusive(). None of the tested case need to OSR Exit.";
87     }
88
89     for (let i = 1; i < 1e5; ++i) {
90         if (opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-i) !== i) {
91             throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive()";
92         }
93         let result = opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483648);
94         if (result !== 2147483648) {
95             throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483648, got " + result;
96         }
97     }
98
99     if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive) > 2) {
100         throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
101     }
102 }
103 testCheckedBetweenIntMinInclusiveAndZeroExclusive();
104
105
106 // Checked int_min <= value <= 0
107 function opaqueCheckedBetweenIntMinAndZeroInclusive(arg) {
108     if (arg <= 0) {
109         if (arg >= (0x80000000|0)) {
110             return Math.abs(arg);
111         }
112     }
113     throw "We should not be here";
114 }
115 noInline(opaqueCheckedBetweenIntMinAndZeroInclusive);
116
117 function testCheckedBetweenIntMinAndZeroInclusive()
118 {
119     for (let i = 1; i < 1e5; ++i) {
120         if (opaqueCheckedBetweenIntMinAndZeroInclusive(-i) !== i) {
121             throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
122         }
123         if (opaqueCheckedBetweenIntMinAndZeroInclusive(0) !== 0) {
124             throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
125         }
126         if (opaqueCheckedBetweenIntMinAndZeroInclusive(-2147483647) !== 2147483647) {
127             throw "Failed testCheckedBetweenIntMinAndZeroInclusive() on -2147483647";
128         }
129     }
130     if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinAndZeroInclusive) > 1) {
131         throw "Failed optimizing testCheckedBetweenIntMinAndZeroInclusive(). None of the tested case need to OSR Exit.";
132     }
133
134     for (let i = 1; i < 1e5; ++i) {
135         if (opaqueCheckedBetweenIntMinAndZeroInclusive(-i) !== i) {
136             throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
137         }
138         if (opaqueCheckedBetweenIntMinAndZeroInclusive(0) !== 0) {
139             throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
140         }
141         if (opaqueCheckedBetweenIntMinAndZeroInclusive(-2147483648) !== 2147483648) {
142             throw "Failed testCheckedBetweenIntMinAndZeroInclusive() on -2147483648";
143         }
144     }
145
146     if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinAndZeroInclusive) > 2) {
147         throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
148     }
149 }
150 testCheckedBetweenIntMinAndZeroInclusive();
151
152
153 // Unchecked int_min < value < 0
154 function opaqueUncheckedBetweenIntMinAndZeroExclusive(arg) {
155     if (arg < 0) {
156         if (arg > (0x80000000|0)) {
157             return Math.abs(arg)|0;
158         }
159     }
160     throw "We should not be here";
161 }
162 noInline(opaqueUncheckedBetweenIntMinAndZeroExclusive);
163
164 function testUncheckedBetweenIntMinAndZeroExclusive()
165 {
166     for (let i = 1; i < 1e5; ++i) {
167         if (opaqueUncheckedBetweenIntMinAndZeroExclusive(-i) !== i) {
168             throw "Failed testUncheckedBetweenIntMinAndZeroExclusive()";
169         }
170         if (opaqueUncheckedBetweenIntMinAndZeroExclusive(-2147483647) !== 2147483647) {
171             throw "Failed testUncheckedBetweenIntMinAndZeroExclusive() on -2147483647";
172         }
173     }
174     if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinAndZeroExclusive) > 1) {
175         throw "Failed optimizing testUncheckedBetweenIntMinAndZeroExclusive(). None of the tested case need to OSR Exit.";
176     }
177 }
178 testUncheckedBetweenIntMinAndZeroExclusive();
179
180
181 // Unchecked int_min < value <= 0
182 function opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(arg) {
183     if (arg <= 0) {
184         if (arg > (0x80000000|0)) {
185             return Math.abs(arg)|0;
186         }
187     }
188     throw "We should not be here";
189 }
190 noInline(opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive);
191
192 function testUncheckedBetweenIntMinExclusiveAndZeroInclusive()
193 {
194     for (let i = 1; i < 1e5; ++i) {
195         if (opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(-i) !== i) {
196             throw "Failed testUncheckedBetweenIntMinExclusiveAndZeroInclusive()";
197         }
198         if (opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(0) !== 0) {
199             throw "Failed testUncheckedBetweenIntMinExclusiveAndZeroInclusive() on 0";
200         }
201         if (opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(-2147483647) !== 2147483647) {
202             throw "Failed testUncheckedBetweenIntMinExclusiveAndZeroInclusive() on -2147483647";
203         }
204     }
205     if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive) > 1) {
206         throw "Failed optimizing testUncheckedBetweenIntMinExclusiveAndZeroInclusive(). None of the tested case need to OSR Exit.";
207     }
208 }
209 testUncheckedBetweenIntMinExclusiveAndZeroInclusive();
210
211
212 // Unchecked int_min <= value < 0
213 function opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(arg) {
214     if (arg < 0) {
215         if (arg >= (0x80000000|0)) {
216             return Math.abs(arg)|0;
217         }
218     }
219     throw "We should not be here";
220 }
221 noInline(opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive);
222
223 function testUncheckedBetweenIntMinInclusiveAndZeroExclusive()
224 {
225     for (let i = 1; i < 1e5; ++i) {
226         if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-i) !== i) {
227             throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive()";
228         }
229         if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483647) !== 2147483647) {
230             throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483647";
231         }
232         if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483648) !== -2147483648) {
233             throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483648";
234         }
235     }
236     if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive) > 1) {
237         throw "Failed optimizing testUncheckedBetweenIntMinInclusiveAndZeroExclusive(). None of the tested case need to OSR Exit.";
238     }
239 }
240 testUncheckedBetweenIntMinInclusiveAndZeroExclusive();
241
242
243 // Unchecked int_min <= value <= 0
244 function opaqueUncheckedBetweenIntMinAndZeroInclusive(arg) {
245     if (arg <= 0) {
246         if (arg >= (0x80000000|0)) {
247             return Math.abs(arg)|0;
248         }
249     }
250     throw "We should not be here";
251 }
252 noInline(opaqueUncheckedBetweenIntMinAndZeroInclusive);
253
254 function testUncheckedBetweenIntMinAndZeroInclusive()
255 {
256     for (let i = 1; i < 1e5; ++i) {
257         if (opaqueUncheckedBetweenIntMinAndZeroInclusive(-i) !== i) {
258             throw "Failed testUncheckedBetweenIntMinAndZeroInclusive()";
259         }
260         if (opaqueUncheckedBetweenIntMinAndZeroInclusive(0) !== 0) {
261             throw "Failed testUncheckedBetweenIntMinAndZeroInclusive()";
262         }
263         if (opaqueUncheckedBetweenIntMinAndZeroInclusive(-2147483647) !== 2147483647) {
264             throw "Failed testUncheckedBetweenIntMinAndZeroInclusive() on -2147483647";
265         }
266         if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483648) !== -2147483648) {
267             throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483648";
268         }
269     }
270     if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinAndZeroInclusive) > 1) {
271         throw "Failed optimizing testUncheckedBetweenIntMinAndZeroInclusive(). None of the tested case need to OSR Exit.";
272     }
273 }
274 testUncheckedBetweenIntMinAndZeroInclusive();
275
276
277 // Checked value < 0
278 function opaqueCheckedLessThanZero(arg) {
279     if (arg < 0) {
280         return Math.abs(arg);
281     }
282     throw "We should not be here";
283 }
284 noInline(opaqueCheckedLessThanZero);
285
286 function testCheckedLessThanZero()
287 {
288     for (let i = 1; i < 1e5; ++i) {
289         if (opaqueCheckedLessThanZero(-i) !== i) {
290             throw "Failed testCheckedLessThanZero()";
291         }
292         if (opaqueCheckedLessThanZero(-2147483647) !== 2147483647) {
293             throw "Failed testCheckedLessThanZero() on -2147483647";
294         }
295     }
296     if (numberOfDFGCompiles(opaqueCheckedLessThanZero) > 1) {
297         throw "Failed optimizing testCheckedLessThanZero(). None of the tested case need to OSR Exit.";
298     }
299
300     for (let i = 1; i < 1e5; ++i) {
301         if (opaqueCheckedLessThanZero(-i) !== i) {
302             throw "Failed testCheckedLessThanZero()";
303         }
304         let result = opaqueCheckedLessThanZero(-2147483648);
305         if (result !== 2147483648) {
306             throw "Failed testCheckedLessThanZero() on -2147483648, got " + result;
307         }
308     }
309     if (numberOfDFGCompiles(opaqueCheckedLessThanZero) > 2) {
310         throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
311     }
312 }
313 testCheckedLessThanZero();
314
315
316 // Checked value <= 0
317 function opaqueCheckedLessThanOrEqualZero(arg) {
318     if (arg <= 0) {
319         return Math.abs(arg);
320     }
321     throw "We should not be here";
322 }
323 noInline(opaqueCheckedLessThanOrEqualZero);
324
325 function testCheckedLessThanOrEqualZero()
326 {
327     for (let i = 1; i < 1e5; ++i) {
328         if (opaqueCheckedLessThanOrEqualZero(-i) !== i) {
329             throw "Failed testCheckedLessThanOrEqualZero()";
330         }
331         if (opaqueCheckedLessThanOrEqualZero(0) !== 0) {
332             throw "Failed testCheckedLessThanOrEqualZero() on 0";
333         }
334         if (opaqueCheckedLessThanOrEqualZero(-2147483647) !== 2147483647) {
335             throw "Failed testCheckedLessThanOrEqualZero() on -2147483647";
336         }
337     }
338     if (numberOfDFGCompiles(opaqueCheckedLessThanOrEqualZero) > 1) {
339         throw "Failed optimizing testCheckedLessThanOrEqualZero(). None of the tested case need to OSR Exit.";
340     }
341
342     for (let i = 1; i < 1e5; ++i) {
343         if (opaqueCheckedLessThanOrEqualZero(-i) !== i) {
344             throw "Failed testCheckedLessThanOrEqualZero()";
345         }
346         if (opaqueCheckedLessThanOrEqualZero(-2147483648) !== 2147483648) {
347             throw "Failed testCheckedLessThanOrEqualZero() on -2147483648";
348         }
349     }
350     if (numberOfDFGCompiles(opaqueCheckedLessThanOrEqualZero) > 2) {
351         throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
352     }
353 }
354 testCheckedLessThanOrEqualZero();
355
356
357 // Unchecked value < 0
358 function opaqueUncheckedLessThanZero(arg) {
359     if (arg < 0) {
360         return Math.abs(arg)|0;
361     }
362     throw "We should not be here";
363 }
364 noInline(opaqueUncheckedLessThanZero);
365
366 function testUncheckedLessThanZero()
367 {
368     for (let i = 1; i < 1e5; ++i) {
369         if (opaqueUncheckedLessThanZero(-i) !== i) {
370             throw "Failed testUncheckedLessThanZero()";
371         }
372         if (opaqueUncheckedLessThanZero(-2147483647) !== 2147483647) {
373             throw "Failed testUncheckedLessThanZero() on -2147483647";
374         }
375         if (opaqueUncheckedLessThanZero(-2147483648) !== -2147483648) {
376             throw "Failed testUncheckedLessThanOrEqualZero() on -2147483648";
377         }
378     }
379     if (numberOfDFGCompiles(opaqueUncheckedLessThanZero) > 1) {
380         throw "Failed optimizing testUncheckedLessThanZero(). None of the tested case need to OSR Exit.";
381     }
382
383     for (let i = 1; i < 1e5; ++i) {
384         if (opaqueUncheckedLessThanZero(-i) !== i) {
385             throw "Failed testUncheckedLessThanZero()";
386         }
387         if (opaqueUncheckedLessThanZero(-2147483648) !== -2147483648) {
388             throw "Failed testUncheckedLessThanZero() on -2147483648";
389         }
390     }
391     if (numberOfDFGCompiles(opaqueUncheckedLessThanZero) > 2) {
392         throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
393     }
394 }
395 testUncheckedLessThanZero();
396
397
398 // Unchecked value <= 0
399 function opaqueUncheckedLessThanOrEqualZero(arg) {
400     if (arg <= 0) {
401         return Math.abs(arg)|0;
402     }
403     throw "We should not be here";
404 }
405 noInline(opaqueUncheckedLessThanOrEqualZero);
406
407 function testUncheckedLessThanOrEqualZero()
408 {
409     for (let i = 1; i < 1e5; ++i) {
410         if (opaqueUncheckedLessThanOrEqualZero(-i) !== i) {
411             throw "Failed testUncheckedLessThanOrEqualZero()";
412         }
413         if (opaqueUncheckedLessThanOrEqualZero(0) !== 0) {
414             throw "Failed testUncheckedLessThanOrEqualZero() on 0";
415         }
416         if (opaqueUncheckedLessThanOrEqualZero(-2147483647) !== 2147483647) {
417             throw "Failed testUncheckedLessThanOrEqualZero() on -2147483647";
418         }
419         if (opaqueUncheckedLessThanOrEqualZero(-2147483648) !== -2147483648) {
420             throw "Failed testUncheckedLessThanOrEqualZero() on -2147483648";
421         }
422     }
423     if (numberOfDFGCompiles(opaqueUncheckedLessThanOrEqualZero) > 1) {
424         throw "Failed optimizing testUncheckedLessThanOrEqualZero(). None of the tested case need to OSR Exit.";
425     }
426 }
427 testUncheckedLessThanOrEqualZero();