1
2
3 package rewriteppc64latelower
4
5 import "internal/buildcfg"
6 import "cmd/compile/internal/ssa/ssaop"
7 import "cmd/compile/internal/ssa"
8
9 func RewriteValue(v *ssa.Value) bool {
10 switch v.Op {
11 case ssaop.OpPPC64ADD:
12 return rewriteValue_OpPPC64ADD(v)
13 case ssaop.OpPPC64AND:
14 return rewriteValue_OpPPC64AND(v)
15 case ssaop.OpPPC64ANDconst:
16 return rewriteValue_OpPPC64ANDconst(v)
17 case ssaop.OpPPC64CMPconst:
18 return rewriteValue_OpPPC64CMPconst(v)
19 case ssaop.OpPPC64ISEL:
20 return rewriteValue_OpPPC64ISEL(v)
21 case ssaop.OpPPC64RLDICL:
22 return rewriteValue_OpPPC64RLDICL(v)
23 case ssaop.OpPPC64RLDICLCC:
24 return rewriteValue_OpPPC64RLDICLCC(v)
25 case ssaop.OpPPC64SETBC:
26 return rewriteValue_OpPPC64SETBC(v)
27 case ssaop.OpPPC64SETBCR:
28 return rewriteValue_OpPPC64SETBCR(v)
29 }
30 return false
31 }
32 func rewriteValue_OpPPC64ADD(v *ssa.Value) bool {
33 v_1 := v.Args[1]
34 v_0 := v.Args[0]
35
36
37
38 for {
39 for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
40 if v_0.Op != ssaop.OpPPC64MOVDconst {
41 continue
42 }
43 m := ssa.AuxIntToInt64(v_0.AuxInt)
44 x := v_1
45 if !(ssa.SupportsPPC64PCRel() && (m<<30)>>30 == m) {
46 continue
47 }
48 v.Reset(ssaop.OpPPC64ADDconst)
49 v.AuxInt = ssa.Int64ToAuxInt(m)
50 v.AddArg(x)
51 return true
52 }
53 break
54 }
55 return false
56 }
57 func rewriteValue_OpPPC64AND(v *ssa.Value) bool {
58 v_1 := v.Args[1]
59 v_0 := v.Args[0]
60
61
62
63 for {
64 for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
65 x := v_0
66 if x.Op != ssaop.OpPPC64MOVDconst {
67 continue
68 }
69 m := ssa.AuxIntToInt64(x.AuxInt)
70 n := v_1
71 if !(ssa.IsPPC64ValidShiftMask(m)) {
72 continue
73 }
74 v.Reset(ssaop.OpPPC64RLDICL)
75 v.AuxInt = ssa.Int64ToAuxInt(ssa.EncodePPC64RotateMask(0, m, 64))
76 v.AddArg(n)
77 return true
78 }
79 break
80 }
81
82
83
84 for {
85 for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
86 x := v_0
87 if x.Op != ssaop.OpPPC64MOVDconst {
88 continue
89 }
90 m := ssa.AuxIntToInt64(x.AuxInt)
91 n := v_1
92 if !(m != 0 && ssa.IsPPC64ValidShiftMask(^m)) {
93 continue
94 }
95 v.Reset(ssaop.OpPPC64RLDICR)
96 v.AuxInt = ssa.Int64ToAuxInt(ssa.EncodePPC64RotateMask(0, m, 64))
97 v.AddArg(n)
98 return true
99 }
100 break
101 }
102
103
104
105 for {
106 t := v.Type
107 for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
108 x := v_0
109 if x.Op != ssaop.OpPPC64MOVDconst {
110 continue
111 }
112 m := ssa.AuxIntToInt64(x.AuxInt)
113 n := v_1
114 if !(t.Size() == 4 && ssa.IsPPC64WordRotateMask(m)) {
115 continue
116 }
117 v.Reset(ssaop.OpPPC64RLWINM)
118 v.AuxInt = ssa.Int64ToAuxInt(ssa.EncodePPC64RotateMask(0, m, 32))
119 v.AddArg(n)
120 return true
121 }
122 break
123 }
124 return false
125 }
126 func rewriteValue_OpPPC64ANDconst(v *ssa.Value) bool {
127 v_0 := v.Args[0]
128
129
130
131 for {
132 m := ssa.AuxIntToInt64(v.AuxInt)
133 x := v_0
134 if !(ssa.IsPPC64ValidShiftMask(m)) {
135 break
136 }
137 v.Reset(ssaop.OpPPC64RLDICL)
138 v.AuxInt = ssa.Int64ToAuxInt(ssa.EncodePPC64RotateMask(0, m, 64))
139 v.AddArg(x)
140 return true
141 }
142 return false
143 }
144 func rewriteValue_OpPPC64CMPconst(v *ssa.Value) bool {
145 v_0 := v.Args[0]
146
147
148
149 for {
150 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
151 break
152 }
153 z := v_0
154 if z.Op != ssaop.OpPPC64ADD {
155 break
156 }
157 if !(v.Block == z.Block) {
158 break
159 }
160 v.Reset(ssaop.OpPPC64CMPconst)
161 v.AuxInt = ssa.Int64ToAuxInt(0)
162 v.AddArg(convertPPC64OpToOpCC(z))
163 return true
164 }
165
166
167
168 for {
169 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
170 break
171 }
172 z := v_0
173 if z.Op != ssaop.OpPPC64AND {
174 break
175 }
176 if !(v.Block == z.Block) {
177 break
178 }
179 v.Reset(ssaop.OpPPC64CMPconst)
180 v.AuxInt = ssa.Int64ToAuxInt(0)
181 v.AddArg(convertPPC64OpToOpCC(z))
182 return true
183 }
184
185
186
187 for {
188 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
189 break
190 }
191 z := v_0
192 if z.Op != ssaop.OpPPC64ANDN {
193 break
194 }
195 if !(v.Block == z.Block) {
196 break
197 }
198 v.Reset(ssaop.OpPPC64CMPconst)
199 v.AuxInt = ssa.Int64ToAuxInt(0)
200 v.AddArg(convertPPC64OpToOpCC(z))
201 return true
202 }
203
204
205
206 for {
207 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
208 break
209 }
210 z := v_0
211 if z.Op != ssaop.OpPPC64OR {
212 break
213 }
214 if !(v.Block == z.Block) {
215 break
216 }
217 v.Reset(ssaop.OpPPC64CMPconst)
218 v.AuxInt = ssa.Int64ToAuxInt(0)
219 v.AddArg(convertPPC64OpToOpCC(z))
220 return true
221 }
222
223
224
225 for {
226 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
227 break
228 }
229 z := v_0
230 if z.Op != ssaop.OpPPC64SUB {
231 break
232 }
233 if !(v.Block == z.Block) {
234 break
235 }
236 v.Reset(ssaop.OpPPC64CMPconst)
237 v.AuxInt = ssa.Int64ToAuxInt(0)
238 v.AddArg(convertPPC64OpToOpCC(z))
239 return true
240 }
241
242
243
244 for {
245 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
246 break
247 }
248 z := v_0
249 if z.Op != ssaop.OpPPC64NOR {
250 break
251 }
252 if !(v.Block == z.Block) {
253 break
254 }
255 v.Reset(ssaop.OpPPC64CMPconst)
256 v.AuxInt = ssa.Int64ToAuxInt(0)
257 v.AddArg(convertPPC64OpToOpCC(z))
258 return true
259 }
260
261
262
263 for {
264 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
265 break
266 }
267 z := v_0
268 if z.Op != ssaop.OpPPC64XOR {
269 break
270 }
271 if !(v.Block == z.Block) {
272 break
273 }
274 v.Reset(ssaop.OpPPC64CMPconst)
275 v.AuxInt = ssa.Int64ToAuxInt(0)
276 v.AddArg(convertPPC64OpToOpCC(z))
277 return true
278 }
279
280
281
282 for {
283 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
284 break
285 }
286 z := v_0
287 if z.Op != ssaop.OpPPC64MULHDU {
288 break
289 }
290 if !(v.Block == z.Block) {
291 break
292 }
293 v.Reset(ssaop.OpPPC64CMPconst)
294 v.AuxInt = ssa.Int64ToAuxInt(0)
295 v.AddArg(convertPPC64OpToOpCC(z))
296 return true
297 }
298
299
300
301 for {
302 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
303 break
304 }
305 z := v_0
306 if z.Op != ssaop.OpPPC64NEG {
307 break
308 }
309 if !(v.Block == z.Block) {
310 break
311 }
312 v.Reset(ssaop.OpPPC64CMPconst)
313 v.AuxInt = ssa.Int64ToAuxInt(0)
314 v.AddArg(convertPPC64OpToOpCC(z))
315 return true
316 }
317
318
319
320 for {
321 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
322 break
323 }
324 z := v_0
325 if z.Op != ssaop.OpPPC64CNTLZD {
326 break
327 }
328 if !(v.Block == z.Block) {
329 break
330 }
331 v.Reset(ssaop.OpPPC64CMPconst)
332 v.AuxInt = ssa.Int64ToAuxInt(0)
333 v.AddArg(convertPPC64OpToOpCC(z))
334 return true
335 }
336
337
338
339 for {
340 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
341 break
342 }
343 z := v_0
344 if z.Op != ssaop.OpPPC64RLDICL {
345 break
346 }
347 if !(v.Block == z.Block) {
348 break
349 }
350 v.Reset(ssaop.OpPPC64CMPconst)
351 v.AuxInt = ssa.Int64ToAuxInt(0)
352 v.AddArg(convertPPC64OpToOpCC(z))
353 return true
354 }
355
356
357
358 for {
359 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
360 break
361 }
362 z := v_0
363 if z.Op != ssaop.OpPPC64ADDconst {
364 break
365 }
366 c := ssa.AuxIntToInt64(z.AuxInt)
367 if !(int64(int16(c)) == c && v.Block == z.Block) {
368 break
369 }
370 v.Reset(ssaop.OpPPC64CMPconst)
371 v.AuxInt = ssa.Int64ToAuxInt(0)
372 v.AddArg(convertPPC64OpToOpCC(z))
373 return true
374 }
375
376
377
378 for {
379 if ssa.AuxIntToInt64(v.AuxInt) != 0 {
380 break
381 }
382 z := v_0
383 if z.Op != ssaop.OpPPC64ANDconst {
384 break
385 }
386 c := ssa.AuxIntToInt64(z.AuxInt)
387 if !(int64(uint16(c)) == c && v.Block == z.Block) {
388 break
389 }
390 v.Reset(ssaop.OpPPC64CMPconst)
391 v.AuxInt = ssa.Int64ToAuxInt(0)
392 v.AddArg(convertPPC64OpToOpCC(z))
393 return true
394 }
395
396
397 for {
398 t := v.Type
399 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
400 break
401 }
402 z := v_0.Args[0]
403 if z.Op != ssaop.OpPPC64ADDCC {
404 break
405 }
406 v.Reset(ssaop.OpSelect1)
407 v.Type = t
408 v.AddArg(z)
409 return true
410 }
411
412
413 for {
414 t := v.Type
415 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
416 break
417 }
418 z := v_0.Args[0]
419 if z.Op != ssaop.OpPPC64ANDCC {
420 break
421 }
422 v.Reset(ssaop.OpSelect1)
423 v.Type = t
424 v.AddArg(z)
425 return true
426 }
427
428
429 for {
430 t := v.Type
431 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
432 break
433 }
434 z := v_0.Args[0]
435 if z.Op != ssaop.OpPPC64ANDNCC {
436 break
437 }
438 v.Reset(ssaop.OpSelect1)
439 v.Type = t
440 v.AddArg(z)
441 return true
442 }
443
444
445 for {
446 t := v.Type
447 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
448 break
449 }
450 z := v_0.Args[0]
451 if z.Op != ssaop.OpPPC64ORCC {
452 break
453 }
454 v.Reset(ssaop.OpSelect1)
455 v.Type = t
456 v.AddArg(z)
457 return true
458 }
459
460
461 for {
462 t := v.Type
463 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
464 break
465 }
466 z := v_0.Args[0]
467 if z.Op != ssaop.OpPPC64SUBCC {
468 break
469 }
470 v.Reset(ssaop.OpSelect1)
471 v.Type = t
472 v.AddArg(z)
473 return true
474 }
475
476
477 for {
478 t := v.Type
479 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
480 break
481 }
482 z := v_0.Args[0]
483 if z.Op != ssaop.OpPPC64NORCC {
484 break
485 }
486 v.Reset(ssaop.OpSelect1)
487 v.Type = t
488 v.AddArg(z)
489 return true
490 }
491
492
493 for {
494 t := v.Type
495 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
496 break
497 }
498 z := v_0.Args[0]
499 if z.Op != ssaop.OpPPC64XORCC {
500 break
501 }
502 v.Reset(ssaop.OpSelect1)
503 v.Type = t
504 v.AddArg(z)
505 return true
506 }
507
508
509 for {
510 t := v.Type
511 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
512 break
513 }
514 z := v_0.Args[0]
515 if z.Op != ssaop.OpPPC64MULHDUCC {
516 break
517 }
518 v.Reset(ssaop.OpSelect1)
519 v.Type = t
520 v.AddArg(z)
521 return true
522 }
523
524
525 for {
526 t := v.Type
527 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
528 break
529 }
530 z := v_0.Args[0]
531 if z.Op != ssaop.OpPPC64ADDCCconst {
532 break
533 }
534 v.Reset(ssaop.OpSelect1)
535 v.Type = t
536 v.AddArg(z)
537 return true
538 }
539
540
541 for {
542 t := v.Type
543 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
544 break
545 }
546 z := v_0.Args[0]
547 if z.Op != ssaop.OpPPC64ANDCCconst {
548 break
549 }
550 v.Reset(ssaop.OpSelect1)
551 v.Type = t
552 v.AddArg(z)
553 return true
554 }
555
556
557 for {
558 t := v.Type
559 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
560 break
561 }
562 z := v_0.Args[0]
563 if z.Op != ssaop.OpPPC64NEGCC {
564 break
565 }
566 v.Reset(ssaop.OpSelect1)
567 v.Type = t
568 v.AddArg(z)
569 return true
570 }
571
572
573 for {
574 t := v.Type
575 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
576 break
577 }
578 z := v_0.Args[0]
579 if z.Op != ssaop.OpPPC64CNTLZDCC {
580 break
581 }
582 v.Reset(ssaop.OpSelect1)
583 v.Type = t
584 v.AddArg(z)
585 return true
586 }
587
588
589 for {
590 t := v.Type
591 if ssa.AuxIntToInt64(v.AuxInt) != 0 || v_0.Op != ssaop.OpSelect0 {
592 break
593 }
594 z := v_0.Args[0]
595 if z.Op != ssaop.OpPPC64RLDICLCC {
596 break
597 }
598 v.Reset(ssaop.OpSelect1)
599 v.Type = t
600 v.AddArg(z)
601 return true
602 }
603 return false
604 }
605 func rewriteValue_OpPPC64ISEL(v *ssa.Value) bool {
606 v_2 := v.Args[2]
607 v_1 := v.Args[1]
608 v_0 := v.Args[0]
609
610
611 for {
612 a := ssa.AuxIntToInt32(v.AuxInt)
613 x := v_0
614 if v_1.Op != ssaop.OpPPC64MOVDconst || ssa.AuxIntToInt64(v_1.AuxInt) != 0 {
615 break
616 }
617 z := v_2
618 v.Reset(ssaop.OpPPC64ISELZ)
619 v.AuxInt = ssa.Int32ToAuxInt(a)
620 v.AddArg2(x, z)
621 return true
622 }
623
624
625 for {
626 a := ssa.AuxIntToInt32(v.AuxInt)
627 if v_0.Op != ssaop.OpPPC64MOVDconst || ssa.AuxIntToInt64(v_0.AuxInt) != 0 {
628 break
629 }
630 y := v_1
631 z := v_2
632 v.Reset(ssaop.OpPPC64ISELZ)
633 v.AuxInt = ssa.Int32ToAuxInt(a ^ 0x4)
634 v.AddArg2(y, z)
635 return true
636 }
637 return false
638 }
639 func rewriteValue_OpPPC64RLDICL(v *ssa.Value) bool {
640 v_0 := v.Args[0]
641
642
643
644 for {
645 em := ssa.AuxIntToInt64(v.AuxInt)
646 x := v_0
647 if x.Op != ssaop.OpPPC64SRDconst {
648 break
649 }
650 s := ssa.AuxIntToInt64(x.AuxInt)
651 a := x.Args[0]
652 if !((em & 0xFF0000) == 0) {
653 break
654 }
655 v.Reset(ssaop.OpPPC64RLDICL)
656 v.AuxInt = ssa.Int64ToAuxInt(mergePPC64RLDICLandSRDconst(em, s))
657 v.AddArg(a)
658 return true
659 }
660 return false
661 }
662 func rewriteValue_OpPPC64RLDICLCC(v *ssa.Value) bool {
663 v_0 := v.Args[0]
664
665
666
667 for {
668 a := ssa.AuxIntToInt64(v.AuxInt)
669 x := v_0
670 if !(convertPPC64RldiclAndccconst(a) != 0) {
671 break
672 }
673 v.Reset(ssaop.OpPPC64ANDCCconst)
674 v.AuxInt = ssa.Int64ToAuxInt(convertPPC64RldiclAndccconst(a))
675 v.AddArg(x)
676 return true
677 }
678 return false
679 }
680 func rewriteValue_OpPPC64SETBC(v *ssa.Value) bool {
681 v_0 := v.Args[0]
682 b := v.Block
683 typ := &b.Func.Config.Types
684
685
686
687 for {
688 if ssa.AuxIntToInt32(v.AuxInt) != 2 {
689 break
690 }
691 cmp := v_0
692 if !(buildcfg.GOPPC64 <= 9) {
693 break
694 }
695 v.Reset(ssaop.OpPPC64ISELZ)
696 v.AuxInt = ssa.Int32ToAuxInt(2)
697 v0 := b.NewValue0(v.Pos, ssaop.OpPPC64MOVDconst, typ.Int64)
698 v0.AuxInt = ssa.Int64ToAuxInt(1)
699 v.AddArg2(v0, cmp)
700 return true
701 }
702
703
704
705 for {
706 if ssa.AuxIntToInt32(v.AuxInt) != 0 {
707 break
708 }
709 cmp := v_0
710 if !(buildcfg.GOPPC64 <= 9) {
711 break
712 }
713 v.Reset(ssaop.OpPPC64ISELZ)
714 v.AuxInt = ssa.Int32ToAuxInt(0)
715 v0 := b.NewValue0(v.Pos, ssaop.OpPPC64MOVDconst, typ.Int64)
716 v0.AuxInt = ssa.Int64ToAuxInt(1)
717 v.AddArg2(v0, cmp)
718 return true
719 }
720
721
722
723 for {
724 if ssa.AuxIntToInt32(v.AuxInt) != 1 {
725 break
726 }
727 cmp := v_0
728 if !(buildcfg.GOPPC64 <= 9) {
729 break
730 }
731 v.Reset(ssaop.OpPPC64ISELZ)
732 v.AuxInt = ssa.Int32ToAuxInt(1)
733 v0 := b.NewValue0(v.Pos, ssaop.OpPPC64MOVDconst, typ.Int64)
734 v0.AuxInt = ssa.Int64ToAuxInt(1)
735 v.AddArg2(v0, cmp)
736 return true
737 }
738 return false
739 }
740 func rewriteValue_OpPPC64SETBCR(v *ssa.Value) bool {
741 v_0 := v.Args[0]
742 b := v.Block
743 typ := &b.Func.Config.Types
744
745
746
747 for {
748 if ssa.AuxIntToInt32(v.AuxInt) != 2 {
749 break
750 }
751 cmp := v_0
752 if !(buildcfg.GOPPC64 <= 9) {
753 break
754 }
755 v.Reset(ssaop.OpPPC64ISELZ)
756 v.AuxInt = ssa.Int32ToAuxInt(6)
757 v0 := b.NewValue0(v.Pos, ssaop.OpPPC64MOVDconst, typ.Int64)
758 v0.AuxInt = ssa.Int64ToAuxInt(1)
759 v.AddArg2(v0, cmp)
760 return true
761 }
762
763
764
765 for {
766 if ssa.AuxIntToInt32(v.AuxInt) != 0 {
767 break
768 }
769 cmp := v_0
770 if !(buildcfg.GOPPC64 <= 9) {
771 break
772 }
773 v.Reset(ssaop.OpPPC64ISELZ)
774 v.AuxInt = ssa.Int32ToAuxInt(4)
775 v0 := b.NewValue0(v.Pos, ssaop.OpPPC64MOVDconst, typ.Int64)
776 v0.AuxInt = ssa.Int64ToAuxInt(1)
777 v.AddArg2(v0, cmp)
778 return true
779 }
780
781
782
783 for {
784 if ssa.AuxIntToInt32(v.AuxInt) != 1 {
785 break
786 }
787 cmp := v_0
788 if !(buildcfg.GOPPC64 <= 9) {
789 break
790 }
791 v.Reset(ssaop.OpPPC64ISELZ)
792 v.AuxInt = ssa.Int32ToAuxInt(5)
793 v0 := b.NewValue0(v.Pos, ssaop.OpPPC64MOVDconst, typ.Int64)
794 v0.AuxInt = ssa.Int64ToAuxInt(1)
795 v.AddArg2(v0, cmp)
796 return true
797 }
798 return false
799 }
800 func RewriteBlock(b *ssa.Block) bool {
801 return false
802 }
803
View as plain text