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-fir %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
25 !CHECK: omp.wsloop for (%[[ARG0:.*]], %[[ARG1:.*]]) : i64 = (%[[TMP2]], %[[TMP5]]) to (%[[TMP3]], %[[TMP6]]) inclusive step (%[[TMP4]], %[[TMP7]]) {
26 !CHECK: fir.store %[[ARG0]] to %[[STORE_IV0:.*]] : !fir.ref<i64>
27 !CHECK: fir.store %[[ARG1]] to %[[STORE_IV1:.*]] : !fir.ref<i64>
28 !CHECK: %[[LOAD_IV0:.*]] = fir.load %[[STORE_IV0]] : !fir.ref<i64>
29 !CHECK: %[[LOAD_IV1:.*]] = fir.load %[[STORE_IV1]] : !fir.ref<i64>
30 !CHECK: %[[TMP10:.*]] = arith.addi %[[LOAD_IV0]], %[[LOAD_IV1]] : i64
31 !CHECK: %[[TMP11:.*]] = fir.convert %[[TMP10]] : (i64) -> f32
32 !CHECK: fir.store %[[TMP11]] to %{{.*}} : !fir.ref<f32>
37 do i2
= 1, i1_ub
, i2_s
38 do i8
= i16_lb
, 100, i4_s
44 !CHECK: %[[TMP12:.*]] = arith.constant 1 : i32
45 !CHECK: %[[TMP13:.*]] = fir.convert %{{.*}} : (i8) -> i32
46 !CHECK: %[[TMP14:.*]] = fir.convert %{{.*}} : (i64) -> i32
47 !CHECK: omp.wsloop for (%[[ARG0:.*]]) : i32 = (%[[TMP12]]) to (%[[TMP13]]) inclusive step (%[[TMP14]]) {
48 !CHECK: fir.store %[[ARG0]] to %[[STORE3:.*]] : !fir.ref<i32>
49 !CHECK: %[[LOAD3:.*]] = fir.load %[[STORE3]] : !fir.ref<i32>
50 !CHECK: %[[TMP16:.*]] = fir.convert %[[LOAD3]] : (i32) -> f32
52 !CHECK: fir.store %[[TMP16]] to %{{.*}} : !fir.ref<f32>
57 do i2
= 1, i1_ub
, i8_s
62 !CHECK: %[[TMP17:.*]] = fir.convert %{{.*}} : (i8) -> i64
63 !CHECK: %[[TMP18:.*]] = fir.convert %{{.*}} : (i16) -> i64
64 !CHECK: %[[TMP19:.*]] = fir.convert %{{.*}} : (i32) -> i64
65 !CHECK: omp.wsloop for (%[[ARG1:.*]]) : i64 = (%[[TMP17]]) to (%[[TMP18]]) inclusive step (%[[TMP19]]) {
66 !CHECK: fir.store %[[ARG1]] to %[[STORE4:.*]] : !fir.ref<i64>
67 !CHECK: %[[LOAD4:.*]] = fir.load %[[STORE4]] : !fir.ref<i64>
68 !CHECK: %[[TMP21:.*]] = fir.convert %[[LOAD4]] : (i64) -> f32
69 !CHECK: fir.store %[[TMP21]] to %{{.*}} : !fir.ref<f32>
74 do i16
= i1_lb
, i2_ub
, i4_s
79 end program wsloop_variable
81 !CHECK-LABEL: func.func @_QPwsloop_variable_sub() {
82 !CHECK: %[[VAL_0:.*]] = fir.alloca i128 {bindc_name = "i16_lb", uniq_name = "_QFwsloop_variable_subEi16_lb"}
83 !CHECK: %[[VAL_1:.*]] = fir.alloca i8 {bindc_name = "i1_ub", uniq_name = "_QFwsloop_variable_subEi1_ub"}
84 !CHECK: %[[VAL_2:.*]] = fir.alloca i16 {bindc_name = "i2", uniq_name = "_QFwsloop_variable_subEi2"}
85 !CHECK: %[[VAL_3:.*]] = fir.alloca i16 {bindc_name = "i2_s", uniq_name = "_QFwsloop_variable_subEi2_s"}
86 !CHECK: %[[VAL_4:.*]] = fir.alloca i32 {bindc_name = "i4_s", uniq_name = "_QFwsloop_variable_subEi4_s"}
87 !CHECK: %[[VAL_5:.*]] = fir.alloca i64 {bindc_name = "i8", uniq_name = "_QFwsloop_variable_subEi8"}
88 !CHECK: %[[VAL_6:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFwsloop_variable_subEx"}
89 !CHECK: %[[VAL_7:.*]] = arith.constant 1 : i32
90 !CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_1]] : !fir.ref<i8>
91 !CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_3]] : !fir.ref<i16>
92 !CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_8]] : (i8) -> i32
93 !CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_9]] : (i16) -> i32
94 !CHECK: omp.wsloop for (%[[ARG0:.*]]) : i32 = (%[[VAL_7]]) to (%[[VAL_10]]) inclusive step (%[[VAL_11]]) {
95 !CHECK: fir.store %[[ARG0]] to %[[STORE_IV:.*]] : !fir.ref<i32>
96 !CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_0]] : !fir.ref<i128>
97 !CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i128) -> index
98 !CHECK: %[[VAL_15:.*]] = arith.constant 100 : i32
99 !CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> index
100 !CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
101 !CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i32) -> index
102 !CHECK: %[[LB:.*]] = fir.convert %[[VAL_14]] : (index) -> i64
103 !CHECK: %[[VAL_19:.*]]:2 = fir.do_loop %[[VAL_20:[^ ]*]] =
104 !CHECK-SAME: %[[VAL_14]] to %[[VAL_16]] step %[[VAL_18]]
105 !CHECK-SAME: iter_args(%[[IV:.*]] = %[[LB]]) -> (index, i64) {
106 !CHECK: fir.store %[[IV]] to %[[VAL_5]] : !fir.ref<i64>
107 !CHECK: %[[LOAD_IV:.*]] = fir.load %[[STORE_IV]] : !fir.ref<i32>
108 !CHECK: %[[VAL_22:.*]] = fir.convert %[[LOAD_IV]] : (i32) -> i64
109 !CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
110 !CHECK: %[[VAL_24:.*]] = arith.addi %[[VAL_22]], %[[VAL_23]] : i64
111 !CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i64) -> f32
112 !CHECK: fir.store %[[VAL_25]] to %[[VAL_6]] : !fir.ref<f32>
113 !CHECK: %[[VAL_26:.*]] = arith.addi %[[VAL_20]], %[[VAL_18]] : index
114 !CHECK: %[[STEPCAST:.*]] = fir.convert %[[VAL_18]] : (index) -> i64
115 !CHECK: %[[IVLOAD:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
116 !CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]]
117 !CHECK: fir.result %[[VAL_26]], %[[IVINC]] : index, i64
119 !CHECK: fir.store %[[VAL_19]]#1 to %[[VAL_5]] : !fir.ref<i64>
125 subroutine wsloop_variable_sub
126 integer(kind
=1) :: i1_ub
127 integer(kind
=2) :: i2
, i2_s
128 integer(kind
=4) :: i4_s
129 integer(kind
=8) :: i8
130 integer(kind
=16) :: i16_lb
134 do i2
= 1, i1_ub
, i2_s
135 do i8
= i16_lb
, 100, i4_s