Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / wsloop-reduction-logical-eqv.f90
blobe8cf46f8261c4fc61cc07f70c505e56406de8e6d
1 ! RUN: bbc -emit-fir -fopenmp %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
4 !CHECK-LABEL: omp.reduction.declare
5 !CHECK-SAME: @[[RED_NAME:.*]] : !fir.logical<4> init {
6 !CHECK: ^bb0(%{{.*}}: !fir.logical<4>):
7 !CHECK: %true = arith.constant true
8 !CHECK: %[[true_fir:.*]] = fir.convert %true : (i1) -> !fir.logical<4>
9 !CHECK: omp.yield(%[[true_fir]] : !fir.logical<4>)
10 !CHECK: } combiner {
11 !CHECK: ^bb0(%[[ARG0:.*]]: !fir.logical<4>, %[[ARG1:.*]]: !fir.logical<4>):
12 !CHECK: %[[arg0_i1:.*]] = fir.convert %[[ARG0]] : (!fir.logical<4>) -> i1
13 !CHECK: %[[arg1_i1:.*]] = fir.convert %[[ARG1]] : (!fir.logical<4>) -> i1
14 !CHECK: %[[RES:.*]] = arith.cmpi eq, %[[arg0_i1]], %[[arg1_i1]] : i1
15 !CHECK: %[[RES_logical:.*]] = fir.convert %[[RES]] : (i1) -> !fir.logical<4>
16 !CHECK: omp.yield(%[[RES_logical]] : !fir.logical<4>)
17 !CHECK: }
19 !CHECK-LABEL: func.func @_QPsimple_reduction(
20 !CHECK-SAME: %[[ARRAY:.*]]: !fir.ref<!fir.array<100x!fir.logical<4>>> {fir.bindc_name = "y"}) {
21 !CHECK: %[[IREF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_reductionEi"}
22 !CHECK: %[[XREF:.*]] = fir.alloca !fir.logical<4> {bindc_name = "x", uniq_name = "_QFsimple_reductionEx"}
23 !CHECK: omp.parallel
24 !CHECK: %[[I_PVT_REF:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
25 !CHECK: %[[C1_1:.*]] = arith.constant 1 : i32
26 !CHECK: %[[C100:.*]] = arith.constant 100 : i32
27 !CHECK: %[[C1_2:.*]] = arith.constant 1 : i32
28 !CHECK: omp.wsloop reduction(@[[RED_NAME]] -> %[[XREF]] : !fir.ref<!fir.logical<4>>) for (%[[IVAL:.*]]) : i32 = (%[[C1_1]]) to (%[[C100]]) inclusive step (%[[C1_2]]) {
29 !CHECK: fir.store %[[IVAL]] to %[[I_PVT_REF]] : !fir.ref<i32>
30 !CHECK: %[[I_PVT_VAL:.*]] = fir.load %[[I_PVT_REF]] : !fir.ref<i32>
31 !CHECK: %[[CONVI_64:.*]] = fir.convert %[[I_PVT_VAL]] : (i32) -> i64
32 !CHECK: %[[C1_64:.*]] = arith.constant 1 : i64
33 !CHECK: %[[SUBI:.*]] = arith.subi %[[CONVI_64]], %[[C1_64]] : i64
34 !CHECK: %[[Y_PVT_REF:.*]] = fir.coordinate_of %[[ARRAY]], %[[SUBI]] : (!fir.ref<!fir.array<100x!fir.logical<4>>>, i64) -> !fir.ref<!fir.logical<4>>
35 !CHECK: %[[YVAL:.*]] = fir.load %[[Y_PVT_REF]] : !fir.ref<!fir.logical<4>>
36 !CHECK: omp.reduction %[[YVAL]], %[[XREF]] : !fir.logical<4>, !fir.ref<!fir.logical<4>>
37 !CHECK: omp.yield
38 !CHECK: omp.terminator
39 !CHECK: return
40 subroutine simple_reduction(y)
41 logical :: x, y(100)
42 x = .true.
43 !$omp parallel
44 !$omp do reduction(.eqv.:x)
45 do i=1, 100
46 x = x .eqv. y(i)
47 end do
48 !$omp end do
49 !$omp end parallel
50 end subroutine
52 !CHECK-LABEL: func.func @_QPsimple_reduction_switch_order(
53 !CHECK-SAME: %[[ARRAY:.*]]: !fir.ref<!fir.array<100x!fir.logical<4>>> {fir.bindc_name = "y"}) {
54 !CHECK: %[[IREF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_reduction_switch_orderEi"}
55 !CHECK: %[[XREF:.*]] = fir.alloca !fir.logical<4> {bindc_name = "x", uniq_name = "_QFsimple_reduction_switch_orderEx"}
56 !CHECK: omp.parallel
57 !CHECK: %[[I_PVT_REF:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
58 !CHECK: %[[C1_1:.*]] = arith.constant 1 : i32
59 !CHECK: %[[C100:.*]] = arith.constant 100 : i32
60 !CHECK: %[[C1_2:.*]] = arith.constant 1 : i32
61 !CHECK: omp.wsloop reduction(@[[RED_NAME]] -> %[[XREF]] : !fir.ref<!fir.logical<4>>) for (%[[IVAL:.*]]) : i32 = (%[[C1_1]]) to (%[[C100]]) inclusive step (%[[C1_2]]) {
62 !CHECK: fir.store %[[IVAL]] to %[[I_PVT_REF]] : !fir.ref<i32>
63 !CHECK: %[[I_PVT_VAL:.*]] = fir.load %[[I_PVT_REF]] : !fir.ref<i32>
64 !CHECK: %[[CONVI_64:.*]] = fir.convert %[[I_PVT_VAL]] : (i32) -> i64
65 !CHECK: %[[C1_64:.*]] = arith.constant 1 : i64
66 !CHECK: %[[SUBI:.*]] = arith.subi %[[CONVI_64]], %[[C1_64]] : i64
67 !CHECK: %[[Y_PVT_REF:.*]] = fir.coordinate_of %[[ARRAY]], %[[SUBI]] : (!fir.ref<!fir.array<100x!fir.logical<4>>>, i64) -> !fir.ref<!fir.logical<4>>
68 !CHECK: %[[YVAL:.*]] = fir.load %[[Y_PVT_REF]] : !fir.ref<!fir.logical<4>>
69 !CHECK: omp.reduction %[[YVAL]], %[[XREF]] : !fir.logical<4>, !fir.ref<!fir.logical<4>>
70 !CHECK: omp.yield
71 !CHECK: omp.terminator
72 !CHECK: return
73 subroutine simple_reduction_switch_order(y)
74 logical :: x, y(100)
75 x = .true.
76 !$omp parallel
77 !$omp do reduction(.eqv.:x)
78 do i=1, 100
79 x = y(i) .eqv. x
80 end do
81 !$omp end do
82 !$omp end parallel
83 end subroutine
85 !CHECK-LABEL: func.func @_QPmultiple_reductions
86 !CHECK-SAME %[[ARRAY:.*]]: !fir.ref<!fir.array<100x!fir.logical<4>>> {fir.bindc_name = "w"}) {
87 !CHECK: %[[IREF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFmultiple_reductionsEi"}
88 !CHECK: %[[XREF:.*]] = fir.alloca !fir.logical<4> {bindc_name = "x", uniq_name = "_QFmultiple_reductionsEx"}
89 !CHECK: %[[YREF:.*]] = fir.alloca !fir.logical<4> {bindc_name = "y", uniq_name = "_QFmultiple_reductionsEy"}
90 !CHECK: %[[ZREF:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z", uniq_name = "_QFmultiple_reductionsEz"}
91 !CHECK: omp.parallel
92 !CHECK: %[[I_PVT_REF:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
93 !CHECK: %[[C1_1:.*]] = arith.constant 1 : i32
94 !CHECK: %[[C100:.*]] = arith.constant 100 : i32
95 !CHECK: %[[C1_2:.*]] = arith.constant 1 : i32
96 !CHECK: omp.wsloop reduction(@[[RED_NAME]] -> %[[XREF]] : !fir.ref<!fir.logical<4>>, @[[RED_NAME]] -> %[[YREF]] : !fir.ref<!fir.logical<4>>, @[[RED_NAME]] -> %[[ZREF]] : !fir.ref<!fir.logical<4>>) for (%[[IVAL:.*]]) : i32 = (%[[C1_1]]) to (%[[C100]]) inclusive step (%[[C1_2]]) {
97 !CHECK: fir.store %[[IVAL]] to %[[I_PVT_REF]] : !fir.ref<i32>
98 !CHECK: %[[I_PVT_VAL1:.*]] = fir.load %[[I_PVT_REF]] : !fir.ref<i32>
99 !CHECK: %[[CONVI_64_1:.*]] = fir.convert %[[I_PVT_VAL1]] : (i32) -> i64
100 !CHECK: %[[C1_64:.*]] = arith.constant 1 : i64
101 !CHECK: %[[SUBI_1:.*]] = arith.subi %[[CONVI_64_1]], %[[C1_64]] : i64
102 !CHECK: %[[W_PVT_REF_1:.*]] = fir.coordinate_of %[[ARRAY]], %[[SUBI_1]] : (!fir.ref<!fir.array<100x!fir.logical<4>>>, i64) -> !fir.ref<!fir.logical<4>>
103 !CHECK: %[[WVAL:.*]] = fir.load %[[W_PVT_REF_1]] : !fir.ref<!fir.logical<4>>
104 !CHECK: omp.reduction %[[WVAL]], %[[XREF]] : !fir.logical<4>, !fir.ref<!fir.logical<4>>
105 !CHECK: %[[I_PVT_VAL2:.*]] = fir.load %[[I_PVT_REF]] : !fir.ref<i32>
106 !CHECK: %[[CONVI_64_2:.*]] = fir.convert %[[I_PVT_VAL2]] : (i32) -> i64
107 !CHECK: %[[C1_64:.*]] = arith.constant 1 : i64
108 !CHECK: %[[SUBI_2:.*]] = arith.subi %[[CONVI_64_2]], %[[C1_64]] : i64
109 !CHECK: %[[W_PVT_REF_2:.*]] = fir.coordinate_of %[[ARRAY]], %[[SUBI_2]] : (!fir.ref<!fir.array<100x!fir.logical<4>>>, i64) -> !fir.ref<!fir.logical<4>>
110 !CHECK: %[[WVAL:.*]] = fir.load %[[W_PVT_REF_2]] : !fir.ref<!fir.logical<4>>
111 !CHECK: omp.reduction %[[WVAL]], %[[YREF]] : !fir.logical<4>, !fir.ref<!fir.logical<4>>
112 !CHECK: %[[I_PVT_VAL3:.*]] = fir.load %[[I_PVT_REF]] : !fir.ref<i32>
113 !CHECK: %[[CONVI_64_3:.*]] = fir.convert %[[I_PVT_VAL3]] : (i32) -> i64
114 !CHECK: %[[C1_64:.*]] = arith.constant 1 : i64
115 !CHECK: %[[SUBI_3:.*]] = arith.subi %[[CONVI_64_3]], %[[C1_64]] : i64
116 !CHECK: %[[W_PVT_REF_3:.*]] = fir.coordinate_of %[[ARRAY]], %[[SUBI_3]] : (!fir.ref<!fir.array<100x!fir.logical<4>>>, i64) -> !fir.ref<!fir.logical<4>>
117 !CHECK: %[[WVAL:.*]] = fir.load %[[W_PVT_REF_3]] : !fir.ref<!fir.logical<4>>
118 !CHECK: omp.reduction %[[WVAL]], %[[ZREF]] : !fir.logical<4>, !fir.ref<!fir.logical<4>>
119 !CHECK: omp.yield
120 !CHECK: omp.terminator
121 !CHECK: return
122 subroutine multiple_reductions(w)
123 logical :: x,y,z,w(100)
124 x = .true.
125 y = .true.
126 z = .true.
127 !$omp parallel
128 !$omp do reduction(.eqv.:x,y,z)
129 do i=1, 100
130 x = x .eqv. w(i)
131 y = y .eqv. w(i)
132 z = z .eqv. w(i)
133 end do
134 !$omp end do
135 !$omp end parallel
136 end subroutine