1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
3 ! CHECK-LABEL: func @_QPm
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>
11 ! CHECK: ^bb2: // pred: ^bb0
12 ! CHECK: fir.store %c1{{.*}} to %[[V_0]] : !fir.ref<i32>
14 ! CHECK: ^bb3: // pred: ^bb0
15 ! CHECK: fir.store %c3{{.*}} to %[[V_0]] : !fir.ref<i32>
17 ! CHECK: ^bb4: // pred: ^bb0
18 ! CHECK: fir.store %c5{{.*}} to %[[V_0]] : !fir.ref<i32>
20 ! CHECK: ^bb5: // pred: ^bb0
21 ! CHECK: fir.store %c7{{.*}} to %[[V_0]] : !fir.ref<i32>
23 ! CHECK: ^bb6: // pred: ^bb0
24 ! CHECK: fir.store %c9{{.*}} to %[[V_0]] : !fir.ref<i32>
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
38 ! CHECK-LABEL: func @_QPm1
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]])
48 ! CHECK: ^bb2: // pred: ^bb0
49 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
50 ! CHECK: fir.store %c0{{.*}} to %[[V_0]] : !fir.ref<i32>
52 ! CHECK: ^bb3: // pred: ^bb1
53 ! CHECK: fir.store %c10{{.*}} to %[[V_0]] : !fir.ref<i32>
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
65 ! CHECK-LABEL: func @_QPm2
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]])
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]])
81 ! CHECK: ^bb4: // pred: ^bb2
82 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
83 ! CHECK: fir.store %c0{{.*}} to %[[V_0]] : !fir.ref<i32>
85 ! CHECK: ^bb5: // pred: ^bb1
86 ! CHECK: fir.store %c10{{.*}} to %[[V_0]] : !fir.ref<i32>
88 ! CHECK: ^bb6: // pred: ^bb3
89 ! CHECK: fir.store %c20{{.*}} to %[[V_0]] : !fir.ref<i32>
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
102 ! CHECK-LABEL: func @_QPm3
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]])
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]])
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]])
124 ! CHECK: ^bb6: // pred: ^bb4
125 ! CHECK: fir.call @llvm.stackrestore(%[[V_1]])
126 ! CHECK: fir.store %c0{{.*}} to %[[V_0]] : !fir.ref<i32>
128 ! CHECK: ^bb7: // pred: ^bb1
129 ! CHECK: fir.store %c10{{.*}} to %[[V_0]] : !fir.ref<i32>
131 ! CHECK: ^bb8: // pred: ^bb3
132 ! CHECK: fir.store %c20{{.*}} to %[[V_0]] : !fir.ref<i32>
134 ! CHECK: ^bb9: // pred: ^bb5
135 ! CHECK: fir.store %c30{{.*}} to %[[V_0]] : !fir.ref<i32>
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
141 goto (10,20,30) index
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