Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / computed-goto.f90
blobb9dddd37900c9d4075e78444e00aec4a1b598ec2
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
3 ! CHECK-LABEL: func @_QPm
4 function m(index)
5 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {bindc_name = "m"
6 ! CHECK: %[[V_1:[0-9]+]] = fir.load %arg0 : !fir.ref<i32>
7 ! CHECK: fir.select %[[V_1]] : i32 [1, ^bb6, 2, ^bb5, 3, ^bb4, 4, ^bb3, 5, ^bb2, unit, ^bb1]
8 ! CHECK: ^bb1: // pred: ^bb0
9 ! CHECK: fir.store %c0{{.*}} to %[[V_0]] : !fir.ref<i32>
10 ! CHECK: cf.br ^bb7
11 ! CHECK: ^bb2: // pred: ^bb0
12 ! CHECK: fir.store %c1{{.*}} to %[[V_0]] : !fir.ref<i32>
13 ! CHECK: cf.br ^bb7
14 ! CHECK: ^bb3: // pred: ^bb0
15 ! CHECK: fir.store %c3{{.*}} to %[[V_0]] : !fir.ref<i32>
16 ! CHECK: cf.br ^bb7
17 ! CHECK: ^bb4: // pred: ^bb0
18 ! CHECK: fir.store %c5{{.*}} to %[[V_0]] : !fir.ref<i32>
19 ! CHECK: cf.br ^bb7
20 ! CHECK: ^bb5: // pred: ^bb0
21 ! CHECK: fir.store %c7{{.*}} to %[[V_0]] : !fir.ref<i32>
22 ! CHECK: cf.br ^bb7
23 ! CHECK: ^bb6: // pred: ^bb0
24 ! CHECK: fir.store %c9{{.*}} to %[[V_0]] : !fir.ref<i32>
25 ! CHECK: cf.br ^bb7
26 ! CHECK: ^bb7: // 6 preds: ^bb1, ^bb2, ^bb3, ^bb4, ^bb5, ^bb6
27 ! CHECK: %[[V_2:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
28 ! CHECK: return %[[V_2]] : i32
29 goto (9,7,5,3,1) index ! + 1
30 m = 0; return
31 1 m = 1; return
32 3 m = 3; return
33 5 m = 5; return
34 7 m = 7; return
35 9 m = 9; return
36 end
38 ! CHECK-LABEL: func @_QPm1
39 function m1(index)
40 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {bindc_name = "m1"
41 ! CHECK: %[[V_1:[0-9]+]] = fir.call @llvm.stacksave()
42 ! CHECK: %[[V_2:[0-9]+]] = fir.load %arg0 : !fir.ref<i32>
43 ! CHECK: %[[V_3:[0-9]+]] = arith.cmpi eq, %[[V_2]], %c1{{.*}} : i32
44 ! CHECK: cf.cond_br %[[V_3]], ^bb1, ^bb2
45 ! CHECK: ^bb1: // pred: ^bb0
46 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
47 ! CHECK: cf.br ^bb3
48 ! CHECK: ^bb2: // pred: ^bb0
49 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
50 ! CHECK: fir.store %c0{{.*}} to %[[V_0]] : !fir.ref<i32>
51 ! CHECK: cf.br ^bb4
52 ! CHECK: ^bb3: // pred: ^bb1
53 ! CHECK: fir.store %c10{{.*}} to %[[V_0]] : !fir.ref<i32>
54 ! CHECK: cf.br ^bb4
55 ! CHECK: ^bb4: // 2 preds: ^bb2, ^bb3
56 ! CHECK: %[[V_4:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
57 ! CHECK: return %[[V_4]] : i32
58 block
59 goto (10) index
60 end block
61 m1 = 0; return
62 10 m1 = 10; return
63 end
65 ! CHECK-LABEL: func @_QPm2
66 function m2(index)
67 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {bindc_name = "m2"
68 ! CHECK: %[[V_1:[0-9]+]] = fir.call @llvm.stacksave()
69 ! CHECK: %[[V_2:[0-9]+]] = fir.load %arg0 : !fir.ref<i32>
70 ! CHECK: %[[V_3:[0-9]+]] = arith.cmpi eq, %[[V_2]], %c1{{.*}} : i32
71 ! CHECK: cf.cond_br %[[V_3]], ^bb1, ^bb2
72 ! CHECK: ^bb1: // pred: ^bb0
73 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
74 ! CHECK: cf.br ^bb5
75 ! CHECK: ^bb2: // pred: ^bb0
76 ! CHECK: %[[V_4:[0-9]+]] = arith.cmpi eq, %[[V_2]], %c2{{.*}} : i32
77 ! CHECK: cf.cond_br %[[V_4]], ^bb3, ^bb4
78 ! CHECK: ^bb3: // pred: ^bb2
79 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
80 ! CHECK: cf.br ^bb6
81 ! CHECK: ^bb4: // pred: ^bb2
82 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
83 ! CHECK: fir.store %c0{{.*}} to %[[V_0]] : !fir.ref<i32>
84 ! CHECK: cf.br ^bb7
85 ! CHECK: ^bb5: // pred: ^bb1
86 ! CHECK: fir.store %c10{{.*}} to %[[V_0]] : !fir.ref<i32>
87 ! CHECK: cf.br ^bb7
88 ! CHECK: ^bb6: // pred: ^bb3
89 ! CHECK: fir.store %c20{{.*}} to %[[V_0]] : !fir.ref<i32>
90 ! CHECK: cf.br ^bb7
91 ! CHECK: ^bb7: // 3 preds: ^bb4, ^bb5, ^bb6
92 ! CHECK: %[[V_5:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
93 ! CHECK: return %[[V_5]] : i32
94 block
95 goto (10,20) index
96 end block
97 m2 = 0; return
98 10 m2 = 10; return
99 20 m2 = 20; return
102 ! CHECK-LABEL: func @_QPm3
103 function m3(index)
104 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {bindc_name = "m3"
105 ! CHECK: %[[V_1:[0-9]+]] = fir.call @llvm.stacksave()
106 ! CHECK: %[[V_2:[0-9]+]] = fir.load %arg0 : !fir.ref<i32>
107 ! CHECK: %[[V_3:[0-9]+]] = arith.cmpi eq, %[[V_2]], %c1{{.*}} : i32
108 ! CHECK: cf.cond_br %[[V_3]], ^bb1, ^bb2
109 ! CHECK: ^bb1: // pred: ^bb0
110 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
111 ! CHECK: cf.br ^bb7
112 ! CHECK: ^bb2: // pred: ^bb0
113 ! CHECK: %[[V_4:[0-9]+]] = arith.cmpi eq, %[[V_2]], %c2{{.*}} : i32
114 ! CHECK: cf.cond_br %[[V_4]], ^bb3, ^bb4
115 ! CHECK: ^bb3: // pred: ^bb2
116 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
117 ! CHECK: cf.br ^bb8
118 ! CHECK: ^bb4: // pred: ^bb2
119 ! CHECK: %[[V_5:[0-9]+]] = arith.cmpi eq, %[[V_2]], %c3{{.*}} : i32
120 ! CHECK: cf.cond_br %[[V_5]], ^bb5, ^bb6
121 ! CHECK: ^bb5: // pred: ^bb4
122 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
123 ! CHECK: cf.br ^bb9
124 ! CHECK: ^bb6: // pred: ^bb4
125 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
126 ! CHECK: fir.store %c0{{.*}} to %[[V_0]] : !fir.ref<i32>
127 ! CHECK: cf.br ^bb10
128 ! CHECK: ^bb7: // pred: ^bb1
129 ! CHECK: fir.store %c10{{.*}} to %[[V_0]] : !fir.ref<i32>
130 ! CHECK: cf.br ^bb10
131 ! CHECK: ^bb8: // pred: ^bb3
132 ! CHECK: fir.store %c20{{.*}} to %[[V_0]] : !fir.ref<i32>
133 ! CHECK: cf.br ^bb10
134 ! CHECK: ^bb9: // pred: ^bb5
135 ! CHECK: fir.store %c30{{.*}} to %[[V_0]] : !fir.ref<i32>
136 ! CHECK: cf.br ^bb10
137 ! CHECK: ^bb10: // 4 preds: ^bb6, ^bb7, ^bb8, ^bb9
138 ! CHECK: %[[V_6:[0-9]+]] = fir.load %[[V_0]] : !fir.ref<i32>
139 ! CHECK: return %[[V_6]] : i32
140 block
141 goto (10,20,30) index
142 end block
143 m3 = 0; return
144 10 m3 = 10; return
145 20 m3 = 20; return
146 30 m3 = 30; return
149 program cg
150 print*, m(-3), m(1), m(2), m(3), m(4), m(5), m(9) ! 0 9 7 5 3 1 0
151 print*, m1(0), m1(1), m1(2) ! 0 10 0
152 print*, m2(0), m2(1), m2(2), m2(3) ! 0 10 20 0
153 print*, m3(0), m3(1), m3(2), m3(3), m3(4) ! 0 10 20 30 0