[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt...
[llvm-project.git] / flang / test / Lower / loops.f90
blob12385cbb4c186fe8ea87acd55a0517ee0adfc67b
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
3 ! CHECK-LABEL: loop_test
4 subroutine loop_test
5 ! CHECK: %[[VAL_2:.*]] = fir.alloca i16 {bindc_name = "i"}
6 ! CHECK: %[[VAL_3:.*]] = fir.alloca i16 {bindc_name = "i"}
7 ! CHECK: %[[VAL_4:.*]] = fir.alloca i16 {bindc_name = "i"}
8 ! CHECK: %[[VAL_5:.*]] = fir.alloca i8 {bindc_name = "k"}
9 ! CHECK: %[[VAL_6:.*]] = fir.alloca i8 {bindc_name = "j"}
10 ! CHECK: %[[VAL_7:.*]] = fir.alloca i8 {bindc_name = "i"}
11 ! CHECK: %[[VAL_8:.*]] = fir.alloca i32 {bindc_name = "k"}
12 ! CHECK: %[[VAL_9:.*]] = fir.alloca i32 {bindc_name = "j"}
13 ! CHECK: %[[VAL_10:.*]] = fir.alloca i32 {bindc_name = "i"}
14 ! CHECK: %[[VAL_11:.*]] = fir.alloca !fir.array<5x5x5xi32> {bindc_name = "a", uniq_name = "_QFloop_testEa"}
15 ! CHECK: %[[VAL_12:.*]] = fir.alloca i32 {bindc_name = "asum", uniq_name = "_QFloop_testEasum"}
16 ! CHECK: %[[VAL_13:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFloop_testEi"}
17 ! CHECK: %[[VAL_14:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFloop_testEj"}
18 ! CHECK: %[[VAL_15:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFloop_testEk"}
19 ! CHECK: %[[VAL_16:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFloop_testEx"}
20 ! CHECK: %[[VAL_17:.*]] = fir.alloca i32 {bindc_name = "xsum", uniq_name = "_QFloop_testExsum"}
22 integer(4) :: a(5,5,5), i, j, k, asum, xsum
24 i = 100
25 j = 200
26 k = 300
28 ! CHECK-COUNT-3: fir.do_loop {{.*}} unordered
29 do concurrent (i=1:5, j=1:5, k=1:5) ! shared(a)
30 ! CHECK: fir.coordinate_of
31 a(i,j,k) = 0
32 enddo
33 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
34 print*, 'A:', i, j, k
36 ! CHECK-COUNT-3: fir.do_loop {{.*}} unordered
37 ! CHECK: fir.if
38 do concurrent (integer(1)::i=1:5, j=1:5, k=1:5, i.ne.j .and. k.ne.3) shared(a)
39 ! CHECK-COUNT-2: fir.coordinate_of
40 a(i,j,k) = a(i,j,k) + 1
41 enddo
43 ! CHECK-COUNT-3: fir.do_loop {{[^un]*}} -> (index, i32)
44 asum = 0
45 do i=1,5
46 do j=1,5
47 do k=1,5
48 ! CHECK: fir.coordinate_of
49 asum = asum + a(i,j,k)
50 enddo
51 enddo
52 enddo
53 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
54 print*, 'B:', i, j, k, '-', asum
56 ! CHECK: fir.do_loop {{.*}} unordered
57 ! CHECK-COUNT-2: fir.if
58 do concurrent (integer(2)::i=1:5, i.ne.3)
59 if (i.eq.2 .or. i.eq.4) goto 5 ! fir.if
60 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
61 print*, 'C:', i
62 5 continue
63 enddo
65 ! CHECK: fir.do_loop {{.*}} unordered
66 ! CHECK-COUNT-2: fir.if
67 do concurrent (integer(2)::i=1:5, i.ne.3)
68 if (i.eq.2 .or. i.eq.4) then ! fir.if
69 goto 6
70 endif
71 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
72 print*, 'D:', i
73 6 continue
74 enddo
76 ! CHECK-NOT: fir.do_loop
77 ! CHECK-NOT: fir.if
78 do concurrent (integer(2)::i=1:5, i.ne.3)
79 goto (7, 7) i+1
80 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
81 print*, 'E:', i
82 7 continue
83 enddo
85 xsum = 0.0
86 ! CHECK-NOT: fir.do_loop
87 do x = 1.5, 3.5, 0.3
88 xsum = xsum + 1
89 enddo
90 ! CHECK: fir.call @_FortranAioBeginExternalFormattedOutput
91 print '(" F:",X,F3.1,A,I2)', x, ' -', xsum
92 end subroutine loop_test
94 ! CHECK-LABEL: c.func @_QPlis
95 subroutine lis(n)
96 ! CHECK-DAG: fir.alloca i32 {bindc_name = "m"}
97 ! CHECK-DAG: fir.alloca i32 {bindc_name = "j"}
98 ! CHECK-DAG: fir.alloca i32 {bindc_name = "i"}
99 ! CHECK-DAG: fir.alloca i8 {bindc_name = "i"}
100 ! CHECK-DAG: fir.alloca i32 {bindc_name = "j", uniq_name = "_QFlisEj"}
101 ! CHECK-DAG: fir.alloca i32 {bindc_name = "k", uniq_name = "_QFlisEk"}
102 ! CHECK-DAG: fir.alloca !fir.box<!fir.ptr<!fir.array<?x?x?xi32>>> {bindc_name = "p", uniq_name = "_QFlisEp"}
103 ! CHECK-DAG: fir.alloca !fir.array<?x?x?xi32>, %{{.*}}, %{{.*}}, %{{.*}} {bindc_name = "a", fir.target, uniq_name = "_QFlisEa"}
104 ! CHECK-DAG: fir.alloca !fir.array<?x?xi32>, %{{.*}}, %{{.*}} {bindc_name = "r", uniq_name = "_QFlisEr"}
105 ! CHECK-DAG: fir.alloca !fir.array<?x?xi32>, %{{.*}}, %{{.*}} {bindc_name = "s", uniq_name = "_QFlisEs"}
106 ! CHECK-DAG: fir.alloca !fir.array<?x?xi32>, %{{.*}}, %{{.*}} {bindc_name = "t", uniq_name = "_QFlisEt"}
107 integer, target :: a(n,n,n) ! operand via p
108 integer :: r(n,n) ! result, unspecified locality
109 integer :: s(n,n) ! shared locality
110 integer :: t(n,n) ! local locality
111 integer, pointer :: p(:,:,:) ! local_init locality
113 p => a
114 ! CHECK: fir.do_loop %arg1 = %c0{{.*}} to %{{.*}} step %c1{{.*}} unordered iter_args(%arg2 = %{{.*}}) -> (!fir.array<?x?xi32>) {
115 ! CHECK: fir.do_loop %arg3 = %c0{{.*}} to %{{.*}} step %c1{{.*}} unordered iter_args(%arg4 = %arg2) -> (!fir.array<?x?xi32>) {
116 ! CHECK: }
117 ! CHECK: }
118 r = 0
120 ! CHECK: fir.do_loop %arg1 = %{{.*}} to %{{.*}} step %{{.*}} unordered {
121 ! CHECK: fir.do_loop %arg2 = %{{.*}} to %{{.*}} step %c1{{.*}} iter_args(%arg3 = %{{.*}}) -> (index, i32) {
122 ! CHECK: }
123 ! CHECK: }
124 do concurrent (integer(kind=1)::i=n:1:-1)
125 do j = 1,n
126 a(i,j,:) = 2*(i+j)
127 s(i,j) = -i-j
128 enddo
129 enddo
131 ! CHECK: fir.do_loop %arg1 = %{{.*}} to %{{.*}} step %c1{{.*}} unordered {
132 ! CHECK: fir.do_loop %arg2 = %{{.*}} to %{{.*}} step %c1{{.*}} unordered {
133 ! CHECK: fir.if %{{.*}} {
134 ! CHECK: %[[V_95:[0-9]+]] = fir.alloca !fir.array<?x?xi32>, %{{.*}}, %{{.*}} {bindc_name = "t", pinned, uniq_name = "_QFlisEt"}
135 ! CHECK: %[[V_96:[0-9]+]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?x?xi32>>> {bindc_name = "p", pinned, uniq_name = "_QFlisEp"}
136 ! CHECK: fir.store %{{.*}} to %[[V_96]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x?xi32>>>>
137 ! CHECK: fir.do_loop %arg3 = %{{.*}} to %{{.*}} step %c1{{.*}} iter_args(%arg4 = %{{.*}}) -> (index, i32) {
138 ! CHECK: fir.do_loop %arg5 = %{{.*}} to %{{.*}} step %c1{{.*}} unordered {
139 ! CHECK: fir.load %[[V_96]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x?xi32>>>>
140 ! CHECK: fir.convert %[[V_95]] : (!fir.ref<!fir.array<?x?xi32>>) -> !fir.ref<!fir.array<?xi32>>
141 ! CHECK: }
142 ! CHECK: }
143 ! CHECK: fir.convert %[[V_95]] : (!fir.ref<!fir.array<?x?xi32>>) -> !fir.ref<!fir.array<?xi32>>
144 ! CHECK: }
145 ! CHECK: }
146 ! CHECK: }
147 do concurrent (i=1:n,j=1:n,i.ne.j) local(t) local_init(p) shared(s)
148 do k=1,n
149 do concurrent (m=1:n)
150 t(k,m) = p(k,m,k)
151 enddo
152 enddo
153 r(i,j) = t(i,j) + s(i,j)
154 enddo
156 print*, sum(r) ! n=6 -> 210
159 ! CHECK-LABEL: print_nothing
160 subroutine print_nothing(k1, k2)
161 if (k1 > 0) then
162 ! CHECK: br [[header:\^bb[0-9]+]]
163 ! CHECK: [[header]]
164 do while (k1 > k2)
165 print*, k1, k2 ! no output
166 k2 = k2 + 1
167 ! CHECK: br [[header]]
168 end do
169 end if
172 call loop_test
173 call lis(6)
174 call print_nothing(2, 2)