xref: /llvm-project/flang/test/Lower/OpenMP/wsloop-reduction-ior-byref.f90 (revision 937cbce14c9aa956342a9c818c26a8a557802843)
1! RUN: bbc -emit-hlfir -fopenmp --force-byref-reduction %s -o - | FileCheck %s
2! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --force-byref-reduction %s -o - | FileCheck %s
3
4! CHECK-LABEL:   omp.declare_reduction @ior_byref_i32 : !fir.ref<i32>
5! CHECK-SAME:    alloc {
6! CHECK:            %[[REF:.*]] = fir.alloca i32
7! CHECK:            omp.yield(%[[REF]] : !fir.ref<i32>)
8! CHECK-LABEL:   } init {
9! CHECK:         ^bb0(%[[VAL_0:.*]]: !fir.ref<i32>, %[[ALLOC:.*]]: !fir.ref<i32>):
10! CHECK:            %[[C0_1:.*]] = arith.constant 0 : i32
11! CHECK:            fir.store %[[C0_1]] to %[[ALLOC]] : !fir.ref<i32>
12! CHECK:            omp.yield(%[[ALLOC]] : !fir.ref<i32>)
13
14! CHECK-LABEL:   } combiner {
15! CHECK:         ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):
16! CHECK:           %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
17! CHECK:           %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>
18! CHECK:           %[[RES:.*]] = arith.ori %[[LD0]], %[[LD1]] : i32
19! CHECK:           fir.store %[[RES]] to %[[ARG0]] : !fir.ref<i32>
20! CHECK:           omp.yield(%[[ARG0]] : !fir.ref<i32>)
21! CHECK:         }
22
23! CHECK-LABEL:   func.func @_QPreduction_ior(
24! CHECK-SAME:                                %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "y"}) {
25! CHECK:           %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFreduction_iorEi"}
26! CHECK:           %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFreduction_iorEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
27! CHECK:           %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFreduction_iorEx"}
28! CHECK:           %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFreduction_iorEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
29! CHECK:           %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFreduction_iorEy"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
30! CHECK:           %[[VAL_6:.*]] = arith.constant 0 : i32
31! CHECK:           hlfir.assign %[[VAL_6]] to %[[VAL_4]]#0 : i32, !fir.ref<i32>
32! CHECK:           omp.parallel
33! CHECK:             %[[VAL_7:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
34! CHECK:             %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_7]] {uniq_name = "_QFreduction_iorEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
35! CHECK:             %[[VAL_9:.*]] = arith.constant 1 : i32
36! CHECK:             %[[VAL_10:.*]] = arith.constant 100 : i32
37! CHECK:             %[[VAL_11:.*]] = arith.constant 1 : i32
38! CHECK:             omp.wsloop reduction(byref @ior_byref_i32 %[[VAL_4]]#0 -> %[[VAL_12:.*]] : !fir.ref<i32>) {
39! CHECK-NEXT:          omp.loop_nest (%[[VAL_13:.*]]) : i32 = (%[[VAL_9]]) to (%[[VAL_10]]) inclusive step (%[[VAL_11]]) {
40! CHECK:                 %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_12]] {uniq_name = "_QFreduction_iorEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
41! CHECK:                 fir.store %[[VAL_13]] to %[[VAL_8]]#1 : !fir.ref<i32>
42! CHECK:                 %[[VAL_15:.*]] = fir.load %[[VAL_8]]#0 : !fir.ref<i32>
43! CHECK:                 %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> i64
44! CHECK:                 %[[VAL_17:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_16]])  : (!fir.box<!fir.array<?xi32>>, i64) -> !fir.ref<i32>
45! CHECK:                 %[[VAL_18:.*]] = fir.load %[[VAL_14]]#0 : !fir.ref<i32>
46! CHECK:                 %[[VAL_19:.*]] = fir.load %[[VAL_17]] : !fir.ref<i32>
47! CHECK:                 %[[VAL_20:.*]] = arith.ori %[[VAL_18]], %[[VAL_19]] : i32
48! CHECK:                 hlfir.assign %[[VAL_20]] to %[[VAL_14]]#0 : i32, !fir.ref<i32>
49! CHECK:                 omp.yield
50! CHECK:             omp.terminator
51
52
53
54subroutine reduction_ior(y)
55  integer :: x, y(:)
56  x = 0
57  !$omp parallel
58  !$omp do reduction(ior:x)
59  do i=1, 100
60    x = ior(x, y(i))
61  end do
62  !$omp end do
63  !$omp end parallel
64  print *, x
65end subroutine
66