]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/representations/representations-tests.factor
factor: second stab at [ ] [ ] unit-test -> { } [ ] unit-test
[factor.git] / basis / compiler / cfg / representations / representations-tests.factor
1 USING: accessors compiler.cfg compiler.cfg.debugger
2 compiler.cfg.instructions compiler.cfg.registers
3 compiler.cfg.representations.preferred cpu.architecture kernel
4 namespaces tools.test sequences arrays system literals layouts
5 math compiler.constants compiler.cfg.representations.conversion
6 compiler.cfg.representations.rewrite
7 compiler.cfg.comparisons compiler.cfg.utilities
8 make ;
9 FROM: alien.c-types => char ;
10 IN: compiler.cfg.representations
11
12 { { double-rep double-rep } } [
13     T{ ##add-float
14        { dst 5 }
15        { src1 3 }
16        { src2 4 }
17     } uses-vreg-reps
18 ] unit-test
19
20 { { double-rep } } [
21     T{ ##load-memory-imm
22        { dst 5 }
23        { base 3 }
24        { offset 0 }
25        { rep double-rep }
26     } defs-vreg-reps
27 ] unit-test
28
29 H{ } clone representations set
30
31 3 vreg-counter set-global
32
33 {
34     {
35         T{ ##allot f 2 16 float 4 }
36         T{ ##store-memory-imm f 1 2 $[ float-offset ] double-rep f }
37     }
38 } [
39     [
40         2 1 tagged-rep double-rep emit-conversion
41     ] { } make
42 ] unit-test
43
44 {
45     {
46         T{ ##load-memory-imm f 2 1 $[ float-offset ] double-rep f }
47     }
48 } [
49     [
50         2 1 double-rep tagged-rep emit-conversion
51     ] { } make
52 ] unit-test
53
54 : test-representations ( -- )
55     0 get block>cfg dup cfg set select-representations ;
56
57 ! Make sure cost calculation isn't completely wrong
58 V{
59     T{ ##prologue }
60     T{ ##branch }
61 } 0 test-bb
62
63 V{
64     T{ ##peek f 1 D 0 }
65     T{ ##peek f 2 D 1 }
66     T{ ##add-float f 3 1 2 }
67     T{ ##replace f 3 D 0 }
68     T{ ##replace f 3 D 1 }
69     T{ ##replace f 3 D 2 }
70     T{ ##branch }
71 } 1 test-bb
72
73 V{
74     T{ ##epilogue }
75     T{ ##return }
76 } 2 test-bb
77
78 0 1 edge
79 1 2 edge
80
81 { } [ test-representations ] unit-test
82
83 { 1 } [ 1 get instructions>> [ ##allot? ] count ] unit-test
84
85 ! Don't dereference the result of a peek
86 V{
87     T{ ##prologue }
88     T{ ##branch }
89 } 0 test-bb
90
91 V{
92     T{ ##peek f 1 D 0 }
93     T{ ##branch }
94 } 1 test-bb
95
96 V{
97     T{ ##add-float f 2 1 1 }
98     T{ ##replace f 2 D 0 }
99     T{ ##epilogue }
100     T{ ##return }
101 } 2 test-bb
102
103 V{
104     T{ ##add-float f 3 1 1 }
105     T{ ##replace f 3 D 0 }
106     T{ ##epilogue }
107     T{ ##return }
108 } 3 test-bb
109
110 0 1 edge
111 1 { 2 3 } edges
112
113 { } [ test-representations ] unit-test
114
115 {
116     V{
117         T{ ##peek f 1 D 0 }
118         T{ ##branch }
119     }
120 } [ 1 get instructions>> ] unit-test
121
122 ! We cannot untag-fixnum the result of a peek if there are usages
123 ! of it as a tagged-rep
124 V{
125     T{ ##prologue }
126     T{ ##branch }
127 } 0 test-bb
128
129 V{
130     T{ ##peek f 1 D 0 }
131     T{ ##branch }
132 } 1 test-bb
133
134 V{
135     T{ ##replace f 1 R 0 }
136     T{ ##epilogue }
137     T{ ##return }
138 } 2 test-bb
139
140 V{
141     T{ ##mul f 2 1 1 }
142     T{ ##replace f 2 D 0 }
143     T{ ##branch }
144 } 3 test-bb
145
146 V{
147     T{ ##epilogue }
148     T{ ##return }
149 } 4 test-bb
150
151 0 1 edge
152 1 { 2 3 } edges
153 3 { 3 4 } edges
154 2 4 edge
155
156 { } [ test-representations ] unit-test
157
158 {
159     V{
160         T{ ##peek f 1 D 0 }
161         T{ ##branch }
162     }
163 } [ 1 get instructions>> ] unit-test
164
165 ! But its ok to untag-fixnum the result of a peek if all usages use
166 ! it as int-rep
167 V{
168     T{ ##prologue }
169     T{ ##branch }
170 } 0 test-bb
171
172 V{
173     T{ ##peek f 1 D 0 }
174     T{ ##branch }
175 } 1 test-bb
176
177 V{
178     T{ ##epilogue }
179     T{ ##return }
180 } 2 test-bb
181
182 V{
183     T{ ##add f 2 1 1 }
184     T{ ##mul f 3 1 1 }
185     T{ ##replace f 2 D 0 }
186     T{ ##replace f 3 D 1 }
187     T{ ##branch }
188 } 3 test-bb
189
190 V{
191     T{ ##epilogue }
192     T{ ##return }
193 } 4 test-bb
194
195 0 1 edge
196 1 { 2 3 } edges
197 3 { 3 4 } edges
198 2 4 edge
199
200 3 vreg-counter set-global
201
202 { } [ test-representations ] unit-test
203
204 {
205     V{
206         T{ ##peek f 4 D 0 }
207         T{ ##sar-imm f 1 4 $[ tag-bits get ] }
208         T{ ##branch }
209     }
210 } [ 1 get instructions>> ] unit-test
211
212 ! scalar-rep => int-rep conversion
213 V{
214     T{ ##prologue }
215     T{ ##branch }
216 } 0 test-bb
217
218 V{
219     T{ ##peek f 1 D 0 }
220     T{ ##peek f 2 D 0 }
221     T{ ##vector>scalar f 3 2 int-4-rep }
222     T{ ##replace f 3 D 0 }
223     T{ ##branch }
224 } 1 test-bb
225
226 V{
227     T{ ##epilogue }
228     T{ ##return }
229 } 2 test-bb
230
231 0 1 edge
232 1 2 edge
233
234 { } [ test-representations ] unit-test
235
236 { t } [ 1 get instructions>> 4 swap nth ##scalar>integer? ] unit-test
237
238 ! Test phi node behavior
239 V{
240     T{ ##prologue }
241     T{ ##branch }
242 } 0 test-bb
243
244 V{
245     T{ ##load-integer f 1 1 }
246     T{ ##branch }
247 } 1 test-bb
248
249 V{
250     T{ ##load-integer f 2 2 }
251     T{ ##branch }
252 } 2 test-bb
253
254 V{
255     T{ ##phi f 3 H{ { 1 1 } { 2 2 } } }
256     T{ ##replace f 3 D 0 }
257     T{ ##branch }
258 } 3 test-bb
259
260 V{
261     T{ ##epilogue }
262     T{ ##return }
263 } 4 test-bb
264
265 0 { 1 2 } edges
266 1 3 edge
267 2 3 edge
268 3 4 edge
269
270 { } [ test-representations ] unit-test
271
272 { T{ ##load-tagged f 1 $[ 1 tag-fixnum ] } }
273 [ 1 get instructions>> first ]
274 unit-test
275
276 { T{ ##load-tagged f 2 $[ 2 tag-fixnum ] } }
277 [ 2 get instructions>> first ]
278 unit-test
279
280 ! ##load-reference corner case
281 V{
282     T{ ##prologue }
283     T{ ##branch }
284 } 0 test-bb
285
286 V{
287     T{ ##peek f 0 D 0 }
288     T{ ##peek f 1 D 1 }
289     T{ ##add f 2 0 1 }
290     T{ ##branch }
291 } 1 test-bb
292
293 V{
294     T{ ##load-reference f 3 f }
295     T{ ##branch }
296 } 2 test-bb
297
298 V{
299     T{ ##phi f 4 H{ { 1 2 } { 2 3 } } }
300     T{ ##replace f 4 D 0 }
301     T{ ##branch }
302 } 3 test-bb
303
304 V{
305     T{ ##epilogue }
306     T{ ##return }
307 } 4 test-bb
308
309 0 { 1 2 } edges
310 1 3 edge
311 2 3 edge
312 3 4 edge
313
314 { } [ test-representations ] unit-test
315
316 ! Don't untag the f!
317 { 2 } [ 2 get instructions>> length ] unit-test
318
319 cpu x86.32? [
320
321     ! Make sure load-constant is converted into load-double
322     V{
323         T{ ##prologue }
324         T{ ##branch }
325     } 0 test-bb
326
327     V{
328         T{ ##peek f 1 D 0 }
329         T{ ##load-reference f 2 0.5 }
330         T{ ##add-float f 3 1 2 }
331         T{ ##replace f 3 D 0 }
332         T{ ##branch }
333     } 1 test-bb
334
335     V{
336         T{ ##epilogue }
337         T{ ##return }
338     } 2 test-bb
339
340     0 1 edge
341     1 2 edge
342
343     [ ] [ test-representations ] unit-test
344
345     [ t ] [ 1 get instructions>> second ##load-double? ] unit-test
346
347     ! Make sure phi nodes are handled in a sane way
348     V{
349         T{ ##prologue }
350         T{ ##branch }
351     } 0 test-bb
352
353     V{
354         T{ ##peek f 1 D 0 }
355         T{ ##compare-imm-branch f 1 2 cc= }
356     } 1 test-bb
357
358     V{
359         T{ ##load-reference f 2 1.5 }
360         T{ ##branch }
361     } 2 test-bb
362
363     V{
364         T{ ##load-reference f 3 2.5 }
365         T{ ##branch }
366     } 3 test-bb
367
368     V{
369         T{ ##phi f 4 H{ { 2 2 } { 3 3 } } }
370         T{ ##peek f 5 D 0 }
371         T{ ##add-float f 6 4 5 }
372         T{ ##replace f 6 D 0 }
373     } 4 test-bb
374
375     V{
376         T{ ##epilogue }
377         T{ ##return }
378     } 5 test-bb
379
380     test-diamond
381     4 5 edge
382
383     [ ] [ test-representations ] unit-test
384
385     [ t ] [ 2 get instructions>> first ##load-double? ] unit-test
386
387     [ t ] [ 3 get instructions>> first ##load-double? ] unit-test
388
389     [ t ] [ 4 get instructions>> first ##phi? ] unit-test
390 ] when
391
392 : test-peephole ( insns -- insns )
393     0 test-bb
394     test-representations
395     0 get instructions>> ;
396
397 ! Don't convert the def site into anything but tagged-rep since
398 ! we might lose precision
399 5 vreg-counter set-global
400
401 { f } [
402     V{
403         T{ ##peek f 0 D 0 }
404         T{ ##peek f 1 D 1 }
405         T{ ##tagged>integer f 2 1 }
406         T{ ##add-float f 3 0 0 }
407         T{ ##store-memory-imm f 3 2 0 float-rep f }
408         T{ ##store-memory-imm f 3 2 4 float-rep f }
409         T{ ##mul-float f 4 0 0 }
410         T{ ##replace f 4 D 0 }
411     } test-peephole
412     [ ##single>double-float? ] any?
413 ] unit-test
414
415 ! Converting a ##load-integer into a ##load-tagged
416 {
417     V{
418         T{ ##load-tagged f 1 $[ 100 tag-fixnum ] }
419         T{ ##replace f 1 D 0 }
420     }
421 } [
422     V{
423         T{ ##load-integer f 1 100 }
424         T{ ##replace f 1 D 0 }
425     } test-peephole
426 ] unit-test
427
428 ! Peephole optimization if input to ##shl-imm is tagged
429 3 vreg-counter set-global
430
431 {
432     V{
433         T{ ##peek f 1 D 0 }
434         T{ ##sar-imm f 2 1 1 }
435         T{ ##add f 4 2 2 }
436         T{ ##shl-imm f 3 4 $[ tag-bits get ] }
437         T{ ##replace f 3 D 0 }
438     }
439 } [
440     V{
441         T{ ##peek f 1 D 0 }
442         T{ ##shl-imm f 2 1 3 }
443         T{ ##add f 3 2 2 }
444         T{ ##replace f 3 D 0 }
445     } test-peephole
446 ] unit-test
447
448 3 vreg-counter set-global
449
450 {
451     V{
452         T{ ##peek f 1 D 0 }
453         T{ ##shl-imm f 2 1 $[ 10 tag-bits get - ] }
454         T{ ##add f 4 2 2 }
455         T{ ##shl-imm f 3 4 $[ tag-bits get ] }
456         T{ ##replace f 3 D 0 }
457     }
458 } [
459     V{
460         T{ ##peek f 1 D 0 }
461         T{ ##shl-imm f 2 1 10 }
462         T{ ##add f 3 2 2 }
463         T{ ##replace f 3 D 0 }
464     } test-peephole
465 ] unit-test
466
467 {
468     V{
469         T{ ##peek f 1 D 0 }
470         T{ ##copy f 2 1 int-rep }
471         T{ ##add f 5 2 2 }
472         T{ ##shl-imm f 3 5 $[ tag-bits get ] }
473         T{ ##replace f 3 D 0 }
474     }
475 } [
476     V{
477         T{ ##peek f 1 D 0 }
478         T{ ##shl-imm f 2 1 $[ tag-bits get ] }
479         T{ ##add f 3 2 2 }
480         T{ ##replace f 3 D 0 }
481     } test-peephole
482 ] unit-test
483
484 ! Peephole optimization if output of ##shl-imm needs to be tagged
485 {
486     V{
487         T{ ##load-integer f 1 100 }
488         T{ ##shl-imm f 2 1 $[ 3 tag-bits get + ] }
489         T{ ##replace f 2 D 0 }
490     }
491 } [
492     V{
493         T{ ##load-integer f 1 100 }
494         T{ ##shl-imm f 2 1 3 }
495         T{ ##replace f 2 D 0 }
496     } test-peephole
497 ] unit-test
498
499 ! Peephole optimization if both input and output of ##shl-imm
500 ! need to be tagged
501 {
502     V{
503         T{ ##peek f 0 D 0 }
504         T{ ##shl-imm f 1 0 3 }
505         T{ ##replace f 1 D 0 }
506     }
507 } [
508     V{
509         T{ ##peek f 0 D 0 }
510         T{ ##shl-imm f 1 0 3 }
511         T{ ##replace f 1 D 0 }
512     } test-peephole
513 ] unit-test
514
515 ! Peephole optimization if neither input nor output of ##shl-imm need to be tagged
516 {
517     V{
518         T{ ##load-integer f 1 100 }
519         T{ ##shl-imm f 2 1 3 }
520         T{ ##load-integer f 3 100 }
521         T{ ##load-integer f 4 100 }
522         T{ ##store-memory f 2 3 4 0 0 int-rep char }
523     }
524 } [
525     V{
526         T{ ##load-integer f 1 100 }
527         T{ ##shl-imm f 2 1 3 }
528         T{ ##load-integer f 3 100 }
529         T{ ##load-integer f 4 100 }
530         T{ ##store-memory f 2 3 4 0 0 int-rep char }
531     } test-peephole
532 ] unit-test
533
534 6 vreg-counter set-global
535
536 ! Peephole optimization if input to ##sar-imm is tagged
537 {
538     V{
539         T{ ##peek f 1 D 0 }
540         T{ ##sar-imm f 7 1 $[ 3 tag-bits get + ] }
541         T{ ##shl-imm f 2 7 $[ tag-bits get ] }
542         T{ ##replace f 2 D 0 }
543     }
544 } [
545     V{
546         T{ ##peek f 1 D 0 }
547         T{ ##sar-imm f 2 1 3 }
548         T{ ##replace f 2 D 0 }
549     } test-peephole
550 ] unit-test
551
552 6 vreg-counter set-global
553
554 ! (Lack of) peephole optimization if output of ##sar-imm needs to be tagged
555 {
556     V{
557         T{ ##load-integer f 1 100 }
558         T{ ##sar-imm f 7 1 3 }
559         T{ ##shl-imm f 2 7 $[ tag-bits get ] }
560         T{ ##replace f 2 D 0 }
561     }
562 } [
563     V{
564         T{ ##load-integer f 1 100 }
565         T{ ##sar-imm f 2 1 3 }
566         T{ ##replace f 2 D 0 }
567     } test-peephole
568 ] unit-test
569
570 ! Peephole optimization if input of ##sar-imm is tagged but output is untagged
571 ! need to be tagged
572 {
573     V{
574         T{ ##peek f 0 D 0 }
575         T{ ##sar-imm f 1 0 $[ 3 tag-bits get + ] }
576         T{ ##load-integer f 3 100 }
577         T{ ##load-integer f 4 100 }
578         T{ ##store-memory f 1 3 4 0 0 int-rep char }
579     }
580 } [
581     V{
582         T{ ##peek f 0 D 0 }
583         T{ ##sar-imm f 1 0 3 }
584         T{ ##load-integer f 3 100 }
585         T{ ##load-integer f 4 100 }
586         T{ ##store-memory f 1 3 4 0 0 int-rep char }
587     } test-peephole
588 ] unit-test
589
590 ! Peephole optimization if neither input nor output of ##sar-imm need to be tagged
591 {
592     V{
593         T{ ##load-integer f 1 100 }
594         T{ ##sar-imm f 2 1 3 }
595         T{ ##load-integer f 3 100 }
596         T{ ##load-integer f 4 100 }
597         T{ ##store-memory f 2 3 4 0 0 int-rep char }
598     }
599 } [
600     V{
601         T{ ##load-integer f 1 100 }
602         T{ ##sar-imm f 2 1 3 }
603         T{ ##load-integer f 3 100 }
604         T{ ##load-integer f 4 100 }
605         T{ ##store-memory f 2 3 4 0 0 int-rep char }
606     } test-peephole
607 ] unit-test
608
609 {
610     V{
611         T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } short-8-rep }
612         T{ ##select-vector f 1 0 0 short-8-rep }
613         T{ ##sar-imm f 2 1 3 }
614         T{ ##load-integer f 3 100 }
615         T{ ##add f 4 2 3 }
616         T{ ##load-integer f 5 100 }
617         T{ ##load-integer f 6 100 }
618         T{ ##store-memory f 4 5 6 0 0 int-rep char }
619     }
620 } [
621     V{
622         T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } short-8-rep }
623         T{ ##select-vector f 1 0 0 short-8-rep }
624         T{ ##sar-imm f 2 1 3 }
625         T{ ##load-integer f 3 100 }
626         T{ ##add f 4 2 3 }
627         T{ ##load-integer f 5 100 }
628         T{ ##load-integer f 6 100 }
629         T{ ##store-memory f 4 5 6 0 0 int-rep char }
630     } test-peephole
631 ] unit-test
632
633 6 vreg-counter set-global
634
635 {
636     V{
637         T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } int-4-rep }
638         T{ ##select-vector f 1 0 0 int-4-rep }
639         T{ ##sar-imm f 2 1 3 }
640         T{ ##load-integer f 3 100 }
641         T{ ##add f 7 2 3 }
642         T{ ##shl-imm f 4 7 $[ tag-bits get ] }
643         T{ ##replace f 4 D 0 }
644     }
645 } [
646     V{
647         T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } int-4-rep }
648         T{ ##select-vector f 1 0 0 int-4-rep }
649         T{ ##sar-imm f 2 1 3 }
650         T{ ##load-integer f 3 100 }
651         T{ ##add f 4 2 3 }
652         T{ ##replace f 4 D 0 }
653     } test-peephole
654 ] unit-test
655
656 ! Tag/untag elimination
657 {
658     V{
659         T{ ##peek f 1 D 0 }
660         T{ ##add-imm f 2 1 $[ 100 tag-fixnum ] }
661         T{ ##replace f 2 D 0 }
662     }
663 } [
664     V{
665         T{ ##peek f 1 D 0 }
666         T{ ##add-imm f 2 1 100 }
667         T{ ##replace f 2 D 0 }
668     } test-peephole
669 ] unit-test
670
671 {
672     V{
673         T{ ##peek f 0 D 0 }
674         T{ ##peek f 1 D 1 }
675         T{ ##add f 2 0 1 }
676         T{ ##replace f 2 D 0 }
677     }
678 } [
679     V{
680         T{ ##peek f 0 D 0 }
681         T{ ##peek f 1 D 1 }
682         T{ ##add f 2 0 1 }
683         T{ ##replace f 2 D 0 }
684     } test-peephole
685 ] unit-test
686
687 ! Make sure we don't exceed immediate bounds
688 cpu x86.64? [
689     4 vreg-counter set-global
690
691     [
692         V{
693             T{ ##peek f 0 D 0 }
694             T{ ##sar-imm f 5 0 $[ tag-bits get ] }
695             T{ ##add-imm f 6 5 $[ 30 2^ ] }
696             T{ ##shl-imm f 2 6 $[ tag-bits get ] }
697             T{ ##replace f 2 D 0 }
698         }
699     ] [
700         V{
701             T{ ##peek f 0 D 0 }
702             T{ ##add-imm f 2 0 $[ 30 2^ ] }
703             T{ ##replace f 2 D 0 }
704         } test-peephole
705     ] unit-test
706
707     [
708         V{
709             T{ ##load-integer f 0 100 }
710             T{ ##mul-imm f 7 0 $[ 30 2^ ] }
711             T{ ##shl-imm f 1 7 $[ tag-bits get ] }
712             T{ ##replace f 1 D 0 }
713         }
714     ] [
715         V{
716             T{ ##load-integer f 0 100 }
717             T{ ##mul-imm f 1 0 $[ 30 2^ ] }
718             T{ ##replace f 1 D 0 }
719         } test-peephole
720     ] unit-test
721 ] when
722
723 ! Tag/untag elimination for ##mul-imm
724 {
725     V{
726         T{ ##peek f 0 D 0 }
727         T{ ##mul-imm f 1 0 100 }
728         T{ ##replace f 1 D 0 }
729     }
730 } [
731     V{
732         T{ ##peek f 0 D 0 }
733         T{ ##mul-imm f 1 0 100 }
734         T{ ##replace f 1 D 0 }
735     } test-peephole
736 ] unit-test
737
738 4 vreg-counter set-global
739
740 {
741     V{
742         T{ ##peek f 0 D 0 }
743         T{ ##peek f 1 D 1 }
744         T{ ##sar-imm f 5 1 $[ tag-bits get ] }
745         T{ ##add-imm f 2 5 30 }
746         T{ ##mul-imm f 3 2 $[ 100 tag-fixnum ] }
747         T{ ##replace f 3 D 0 }
748     }
749 } [
750     V{
751         T{ ##peek f 0 D 0 }
752         T{ ##peek f 1 D 1 }
753         T{ ##add-imm f 2 1 30 }
754         T{ ##mul-imm f 3 2 100 }
755         T{ ##replace f 3 D 0 }
756     } test-peephole
757 ] unit-test
758
759 ! Tag/untag elimination for ##compare-integer and ##test
760 {
761     V{
762         T{ ##peek f 0 D 0 }
763         T{ ##peek f 1 D 1 }
764         T{ ##test f 2 0 1 cc= }
765         T{ ##replace f 2 D 0 }
766     }
767 } [
768     V{
769         T{ ##peek f 0 D 0 }
770         T{ ##peek f 1 D 1 }
771         T{ ##test f 2 0 1 cc= }
772         T{ ##replace f 2 D 0 }
773     } test-peephole
774 ] unit-test
775
776 {
777     V{
778         T{ ##peek f 0 D 0 }
779         T{ ##peek f 1 D 1 }
780         T{ ##compare-integer f 2 0 1 cc= }
781         T{ ##replace f 2 D 0 }
782     }
783 } [
784     V{
785         T{ ##peek f 0 D 0 }
786         T{ ##peek f 1 D 1 }
787         T{ ##compare-integer f 2 0 1 cc= }
788         T{ ##replace f 2 D 0 }
789     } test-peephole
790 ] unit-test
791
792 {
793     V{
794         T{ ##peek f 0 D 0 }
795         T{ ##peek f 1 D 1 }
796         T{ ##compare-integer-branch f 0 1 cc= }
797     }
798 } [
799     V{
800         T{ ##peek f 0 D 0 }
801         T{ ##peek f 1 D 1 }
802         T{ ##compare-integer-branch f 0 1 cc= }
803     } test-peephole
804 ] unit-test
805
806 {
807     V{
808         T{ ##peek f 0 D 0 }
809         T{ ##peek f 1 D 1 }
810         T{ ##test-branch f 0 1 cc= }
811     }
812 } [
813     V{
814         T{ ##peek f 0 D 0 }
815         T{ ##peek f 1 D 1 }
816         T{ ##test-branch f 0 1 cc= }
817     } test-peephole
818 ] unit-test
819
820 {
821     V{
822         T{ ##peek f 0 D 0 }
823         T{ ##peek f 1 D 1 }
824         T{ ##compare-integer-imm-branch f 0 $[ 10 tag-fixnum ] cc= }
825     }
826 } [
827     V{
828         T{ ##peek f 0 D 0 }
829         T{ ##peek f 1 D 1 }
830         T{ ##compare-integer-imm-branch f 0 10 cc= }
831     } test-peephole
832 ] unit-test
833
834 {
835     V{
836         T{ ##peek f 0 D 0 }
837         T{ ##peek f 1 D 1 }
838         T{ ##test-imm-branch f 0 $[ 10 tag-fixnum ] cc= }
839     }
840 } [
841     V{
842         T{ ##peek f 0 D 0 }
843         T{ ##peek f 1 D 1 }
844         T{ ##test-imm-branch f 0 10 cc= }
845     } test-peephole
846 ] unit-test
847
848 ! Tag/untag elimination for ##neg
849 {
850     V{
851         T{ ##peek f 0 D 0 }
852         T{ ##neg f 1 0 }
853         T{ ##replace f 1 D 0 }
854     }
855 } [
856     V{
857         T{ ##peek f 0 D 0 }
858         T{ ##neg f 1 0 }
859         T{ ##replace f 1 D 0 }
860     } test-peephole
861 ] unit-test
862
863 4 vreg-counter set-global
864
865 {
866     V{
867         T{ ##peek { dst 0 } { loc D 0 } }
868         T{ ##peek { dst 1 } { loc D 1 } }
869         T{ ##sar-imm { dst 5 } { src1 0 } { src2 4 } }
870         T{ ##sar-imm { dst 6 } { src1 1 } { src2 4 } }
871         T{ ##mul { dst 2 } { src1 5 } { src2 6 } }
872         T{ ##mul-imm { dst 3 } { src1 2 } { src2 -16 } }
873         T{ ##replace { src 3 } { loc D 0 } }
874     }
875 } [
876     V{
877         T{ ##peek f 0 D 0 }
878         T{ ##peek f 1 D 1 }
879         T{ ##mul f 2 0 1 }
880         T{ ##neg f 3 2 }
881         T{ ##replace f 3 D 0 }
882     } test-peephole
883 ] unit-test
884
885 ! Tag/untag elimination for ##not
886 2 vreg-counter set-global
887
888 {
889     V{
890         T{ ##peek f 0 D 0 }
891         T{ ##not f 3 0 }
892         T{ ##xor-imm f 1 3 $[ tag-mask get ] }
893         T{ ##replace f 1 D 0 }
894     }
895 } [
896     V{
897         T{ ##peek f 0 D 0 }
898         T{ ##not f 1 0 }
899         T{ ##replace f 1 D 0 }
900     } test-peephole
901 ] unit-test