xref: /llvm-project/flang/test/Lower/OpenMP/wsloop-reduction-min2.f90 (revision 937cbce14c9aa956342a9c818c26a8a557802843)
1! RUN: bbc -emit-hlfir -fopenmp -o - %s | FileCheck %s
2! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s | FileCheck %s
3
4! regression test for crash
5
6program reduce
7integer :: i = 0
8integer :: r = 0
9
10!$omp parallel do reduction(min:r)
11do i=0,10
12   r = i
13enddo
14!$omp end parallel do
15
16print *,r
17
18end program
19
20! CHECK-LABEL:   omp.declare_reduction @min_i32 : i32 init {
21! CHECK:         ^bb0(%[[VAL_0:.*]]: i32):
22! CHECK:           %[[VAL_1:.*]] = arith.constant 2147483647 : i32
23! CHECK:           omp.yield(%[[VAL_1]] : i32)
24
25! CHECK-LABEL:   } combiner {
26! CHECK:         ^bb0(%[[VAL_0:.*]]: i32, %[[VAL_1:.*]]: i32):
27! CHECK:           %[[VAL_2:.*]] = arith.minsi %[[VAL_0]], %[[VAL_1]] : i32
28! CHECK:           omp.yield(%[[VAL_2]] : i32)
29! CHECK:         }
30
31! CHECK-LABEL:   func.func @_QQmain() attributes {fir.bindc_name = "reduce"} {
32! CHECK:           %[[VAL_0:.*]] = fir.address_of(@_QFEi) : !fir.ref<i32>
33! CHECK:           %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
34! CHECK:           %[[VAL_2:.*]] = fir.address_of(@_QFEr) : !fir.ref<i32>
35! CHECK:           %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QFEr"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
36! CHECK:           omp.parallel {
37! CHECK:             %[[VAL_4:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
38! CHECK:             %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_4]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
39! CHECK:             %[[VAL_6:.*]] = arith.constant 0 : i32
40! CHECK:             %[[VAL_7:.*]] = arith.constant 10 : i32
41! CHECK:             %[[VAL_8:.*]] = arith.constant 1 : i32
42! CHECK:             omp.wsloop reduction(@min_i32 %[[VAL_3]]#0 -> %[[VAL_9:.*]] : !fir.ref<i32>) {
43! CHECK-NEXT:          omp.loop_nest (%[[VAL_10:.*]]) : i32 = (%[[VAL_6]]) to (%[[VAL_7]]) inclusive step (%[[VAL_8]]) {
44! CHECK:                 %[[VAL_11:.*]]:2 = hlfir.declare %[[VAL_9]] {uniq_name = "_QFEr"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
45! CHECK:                 fir.store %[[VAL_10]] to %[[VAL_5]]#1 : !fir.ref<i32>
46! CHECK:                 %[[VAL_12:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
47! CHECK:                 hlfir.assign %[[VAL_12]] to %[[VAL_11]]#0 : i32, !fir.ref<i32>
48! CHECK:                 omp.yield
49! CHECK:               }
50! CHECK:             omp.terminator
51! CHECK:           }
52