1 ! This test checks lowering of OpenMP DO Directive(Worksharing) for different
2 ! types of loop iteration variable, lower bound, upper bound, and step.
5 !RUN: bbc -fopenmp -emit-hlfir %s -o - 2>&1 | FileCheck %s
7 !CHECK: OpenMP loop iteration variable cannot have more than 64 bits size and will be narrowed into 64 bits.
9 program wsloop_variable
10 integer(kind
=1) :: i1_lb
, i1_ub
11 integer(kind
=2) :: i2
, i2_ub
, i2_s
12 integer(kind
=4) :: i4_s
13 integer(kind
=8) :: i8
, i8_s
14 integer(kind
=16) :: i16
, i16_lb
17 !CHECK: %[[TMP0:.*]] = arith.constant 1 : i32
18 !CHECK: %[[TMP1:.*]] = arith.constant 100 : i32
19 !CHECK: %[[TMP2:.*]] = fir.convert %[[TMP0]] : (i32) -> i64
20 !CHECK: %[[TMP3:.*]] = fir.convert %{{.*}} : (i8) -> i64
21 !CHECK: %[[TMP4:.*]] = fir.convert %{{.*}} : (i16) -> i64
22 !CHECK: %[[TMP5:.*]] = fir.convert %{{.*}} : (i128) -> i64
23 !CHECK: %[[TMP6:.*]] = fir.convert %[[TMP1]] : (i32) -> i64
24 !CHECK: %[[TMP7:.*]] = fir.convert %{{.*}} : (i32) -> i64
26 !CHECK-NEXT: omp.loop_nest (%[[ARG0:.*]], %[[ARG1:.*]]) : i64 = (%[[TMP2]], %[[TMP5]]) to (%[[TMP3]], %[[TMP6]]) inclusive step (%[[TMP4]], %[[TMP7]]) {
27 !CHECK: %[[ARG0_I16:.*]] = fir.convert %[[ARG0]] : (i64) -> i16
28 !CHECK: fir.store %[[ARG0_I16]] to %[[STORE_IV0:.*]]#1 : !fir.ref<i16>
29 !CHECK: fir.store %[[ARG1]] to %[[STORE_IV1:.*]]#1 : !fir.ref<i64>
30 !CHECK: %[[LOAD_IV0:.*]] = fir.load %[[STORE_IV0]]#0 : !fir.ref<i16>
31 !CHECK: %[[LOAD_IV0_I64:.*]] = fir.convert %[[LOAD_IV0]] : (i16) -> i64
32 !CHECK: %[[LOAD_IV1:.*]] = fir.load %[[STORE_IV1]]#0 : !fir.ref<i64>
33 !CHECK: %[[TMP10:.*]] = arith.addi %[[LOAD_IV0_I64]], %[[LOAD_IV1]] : i64
34 !CHECK: %[[TMP11:.*]] = fir.convert %[[TMP10]] : (i64) -> f32
35 !CHECK: hlfir.assign %[[TMP11]] to %{{.*}} : f32, !fir.ref<f32>
41 do i2
= 1, i1_ub
, i2_s
42 do i8
= i16_lb
, 100, i4_s
48 !CHECK: %[[TMP12:.*]] = arith.constant 1 : i32
49 !CHECK: %[[TMP13:.*]] = fir.convert %{{.*}} : (i8) -> i32
50 !CHECK: %[[TMP14:.*]] = fir.convert %{{.*}} : (i64) -> i32
52 !CHECK-NEXT: omp.loop_nest (%[[ARG0:.*]]) : i32 = (%[[TMP12]]) to (%[[TMP13]]) inclusive step (%[[TMP14]]) {
53 !CHECK: %[[ARG0_I16:.*]] = fir.convert %[[ARG0]] : (i32) -> i16
54 !CHECK: fir.store %[[ARG0_I16]] to %[[STORE3:.*]]#1 : !fir.ref<i16>
55 !CHECK: %[[LOAD3:.*]] = fir.load %[[STORE3]]#0 : !fir.ref<i16>
56 !CHECK: %[[TMP16:.*]] = fir.convert %[[LOAD3]] : (i16) -> f32
57 !CHECK: hlfir.assign %[[TMP16]] to %{{.*}} : f32, !fir.ref<f32>
63 do i2
= 1, i1_ub
, i8_s
68 !CHECK: %[[TMP17:.*]] = fir.convert %{{.*}} : (i8) -> i64
69 !CHECK: %[[TMP18:.*]] = fir.convert %{{.*}} : (i16) -> i64
70 !CHECK: %[[TMP19:.*]] = fir.convert %{{.*}} : (i32) -> i64
72 !CHECK-NEXT: omp.loop_nest (%[[ARG1:.*]]) : i64 = (%[[TMP17]]) to (%[[TMP18]]) inclusive step (%[[TMP19]]) {
73 !CHECK: %[[ARG1_I128:.*]] = fir.convert %[[ARG1]] : (i64) -> i128
74 !CHECK: fir.store %[[ARG1_I128]] to %[[STORE4:.*]]#1 : !fir.ref<i128>
75 !CHECK: %[[LOAD4:.*]] = fir.load %[[STORE4]]#0 : !fir.ref<i128>
76 !CHECK: %[[TMP21:.*]] = fir.convert %[[LOAD4]] : (i128) -> f32
77 !CHECK: hlfir.assign %[[TMP21]] to %{{.*}} : f32, !fir.ref<f32>
83 do i16
= i1_lb
, i2_ub
, i4_s
88 end program wsloop_variable
90 !CHECK-LABEL: func.func @_QPwsloop_variable_sub() {
91 !CHECK: %[[VAL_4:.*]] = fir.alloca i8 {bindc_name = "i1", uniq_name = "_QFwsloop_variable_subEi1"}
92 !CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_4]] {uniq_name = "_QFwsloop_variable_subEi1"} : (!fir.ref<i8>) -> (!fir.ref<i8>, !fir.ref<i8>)
94 !CHECK: %[[VAL_6:.*]] = fir.alloca i128 {bindc_name = "i16_lb", uniq_name = "_QFwsloop_variable_subEi16_lb"}
95 !CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]] {uniq_name = "_QFwsloop_variable_subEi16_lb"} : (!fir.ref<i128>) -> (!fir.ref<i128>, !fir.ref<i128>)
97 !CHECK: %[[VAL_8:.*]] = fir.alloca i8 {bindc_name = "i1_ub", uniq_name = "_QFwsloop_variable_subEi1_ub"}
98 !CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_8]] {uniq_name = "_QFwsloop_variable_subEi1_ub"} : (!fir.ref<i8>) -> (!fir.ref<i8>, !fir.ref<i8>)
100 !CHECK: %[[VAL_10:.*]] = fir.alloca i16 {bindc_name = "i2", uniq_name = "_QFwsloop_variable_subEi2"}
101 !CHECK: %[[VAL_11:.*]]:2 = hlfir.declare %[[VAL_10]] {uniq_name = "_QFwsloop_variable_subEi2"} : (!fir.ref<i16>) -> (!fir.ref<i16>, !fir.ref<i16>)
103 !CHECK: %[[VAL_12:.*]] = fir.alloca i16 {bindc_name = "i2_s", uniq_name = "_QFwsloop_variable_subEi2_s"}
104 !CHECK: %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_12]] {uniq_name = "_QFwsloop_variable_subEi2_s"} : (!fir.ref<i16>) -> (!fir.ref<i16>, !fir.ref<i16>)
106 !CHECK: %[[VAL_14:.*]] = fir.alloca i32 {bindc_name = "i4_s", uniq_name = "_QFwsloop_variable_subEi4_s"}
107 !CHECK: %[[VAL_15:.*]]:2 = hlfir.declare %[[VAL_14]] {uniq_name = "_QFwsloop_variable_subEi4_s"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
109 !CHECK: %[[VAL_16:.*]] = fir.alloca i64 {bindc_name = "i8", uniq_name = "_QFwsloop_variable_subEi8"}
110 !CHECK: %[[VAL_17:.*]]:2 = hlfir.declare %[[VAL_16]] {uniq_name = "_QFwsloop_variable_subEi8"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
112 !CHECK: %[[VAL_18:.*]] = fir.alloca i8 {bindc_name = "j1", uniq_name = "_QFwsloop_variable_subEj1"}
113 !CHECK: %[[VAL_19:.*]]:2 = hlfir.declare %[[VAL_18]] {uniq_name = "_QFwsloop_variable_subEj1"} : (!fir.ref<i8>) -> (!fir.ref<i8>, !fir.ref<i8>)
115 !CHECK: %[[VAL_20:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFwsloop_variable_subEx"}
116 !CHECK: %[[VAL_21:.*]]:2 = hlfir.declare %[[VAL_20]] {uniq_name = "_QFwsloop_variable_subEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
118 subroutine wsloop_variable_sub
119 integer(kind
=1) :: i1
, i1_ub
, j1
120 integer(kind
=2) :: i2
, i2_s
121 integer(kind
=4) :: i4_s
122 integer(kind
=8) :: i8
123 integer(kind
=16) :: i16_lb
126 !CHECK: %[[VAL_2:.*]] = fir.alloca i16 {bindc_name = "i2", pinned, {{.*}}}
127 !CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QFwsloop_variable_subEi2"} : (!fir.ref<i16>) -> (!fir.ref<i16>, !fir.ref<i16>)
129 !CHECK: %[[VAL_22:.*]] = arith.constant 1 : i32
130 !CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<i8>
131 !CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_13]]#0 : !fir.ref<i16>
132 !CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_23]] : (i8) -> i32
133 !CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_24]] : (i16) -> i32
135 !CHECK-NEXT: omp.loop_nest (%[[VAL_27:.*]]) : i32 = (%[[VAL_22]]) to (%[[VAL_25]]) inclusive step (%[[VAL_26]]) {
136 !CHECK: %[[VAL_28:.*]] = fir.convert %[[VAL_27]] : (i32) -> i16
137 !CHECK: fir.store %[[VAL_28]] to %[[VAL_3]]#1 : !fir.ref<i16>
138 !CHECK: %[[VAL_29:.*]] = fir.load %[[VAL_7]]#0 : !fir.ref<i128>
139 !CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i128) -> index
140 !CHECK: %[[VAL_31:.*]] = arith.constant 100 : i32
141 !CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_31]] : (i32) -> index
142 !CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_15]]#0 : !fir.ref<i32>
143 !CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_33]] : (i32) -> index
144 !CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_30]] : (index) -> i64
145 !CHECK: %[[VAL_36:.*]]:2 = fir.do_loop %[[VAL_37:.*]] = %[[VAL_30]] to %[[VAL_32]] step %[[VAL_34]] iter_args(%[[VAL_38:.*]] = %[[VAL_35]]) -> (index, i64) {
146 !CHECK: fir.store %[[VAL_38]] to %[[VAL_17]]#1 : !fir.ref<i64>
147 !CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i16>
148 !CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_39]] : (i16) -> i64
149 !CHECK: %[[VAL_41:.*]] = fir.load %[[VAL_17]]#0 : !fir.ref<i64>
150 !CHECK: %[[VAL_42:.*]] = arith.addi %[[VAL_40]], %[[VAL_41]] : i64
151 !CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_42]] : (i64) -> f32
152 !CHECK: hlfir.assign %[[VAL_43]] to %[[VAL_21]]#0 : f32, !fir.ref<f32>
153 !CHECK: %[[VAL_44:.*]] = arith.addi %[[VAL_37]], %[[VAL_34]] overflow<nsw> : index
154 !CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_34]] : (index) -> i64
155 !CHECK: %[[VAL_46:.*]] = fir.load %[[VAL_17]]#1 : !fir.ref<i64>
156 !CHECK: %[[VAL_47:.*]] = arith.addi %[[VAL_46]], %[[VAL_45]] overflow<nsw> : i64
157 !CHECK: fir.result %[[VAL_44]], %[[VAL_47]] : index, i64
159 !CHECK: fir.store %[[VAL_48:.*]]#1 to %[[VAL_17]]#1 : !fir.ref<i64>
165 do i2
= 1, i1_ub
, i2_s
166 do i8
= i16_lb
, 100, i4_s
172 !CHECK: %[[VAL_49:.*]] = arith.constant 5 : i8
173 !CHECK: hlfir.assign %[[VAL_49]] to %[[VAL_19]]#0 : i8, !fir.ref<i8>
175 !CHECK: %[[VAL_0:.*]] = fir.alloca i8 {bindc_name = "i1", pinned, {{.*}}}
176 !CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFwsloop_variable_subEi1"} : (!fir.ref<i8>) -> (!fir.ref<i8>, !fir.ref<i8>)
178 !CHECK: %[[VAL_50:.*]] = arith.constant 1 : i32
179 !CHECK: %[[VAL_51:.*]] = arith.constant 10 : i32
180 !CHECK: %[[VAL_52:.*]] = arith.constant 1 : i32
182 !CHECK-NEXT: omp.loop_nest (%[[VAL_53:.*]]) : i32 = (%[[VAL_50]]) to (%[[VAL_51]]) inclusive step (%[[VAL_52]]) {
183 !CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (i32) -> i8
184 !CHECK: fir.store %[[VAL_54]] to %[[VAL_1]]#1 : !fir.ref<i8>
185 !CHECK: %[[VAL_55:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i8>
186 !CHECK: %[[VAL_56:.*]] = fir.load %[[VAL_19]]#0 : !fir.ref<i8>
187 !CHECK: %[[VAL_57:.*]] = arith.cmpi eq, %[[VAL_55]], %[[VAL_56]] : i8
188 !CHECK: fir.if %[[VAL_57]] {