1// Copyright 2013 the V8 project authors. All rights reserved.
2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions
6// are met:
7// 1.  Redistributions of source code must retain the above copyright
8//     notice, this list of conditions and the following disclaimer.
9// 2.  Redistributions in binary form must reproduce the above copyright
10//     notice, this list of conditions and the following disclaimer in the
11//     documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24description(
25"Tests loop codegen when the condition is a logical node."
26);
27
28function while_or_eq()
29{
30    var a = 0;
31    while (a == 0 || a == 0)
32        return true;
33    return false;
34}
35
36shouldBeTrue("while_or_eq()");
37
38function while_or_neq()
39{
40    var a = 0;
41    while (a != 1 || a != 1)
42        return true;
43    return false;
44}
45
46shouldBeTrue("while_or_neq()");
47
48function while_or_less()
49{
50    var a = 0;
51    while (a < 1 || a < 1)
52        return true;
53    return false;
54}
55
56shouldBeTrue("while_or_less()");
57
58function while_or_lesseq()
59{
60    var a = 0;
61    while (a <= 1 || a <= 1)
62        return true;
63    return false;
64}
65
66shouldBeTrue("while_or_lesseq()");
67
68function while_and_eq()
69{
70    var a = 0;
71    while (a == 0 && a == 0)
72        return true;
73    return false;
74}
75
76shouldBeTrue("while_and_eq()");
77
78function while_and_neq()
79{
80    var a = 0;
81    while (a != 1 && a != 1)
82        return true;
83    return false;
84}
85
86shouldBeTrue("while_and_neq()");
87
88function while_and_less()
89{
90    var a = 0;
91    while (a < 1 && a < 1)
92        return true;
93    return false;
94}
95
96shouldBeTrue("while_and_less()");
97
98function while_and_lesseq()
99{
100    var a = 0;
101    while (a <= 1 && a <= 1)
102        return true;
103    return false;
104}
105
106shouldBeTrue("while_and_lesseq()");
107
108function for_or_eq()
109{
110    for (var a = 0; a == 0 || a == 0; )
111        return true;
112    return false;
113}
114
115shouldBeTrue("for_or_eq()");
116
117function for_or_neq()
118{
119    for (var a = 0; a != 1 || a != 1; )
120        return true;
121    return false;
122}
123
124shouldBeTrue("for_or_neq()");
125
126function for_or_less()
127{
128    for (var a = 0; a < 1 || a < 1; )
129        return true;
130    return false;
131}
132
133shouldBeTrue("for_or_less()");
134
135function for_or_lesseq()
136{
137    for (var a = 0; a <= 1 || a <= 1; )
138        return true;
139    return false;
140}
141
142shouldBeTrue("for_or_lesseq()");
143
144function for_and_eq()
145{
146    for (var a = 0; a == 0 && a == 0; )
147        return true;
148    return false;
149}
150
151shouldBeTrue("for_and_eq()");
152
153function for_and_neq()
154{
155    for (var a = 0; a != 1 && a != 1; )
156        return true;
157    return false;
158}
159
160shouldBeTrue("for_and_neq()");
161
162function for_and_less()
163{
164    for (var a = 0; a < 1 && a < 1; )
165        return true;
166    return false;
167}
168
169shouldBeTrue("for_and_less()");
170
171function for_and_lesseq()
172{
173    for (var a = 0; a <= 1 && a <= 1; )
174        return true;
175    return false;
176}
177
178shouldBeTrue("for_and_lesseq()");
179
180function dowhile_or_eq()
181{
182    var a = 0;
183    var i = 0;
184    do {
185        if (i > 0)
186            return true;
187        i++;
188    } while (a == 0 || a == 0)
189    return false;
190}
191
192shouldBeTrue("dowhile_or_eq()");
193
194function dowhile_or_neq()
195{
196    var a = 0;
197    var i = 0;
198    do {
199        if (i > 0)
200            return true;
201        i++;
202    } while (a != 1 || a != 1)
203    return false;
204}
205
206shouldBeTrue("dowhile_or_neq()");
207
208function dowhile_or_less()
209{
210    var a = 0;
211    var i = 0;
212    do {
213        if (i > 0)
214            return true;
215        i++;
216    } while (a < 1 || a < 1)
217    return false;
218}
219
220shouldBeTrue("dowhile_or_less()");
221
222function dowhile_or_lesseq()
223{
224    var a = 0;
225    var i = 0;
226    do {
227        if (i > 0)
228            return true;
229        i++;
230    } while (a <= 1 || a <= 1)
231    return false;
232}
233
234shouldBeTrue("dowhile_or_lesseq()");
235
236function dowhile_and_eq()
237{
238    var a = 0;
239    var i = 0;
240    do {
241        if (i > 0)
242            return true;
243        i++;
244    } while (a == 0 && a == 0)
245    return false;
246}
247
248shouldBeTrue("dowhile_and_eq()");
249
250function dowhile_and_neq()
251{
252    var a = 0;
253    var i = 0;
254    do {
255        if (i > 0)
256            return true;
257        i++;
258    } while (a != 1 && a != 1)
259    return false;
260}
261
262shouldBeTrue("dowhile_and_neq()");
263
264function dowhile_and_less()
265{
266    var a = 0;
267    var i = 0;
268    do {
269        if (i > 0)
270            return true;
271        i++;
272    } while (a < 1 && a < 1)
273    return false;
274}
275
276shouldBeTrue("dowhile_and_less()");
277
278function dowhile_and_lesseq()
279{
280    var a = 0;
281    var i = 0;
282    do {
283        if (i > 0)
284            return true;
285        i++;
286    } while (a <= 1 && a <= 1)
287    return false;
288}
289
290shouldBeTrue("dowhile_and_lesseq()");
291
292function while_not_or_eq()
293{
294    var a = 0;
295    while (!(a == 0 || a == 0))
296        return true;
297    return false;
298}
299
300shouldBeFalse("while_not_or_eq()");
301
302function while_not_or_neq()
303{
304    var a = 0;
305    while (!(a != 1 || a != 1))
306        return true;
307    return false;
308}
309
310shouldBeFalse("while_not_or_neq()");
311
312function while_not_or_less()
313{
314    var a = 0;
315    while (!(a < 1 || a < 1))
316        return true;
317    return false;
318}
319
320shouldBeFalse("while_not_or_less()");
321
322function while_not_or_lesseq()
323{
324    var a = 0;
325    while (!(a <= 1 || a <= 1))
326        return true;
327    return false;
328}
329
330shouldBeFalse("while_not_or_lesseq()");
331
332function while_not_and_eq()
333{
334    var a = 0;
335    while (!(a == 0 && a == 0))
336        return true;
337    return false;
338}
339
340shouldBeFalse("while_not_and_eq()");
341
342function while_not_and_neq()
343{
344    var a = 0;
345    while (!(a != 1 && a != 1))
346        return true;
347    return false;
348}
349
350shouldBeFalse("while_not_and_neq()");
351
352function while_not_and_less()
353{
354    var a = 0;
355    while (!(a < 1 && a < 1))
356        return true;
357    return false;
358}
359
360shouldBeFalse("while_not_and_less()");
361
362function while_not_and_lesseq()
363{
364    var a = 0;
365    while (!(a <= 1 && a <= 1))
366        return true;
367    return false;
368}
369
370shouldBeFalse("while_not_and_lesseq()");
371
372function for_not_or_eq()
373{
374    for (var a = 0; !(a == 0 || a == 0); )
375        return true;
376    return false;
377}
378
379shouldBeFalse("for_not_or_eq()");
380
381function for_not_or_neq()
382{
383    for (var a = 0; !(a != 1 || a != 1); )
384        return true;
385    return false;
386}
387
388shouldBeFalse("for_not_or_neq()");
389
390function for_not_or_less()
391{
392    for (var a = 0; !(a < 1 || a < 1); )
393        return true;
394    return false;
395}
396
397shouldBeFalse("for_not_or_less()");
398
399function for_not_or_lesseq()
400{
401    for (var a = 0; !(a <= 1 || a <= 1); )
402        return true;
403    return false;
404}
405
406shouldBeFalse("for_not_or_lesseq()");
407
408function for_not_and_eq()
409{
410    for (var a = 0; !(a == 0 && a == 0); )
411        return true;
412    return false;
413}
414
415shouldBeFalse("for_not_and_eq()");
416
417function for_not_and_neq()
418{
419    for (var a = 0; !(a != 1 && a != 1); )
420        return true;
421    return false;
422}
423
424shouldBeFalse("for_not_and_neq()");
425
426function for_not_and_less()
427{
428    for (var a = 0; !(a < 1 && a < 1); )
429        return true;
430    return false;
431}
432
433shouldBeFalse("for_not_and_less()");
434
435function for_not_and_lesseq()
436{
437    for (var a = 0; !(a <= 1 && a <= 1); )
438        return true;
439    return false;
440}
441
442shouldBeFalse("for_not_and_lesseq()");
443
444function dowhile_not_or_eq()
445{
446    var a = 0;
447    var i = 0;
448    do {
449        if (i > 0)
450            return true;
451        i++;
452    } while (!(a == 0 || a == 0))
453    return false;
454}
455
456shouldBeFalse("dowhile_not_or_eq()");
457
458function dowhile_not_or_neq()
459{
460    var a = 0;
461    var i = 0;
462    do {
463        if (i > 0)
464            return true;
465        i++;
466    } while (!(a != 1 || a != 1))
467    return false;
468}
469
470shouldBeFalse("dowhile_not_or_neq()");
471
472function dowhile_not_or_less()
473{
474    var a = 0;
475    var i = 0;
476    do {
477        if (i > 0)
478            return true;
479        i++;
480    } while (!(a < 1 || a < 1))
481    return false;
482}
483
484shouldBeFalse("dowhile_not_or_less()");
485
486function dowhile_not_or_lesseq()
487{
488    var a = 0;
489    var i = 0;
490    do {
491        if (i > 0)
492            return true;
493        i++;
494    } while (!(a <= 1 || a <= 1))
495    return false;
496}
497
498shouldBeFalse("dowhile_not_or_lesseq()");
499
500function dowhile_not_and_eq()
501{
502    var a = 0;
503    var i = 0;
504    do {
505        if (i > 0)
506            return true;
507        i++;
508    } while (!(a == 0 && a == 0))
509    return false;
510}
511
512shouldBeFalse("dowhile_not_and_eq()");
513
514function dowhile_not_and_neq()
515{
516    var a = 0;
517    var i = 0;
518    do {
519        if (i > 0)
520            return true;
521        i++;
522    } while (!(a != 1 && a != 1))
523    return false;
524}
525
526shouldBeFalse("dowhile_not_and_neq()");
527
528function dowhile_not_and_less()
529{
530    var a = 0;
531    var i = 0;
532    do {
533        if (i > 0)
534            return true;
535        i++;
536    } while (!(a < 1 && a < 1))
537    return false;
538}
539
540shouldBeFalse("dowhile_not_and_less()");
541
542function dowhile_not_and_lesseq()
543{
544    var a = 0;
545    var i = 0;
546    do {
547        if (i > 0)
548            return true;
549        i++;
550    } while (!(a <= 1 && a <= 1))
551    return false;
552}
553
554shouldBeFalse("dowhile_not_and_lesseq()");
555
556function float_while_or_eq()
557{
558    var a = 0.1;
559    while (a == 0.1 || a == 0.1)
560        return true;
561    return false;
562}
563
564shouldBeTrue("float_while_or_eq()");
565
566function float_while_or_neq()
567{
568    var a = 0.1;
569    while (a != 1.1 || a != 1.1)
570        return true;
571    return false;
572}
573
574shouldBeTrue("float_while_or_neq()");
575
576function float_while_or_less()
577{
578    var a = 0.1;
579    while (a < 1.1 || a < 1.1)
580        return true;
581    return false;
582}
583
584shouldBeTrue("float_while_or_less()");
585
586function float_while_or_lesseq()
587{
588    var a = 0.1;
589    while (a <= 1.1 || a <= 1.1)
590        return true;
591    return false;
592}
593
594shouldBeTrue("float_while_or_lesseq()");
595
596function float_while_and_eq()
597{
598    var a = 0.1;
599    while (a == 0.1 && a == 0.1)
600        return true;
601    return false;
602}
603
604shouldBeTrue("float_while_and_eq()");
605
606function float_while_and_neq()
607{
608    var a = 0.1;
609    while (a != 1.1 && a != 1.1)
610        return true;
611    return false;
612}
613
614shouldBeTrue("float_while_and_neq()");
615
616function float_while_and_less()
617{
618    var a = 0.1;
619    while (a < 1.1 && a < 1.1)
620        return true;
621    return false;
622}
623
624shouldBeTrue("float_while_and_less()");
625
626function float_while_and_lesseq()
627{
628    var a = 0.1;
629    while (a <= 1.1 && a <= 1.1)
630        return true;
631    return false;
632}
633
634shouldBeTrue("float_while_and_lesseq()");
635
636function float_for_or_eq()
637{
638    for (var a = 0.1; a == 0.1 || a == 0.1; )
639        return true;
640    return false;
641}
642
643shouldBeTrue("float_for_or_eq()");
644
645function float_for_or_neq()
646{
647    for (var a = 0.1; a != 1.1 || a != 1.1; )
648        return true;
649    return false;
650}
651
652shouldBeTrue("float_for_or_neq()");
653
654function float_for_or_less()
655{
656    for (var a = 0.1; a < 1.1 || a < 1.1; )
657        return true;
658    return false;
659}
660
661shouldBeTrue("float_for_or_less()");
662
663function float_for_or_lesseq()
664{
665    for (var a = 0.1; a <= 1.1 || a <= 1.1; )
666        return true;
667    return false;
668}
669
670shouldBeTrue("float_for_or_lesseq()");
671
672function float_for_and_eq()
673{
674    for (var a = 0.1; a == 0.1 && a == 0.1; )
675        return true;
676    return false;
677}
678
679shouldBeTrue("float_for_and_eq()");
680
681function float_for_and_neq()
682{
683    for (var a = 0.1; a != 1.1 && a != 1.1; )
684        return true;
685    return false;
686}
687
688shouldBeTrue("float_for_and_neq()");
689
690function float_for_and_less()
691{
692    for (var a = 0.1; a < 1.1 && a < 1.1; )
693        return true;
694    return false;
695}
696
697shouldBeTrue("float_for_and_less()");
698
699function float_for_and_lesseq()
700{
701    for (var a = 0.1; a <= 1.1 && a <= 1.1; )
702        return true;
703    return false;
704}
705
706shouldBeTrue("float_for_and_lesseq()");
707
708function float_dowhile_or_eq()
709{
710    var a = 0.1;
711    var i = 0.1;
712    do {
713        if (i > 0.1)
714            return true;
715        i++;
716    } while (a == 0.1 || a == 0.1)
717    return false;
718}
719
720shouldBeTrue("float_dowhile_or_eq()");
721
722function float_dowhile_or_neq()
723{
724    var a = 0.1;
725    var i = 0.1;
726    do {
727        if (i > 0.1)
728            return true;
729        i++;
730    } while (a != 1.1 || a != 1.1)
731    return false;
732}
733
734shouldBeTrue("float_dowhile_or_neq()");
735
736function float_dowhile_or_less()
737{
738    var a = 0.1;
739    var i = 0.1;
740    do {
741        if (i > 0.1)
742            return true;
743        i++;
744    } while (a < 1.1 || a < 1.1)
745    return false;
746}
747
748shouldBeTrue("float_dowhile_or_less()");
749
750function float_dowhile_or_lesseq()
751{
752    var a = 0.1;
753    var i = 0.1;
754    do {
755        if (i > 0.1)
756            return true;
757        i++;
758    } while (a <= 1.1 || a <= 1.1)
759    return false;
760}
761
762shouldBeTrue("float_dowhile_or_lesseq()");
763
764function float_dowhile_and_eq()
765{
766    var a = 0.1;
767    var i = 0.1;
768    do {
769        if (i > 0.1)
770            return true;
771        i++;
772    } while (a == 0.1 && a == 0.1)
773    return false;
774}
775
776shouldBeTrue("float_dowhile_and_eq()");
777
778function float_dowhile_and_neq()
779{
780    var a = 0.1;
781    var i = 0.1;
782    do {
783        if (i > 0.1)
784            return true;
785        i++;
786    } while (a != 1.1 && a != 1.1)
787    return false;
788}
789
790shouldBeTrue("float_dowhile_and_neq()");
791
792function float_dowhile_and_less()
793{
794    var a = 0.1;
795    var i = 0.1;
796    do {
797        if (i > 0.1)
798            return true;
799        i++;
800    } while (a < 1.1 && a < 1.1)
801    return false;
802}
803
804shouldBeTrue("float_dowhile_and_less()");
805
806function float_dowhile_and_lesseq()
807{
808    var a = 0.1;
809    var i = 0.1;
810    do {
811        if (i > 0.1)
812            return true;
813        i++;
814    } while (a <= 1.1 && a <= 1.1)
815    return false;
816}
817
818shouldBeTrue("float_dowhile_and_lesseq()");
819
820function float_while_not_or_eq()
821{
822    var a = 0.1;
823    while (!(a == 0.1 || a == 0.1))
824        return true;
825    return false;
826}
827
828shouldBeFalse("float_while_not_or_eq()");
829
830function float_while_not_or_neq()
831{
832    var a = 0.1;
833    while (!(a != 1.1 || a != 1.1))
834        return true;
835    return false;
836}
837
838shouldBeFalse("float_while_not_or_neq()");
839
840function float_while_not_or_less()
841{
842    var a = 0.1;
843    while (!(a < 1.1 || a < 1.1))
844        return true;
845    return false;
846}
847
848shouldBeFalse("float_while_not_or_less()");
849
850function float_while_not_or_lesseq()
851{
852    var a = 0.1;
853    while (!(a <= 1.1 || a <= 1.1))
854        return true;
855    return false;
856}
857
858shouldBeFalse("float_while_not_or_lesseq()");
859
860function float_while_not_and_eq()
861{
862    var a = 0.1;
863    while (!(a == 0.1 && a == 0.1))
864        return true;
865    return false;
866}
867
868shouldBeFalse("float_while_not_and_eq()");
869
870function float_while_not_and_neq()
871{
872    var a = 0.1;
873    while (!(a != 1.1 && a != 1.1))
874        return true;
875    return false;
876}
877
878shouldBeFalse("float_while_not_and_neq()");
879
880function float_while_not_and_less()
881{
882    var a = 0.1;
883    while (!(a < 1.1 && a < 1.1))
884        return true;
885    return false;
886}
887
888shouldBeFalse("float_while_not_and_less()");
889
890function float_while_not_and_lesseq()
891{
892    var a = 0.1;
893    while (!(a <= 1.1 && a <= 1.1))
894        return true;
895    return false;
896}
897
898shouldBeFalse("float_while_not_and_lesseq()");
899
900function float_for_not_or_eq()
901{
902    for (var a = 0.1; !(a == 0.1 || a == 0.1); )
903        return true;
904    return false;
905}
906
907shouldBeFalse("float_for_not_or_eq()");
908
909function float_for_not_or_neq()
910{
911    for (var a = 0.1; !(a != 1.1 || a != 1.1); )
912        return true;
913    return false;
914}
915
916shouldBeFalse("float_for_not_or_neq()");
917
918function float_for_not_or_less()
919{
920    for (var a = 0.1; !(a < 1.1 || a < 1.1); )
921        return true;
922    return false;
923}
924
925shouldBeFalse("float_for_not_or_less()");
926
927function float_for_not_or_lesseq()
928{
929    for (var a = 0.1; !(a <= 1.1 || a <= 1.1); )
930        return true;
931    return false;
932}
933
934shouldBeFalse("float_for_not_or_lesseq()");
935
936function float_for_not_and_eq()
937{
938    for (var a = 0.1; !(a == 0.1 && a == 0.1); )
939        return true;
940    return false;
941}
942
943shouldBeFalse("float_for_not_and_eq()");
944
945function float_for_not_and_neq()
946{
947    for (var a = 0.1; !(a != 1.1 && a != 1.1); )
948        return true;
949    return false;
950}
951
952shouldBeFalse("float_for_not_and_neq()");
953
954function float_for_not_and_less()
955{
956    for (var a = 0.1; !(a < 1.1 && a < 1.1); )
957        return true;
958    return false;
959}
960
961shouldBeFalse("float_for_not_and_less()");
962
963function float_for_not_and_lesseq()
964{
965    for (var a = 0.1; !(a <= 1.1 && a <= 1.1); )
966        return true;
967    return false;
968}
969
970shouldBeFalse("float_for_not_and_lesseq()");
971
972function float_dowhile_not_or_eq()
973{
974    var a = 0.1;
975    var i = 0.1;
976    do {
977        if (i > 0.1)
978            return true;
979        i++;
980    } while (!(a == 0.1 || a == 0.1))
981    return false;
982}
983
984shouldBeFalse("float_dowhile_not_or_eq()");
985
986function float_dowhile_not_or_neq()
987{
988    var a = 0.1;
989    var i = 0.1;
990    do {
991        if (i > 0.1)
992            return true;
993        i++;
994    } while (!(a != 1.1 || a != 1.1))
995    return false;
996}
997
998shouldBeFalse("float_dowhile_not_or_neq()");
999
1000function float_dowhile_not_or_less()
1001{
1002    var a = 0.1;
1003    var i = 0.1;
1004    do {
1005        if (i > 0.1)
1006            return true;
1007        i++;
1008    } while (!(a < 1.1 || a < 1.1))
1009    return false;
1010}
1011
1012shouldBeFalse("float_dowhile_not_or_less()");
1013
1014function float_dowhile_not_or_lesseq()
1015{
1016    var a = 0.1;
1017    var i = 0.1;
1018    do {
1019        if (i > 0.1)
1020            return true;
1021        i++;
1022    } while (!(a <= 1.1 || a <= 1.1))
1023    return false;
1024}
1025
1026shouldBeFalse("float_dowhile_not_or_lesseq()");
1027
1028function float_dowhile_not_and_eq()
1029{
1030    var a = 0.1;
1031    var i = 0.1;
1032    do {
1033        if (i > 0.1)
1034            return true;
1035        i++;
1036    } while (!(a == 0.1 && a == 0.1))
1037    return false;
1038}
1039
1040shouldBeFalse("float_dowhile_not_and_eq()");
1041
1042function float_dowhile_not_and_neq()
1043{
1044    var a = 0.1;
1045    var i = 0.1;
1046    do {
1047        if (i > 0.1)
1048            return true;
1049        i++;
1050    } while (!(a != 1.1 && a != 1.1))
1051    return false;
1052}
1053
1054shouldBeFalse("float_dowhile_not_and_neq()");
1055
1056function float_dowhile_not_and_less()
1057{
1058    var a = 0.1;
1059    var i = 0.1;
1060    do {
1061        if (i > 0.1)
1062            return true;
1063        i++;
1064    } while (!(a < 1.1 && a < 1.1))
1065    return false;
1066}
1067
1068shouldBeFalse("float_dowhile_not_and_less()");
1069
1070function float_dowhile_not_and_lesseq()
1071{
1072    var a = 0.1;
1073    var i = 0.1;
1074    do {
1075        if (i > 0.1)
1076            return true;
1077        i++;
1078    } while (!(a <= 1.1 && a <= 1.1))
1079    return false;
1080}
1081