Skip to content

Commit a567801

Browse files
committed
fix IR
1 parent 61c2a48 commit a567801

File tree

2 files changed

+286
-239
lines changed

2 files changed

+286
-239
lines changed

mypyc/test-data/irbuild-lists.test

Lines changed: 151 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -594,27 +594,31 @@ def test():
594594
r3 :: list
595595
r4 :: native_int
596596
r5 :: bit
597-
r6, x, r7 :: str
598-
r8 :: native_int
597+
r6 :: native_int
598+
r7 :: bit
599+
r8, x, r9 :: str
600+
r10 :: native_int
599601
a :: list
600602
L0:
601603
r0 = 'abc'
602604
source = r0
603605
r1 = CPyStr_Size_size_t(source)
604606
r2 = r1 >= 0 :: signed
605607
r3 = PyList_New(r1)
606-
r4 = 0
608+
r4 = CPyStr_Size_size_t(source)
609+
r5 = r4 >= 0 :: signed
610+
r6 = 0
607611
L1:
608-
r5 = r4 < r1 :: signed
609-
if r5 goto L2 else goto L4 :: bool
612+
r7 = r6 < r4 :: signed
613+
if r7 goto L2 else goto L4 :: bool
610614
L2:
611-
r6 = CPyStr_GetItemUnsafe(source, r4)
612-
x = r6
613-
r7 = f2(x)
614-
CPyList_SetItemUnsafe(r3, r4, r7)
615+
r8 = CPyStr_GetItemUnsafe(source, r6)
616+
x = r8
617+
r9 = f2(x)
618+
CPyList_SetItemUnsafe(r3, r6, r9)
615619
L3:
616-
r8 = r4 + 1
617-
r4 = r8
620+
r10 = r6 + 1
621+
r6 = r10
618622
goto L1
619623
L4:
620624
a = r3
@@ -635,30 +639,38 @@ L0:
635639
return r1
636640
def test():
637641
r0 :: str
638-
r1 :: list
639-
r2 :: native_int
640-
r3 :: bit
641-
r4, x, r5 :: str
642+
r1 :: native_int
643+
r2 :: bit
644+
r3 :: list
645+
r4 :: native_int
646+
r5 :: bit
642647
r6 :: native_int
648+
r7 :: bit
649+
r8, x, r9 :: str
650+
r10 :: native_int
643651
a :: list
644652
L0:
645653
r0 = 'abc'
646-
r1 = PyList_New(3)
647-
r2 = 0
654+
r1 = CPyStr_Size_size_t(r0)
655+
r2 = r1 >= 0 :: signed
656+
r3 = PyList_New(r1)
657+
r4 = CPyStr_Size_size_t(r0)
658+
r5 = r4 >= 0 :: signed
659+
r6 = 0
648660
L1:
649-
r3 = r2 < 3 :: signed
650-
if r3 goto L2 else goto L4 :: bool
661+
r7 = r6 < r4 :: signed
662+
if r7 goto L2 else goto L4 :: bool
651663
L2:
652-
r4 = CPyStr_GetItemUnsafe(r0, r2)
653-
x = r4
654-
r5 = f2(x)
655-
CPyList_SetItemUnsafe(r1, r2, r5)
664+
r8 = CPyStr_GetItemUnsafe(r0, r6)
665+
x = r8
666+
r9 = f2(x)
667+
CPyList_SetItemUnsafe(r3, r6, r9)
656668
L3:
657-
r6 = r2 + 1
658-
r2 = r6
669+
r10 = r6 + 1
670+
r6 = r10
659671
goto L1
660672
L4:
661-
a = r1
673+
a = r3
662674
return 1
663675

664676
[case testListBuiltFromFinalStr]
@@ -680,30 +692,38 @@ L0:
680692
return r1
681693
def test():
682694
r0 :: str
683-
r1 :: list
684-
r2 :: native_int
685-
r3 :: bit
686-
r4, x, r5 :: str
695+
r1 :: native_int
696+
r2 :: bit
697+
r3 :: list
698+
r4 :: native_int
699+
r5 :: bit
687700
r6 :: native_int
701+
r7 :: bit
702+
r8, x, r9 :: str
703+
r10 :: native_int
688704
a :: list
689705
L0:
690706
r0 = 'abc'
691-
r1 = PyList_New(3)
692-
r2 = 0
707+
r1 = CPyStr_Size_size_t(r0)
708+
r2 = r1 >= 0 :: signed
709+
r3 = PyList_New(r1)
710+
r4 = CPyStr_Size_size_t(r0)
711+
r5 = r4 >= 0 :: signed
712+
r6 = 0
693713
L1:
694-
r3 = r2 < 3 :: signed
695-
if r3 goto L2 else goto L4 :: bool
714+
r7 = r6 < r4 :: signed
715+
if r7 goto L2 else goto L4 :: bool
696716
L2:
697-
r4 = CPyStr_GetItemUnsafe(r0, r2)
698-
x = r4
699-
r5 = f2(x)
700-
CPyList_SetItemUnsafe(r1, r2, r5)
717+
r8 = CPyStr_GetItemUnsafe(r0, r6)
718+
x = r8
719+
r9 = f2(x)
720+
CPyList_SetItemUnsafe(r3, r6, r9)
701721
L3:
702-
r6 = r2 + 1
703-
r2 = r6
722+
r10 = r6 + 1
723+
r6 = r10
704724
goto L1
705725
L4:
706-
a = r1
726+
a = r3
707727
return 1
708728

709729
[case testListBuiltFromBytes_64bit]
@@ -724,47 +744,48 @@ def test():
724744
r0, source :: bytes
725745
r1 :: native_int
726746
r2 :: list
727-
r3 :: native_int
728-
r4, r5, r6 :: bit
729-
r7, r8, r9, r10 :: int
730-
r11 :: object
731-
r12, x, r13 :: int
732-
r14 :: object
733-
r15 :: native_int
747+
r3, r4 :: native_int
748+
r5, r6, r7 :: bit
749+
r8, r9, r10, r11 :: int
750+
r12 :: object
751+
r13, x, r14 :: int
752+
r15 :: object
753+
r16 :: native_int
734754
a :: list
735755
L0:
736756
r0 = b'abc'
737757
source = r0
738758
r1 = var_object_size source
739759
r2 = PyList_New(r1)
740-
r3 = 0
760+
r3 = var_object_size source
761+
r4 = 0
741762
L1:
742-
r4 = r3 < r1 :: signed
743-
if r4 goto L2 else goto L8 :: bool
763+
r5 = r4 < r3 :: signed
764+
if r5 goto L2 else goto L8 :: bool
744765
L2:
745-
r5 = r3 <= 4611686018427387903 :: signed
746-
if r5 goto L3 else goto L4 :: bool
766+
r6 = r4 <= 4611686018427387903 :: signed
767+
if r6 goto L3 else goto L4 :: bool
747768
L3:
748-
r6 = r3 >= -4611686018427387904 :: signed
749-
if r6 goto L5 else goto L4 :: bool
769+
r7 = r4 >= -4611686018427387904 :: signed
770+
if r7 goto L5 else goto L4 :: bool
750771
L4:
751-
r7 = CPyTagged_FromInt64(r3)
752-
r8 = r7
772+
r8 = CPyTagged_FromInt64(r4)
773+
r9 = r8
753774
goto L6
754775
L5:
755-
r9 = r3 << 1
756-
r8 = r9
776+
r10 = r4 << 1
777+
r9 = r10
757778
L6:
758-
r10 = CPyBytes_GetItem(source, r8)
759-
r11 = box(int, r10)
760-
r12 = unbox(int, r11)
761-
x = r12
762-
r13 = f2(x)
763-
r14 = box(int, r13)
764-
CPyList_SetItemUnsafe(r2, r3, r14)
779+
r11 = CPyBytes_GetItem(source, r9)
780+
r12 = box(int, r11)
781+
r13 = unbox(int, r12)
782+
x = r13
783+
r14 = f2(x)
784+
r15 = box(int, r14)
785+
CPyList_SetItemUnsafe(r2, r4, r15)
765786
L7:
766-
r15 = r3 + 1
767-
r3 = r15
787+
r16 = r4 + 1
788+
r4 = r16
768789
goto L1
769790
L8:
770791
a = r2
@@ -785,49 +806,52 @@ L0:
785806
return r0
786807
def test():
787808
r0 :: bytes
788-
r1 :: list
789-
r2 :: native_int
790-
r3, r4, r5 :: bit
791-
r6, r7, r8, r9 :: int
792-
r10 :: object
793-
r11, x, r12 :: int
794-
r13 :: object
795-
r14 :: native_int
809+
r1 :: native_int
810+
r2 :: list
811+
r3, r4 :: native_int
812+
r5, r6, r7 :: bit
813+
r8, r9, r10, r11 :: int
814+
r12 :: object
815+
r13, x, r14 :: int
816+
r15 :: object
817+
r16 :: native_int
796818
a :: list
797819
L0:
798820
r0 = b'abc'
799-
r1 = PyList_New(3)
800-
r2 = 0
821+
r1 = var_object_size r0
822+
r2 = PyList_New(r1)
823+
r3 = var_object_size r0
824+
r4 = 0
801825
L1:
802-
r3 = r2 < 3 :: signed
803-
if r3 goto L2 else goto L8 :: bool
826+
r5 = r4 < r3 :: signed
827+
if r5 goto L2 else goto L8 :: bool
804828
L2:
805-
r4 = r2 <= 4611686018427387903 :: signed
806-
if r4 goto L3 else goto L4 :: bool
829+
r6 = r4 <= 4611686018427387903 :: signed
830+
if r6 goto L3 else goto L4 :: bool
807831
L3:
808-
r5 = r2 >= -4611686018427387904 :: signed
809-
if r5 goto L5 else goto L4 :: bool
832+
r7 = r4 >= -4611686018427387904 :: signed
833+
if r7 goto L5 else goto L4 :: bool
810834
L4:
811-
r6 = CPyTagged_FromInt64(r2)
812-
r7 = r6
835+
r8 = CPyTagged_FromInt64(r4)
836+
r9 = r8
813837
goto L6
814838
L5:
815-
r8 = r2 << 1
816-
r7 = r8
839+
r10 = r4 << 1
840+
r9 = r10
817841
L6:
818-
r9 = CPyBytes_GetItem(r0, r7)
819-
r10 = box(int, r9)
820-
r11 = unbox(int, r10)
821-
x = r11
822-
r12 = f2(x)
823-
r13 = box(int, r12)
824-
CPyList_SetItemUnsafe(r1, r2, r13)
842+
r11 = CPyBytes_GetItem(r0, r9)
843+
r12 = box(int, r11)
844+
r13 = unbox(int, r12)
845+
x = r13
846+
r14 = f2(x)
847+
r15 = box(int, r14)
848+
CPyList_SetItemUnsafe(r2, r4, r15)
825849
L7:
826-
r14 = r2 + 1
827-
r2 = r14
850+
r16 = r4 + 1
851+
r4 = r16
828852
goto L1
829853
L8:
830-
a = r1
854+
a = r2
831855
return 1
832856

833857
[case testListBuiltFromFinalBytes_64bit]
@@ -852,13 +876,13 @@ def test():
852876
r1 :: bool
853877
r2 :: native_int
854878
r3 :: list
855-
r4 :: native_int
856-
r5, r6, r7 :: bit
857-
r8, r9, r10, r11 :: int
858-
r12 :: object
859-
r13, x, r14 :: int
860-
r15 :: object
861-
r16 :: native_int
879+
r4, r5 :: native_int
880+
r6, r7, r8 :: bit
881+
r9, r10, r11, r12 :: int
882+
r13 :: object
883+
r14, x, r15 :: int
884+
r16 :: object
885+
r17 :: native_int
862886
a :: list
863887
L0:
864888
r0 = __main__.source :: static
@@ -869,35 +893,37 @@ L1:
869893
L2:
870894
r2 = var_object_size r0
871895
r3 = PyList_New(r2)
872-
r4 = 0
896+
r4 = var_object_size r0
897+
r5 = 0
873898
L3:
874-
r5 = r4 < r2 :: signed
875-
if r5 goto L4 else goto L10 :: bool
899+
r6 = r5 < r4 :: signed
900+
if r6 goto L4 else goto L10 :: bool
876901
L4:
877-
r6 = r4 <= 4611686018427387903 :: signed
878-
if r6 goto L5 else goto L6 :: bool
902+
r7 = r5 <= 4611686018427387903 :: signed
903+
if r7 goto L5 else goto L6 :: bool
879904
L5:
880-
r7 = r4 >= -4611686018427387904 :: signed
881-
if r7 goto L7 else goto L6 :: bool
905+
r8 = r5 >= -4611686018427387904 :: signed
906+
if r8 goto L7 else goto L6 :: bool
882907
L6:
883-
r8 = CPyTagged_FromInt64(r4)
884-
r9 = r8
908+
r9 = CPyTagged_FromInt64(r5)
909+
r10 = r9
885910
goto L8
886911
L7:
887-
r10 = r4 << 1
888-
r9 = r10
912+
r11 = r5 << 1
913+
r10 = r11
889914
L8:
890-
r11 = CPyBytes_GetItem(r0, r9)
891-
r12 = box(int, r11)
892-
r13 = unbox(int, r12)
893-
x = r13
894-
r14 = f2(x)
895-
r15 = box(int, r14)
896-
CPyList_SetItemUnsafe(r3, r4, r15)
915+
r12 = CPyBytes_GetItem(r0, r10)
916+
r13 = box(int, r12)
917+
r14 = unbox(int, r13)
918+
x = r14
919+
r15 = f2(x)
920+
r16 = box(int, r15)
921+
CPyList_SetItemUnsafe(r3, r5, r16)
897922
L9:
898-
r16 = r4 + 1
899-
r4 = r16
923+
r17 = r5 + 1
924+
r5 = r17
900925
goto L3
901926
L10:
902927
a = r3
903928
return 1
929+

0 commit comments

Comments
 (0)