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