15b66987cSKiran Chandramohan! RUN: bbc -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s 25b66987cSKiran Chandramohan! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s 35b66987cSKiran Chandramohan 4be9f8ffdSDavid Truby! NOTE: Assertions have been autogenerated by utils/generate-test-checks.py 55b66987cSKiran Chandramohan 63deaa77fSTom Eccles! CHECK-LABEL: omp.declare_reduction @min_f32 : f32 init { 7be9f8ffdSDavid Truby! CHECK: ^bb0(%[[VAL_0:.*]]: f32): 8be9f8ffdSDavid Truby! CHECK: %[[VAL_1:.*]] = arith.constant 3.40282347E+38 : f32 9be9f8ffdSDavid Truby! CHECK: omp.yield(%[[VAL_1]] : f32) 105b66987cSKiran Chandramohan 11be9f8ffdSDavid Truby! CHECK-LABEL: } combiner { 12be9f8ffdSDavid Truby! CHECK: ^bb0(%[[VAL_0:.*]]: f32, %[[VAL_1:.*]]: f32): 130c455ee3SJan Leyonberg! CHECK: %[[VAL_2:.*]] = arith.minnumf %[[VAL_0]], %[[VAL_1]] fastmath<contract> : f32 14be9f8ffdSDavid Truby! CHECK: omp.yield(%[[VAL_2]] : f32) 15be9f8ffdSDavid Truby! CHECK: } 16be9f8ffdSDavid Truby 173deaa77fSTom Eccles! CHECK-LABEL: omp.declare_reduction @min_i32 : i32 init { 18be9f8ffdSDavid Truby! CHECK: ^bb0(%[[VAL_0:.*]]: i32): 19be9f8ffdSDavid Truby! CHECK: %[[VAL_1:.*]] = arith.constant 2147483647 : i32 20be9f8ffdSDavid Truby! CHECK: omp.yield(%[[VAL_1]] : i32) 21be9f8ffdSDavid Truby 22be9f8ffdSDavid Truby! CHECK-LABEL: } combiner { 23be9f8ffdSDavid Truby! CHECK: ^bb0(%[[VAL_0:.*]]: i32, %[[VAL_1:.*]]: i32): 24be9f8ffdSDavid Truby! CHECK: %[[VAL_2:.*]] = arith.minsi %[[VAL_0]], %[[VAL_1]] : i32 25be9f8ffdSDavid Truby! CHECK: omp.yield(%[[VAL_2]] : i32) 26be9f8ffdSDavid Truby! CHECK: } 27be9f8ffdSDavid Truby 28be9f8ffdSDavid Truby! CHECK-LABEL: func.func @_QPreduction_min_int( 29be9f8ffdSDavid Truby! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "y"}) { 30be9f8ffdSDavid Truby! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFreduction_min_intEi"} 31be9f8ffdSDavid Truby! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFreduction_min_intEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 32be9f8ffdSDavid Truby! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFreduction_min_intEx"} 33be9f8ffdSDavid Truby! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFreduction_min_intEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 341710c8cfSSlava Zakharin! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFreduction_min_intEy"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>) 35be9f8ffdSDavid Truby! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i32 36be9f8ffdSDavid Truby! CHECK: hlfir.assign %[[VAL_6]] to %[[VAL_4]]#0 : i32, !fir.ref<i32> 37be9f8ffdSDavid Truby! CHECK: omp.parallel { 38*937cbce1SKareem Ergawy! CHECK: %[[VAL_7:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}} 39*937cbce1SKareem Ergawy! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_7]] {uniq_name = "_QFreduction_min_intEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 40be9f8ffdSDavid Truby! CHECK: %[[VAL_9:.*]] = arith.constant 1 : i32 41be9f8ffdSDavid Truby! CHECK: %[[VAL_10:.*]] = arith.constant 100 : i32 42be9f8ffdSDavid Truby! CHECK: %[[VAL_11:.*]] = arith.constant 1 : i32 43*937cbce1SKareem Ergawy! CHECK: omp.wsloop reduction(@min_i32 %[[VAL_4]]#0 -> %[[VAL_12:.*]] : !fir.ref<i32>) { 44ca4dbc27SSergio Afonso! CHECK-NEXT: omp.loop_nest (%[[VAL_13:.*]]) : i32 = (%[[VAL_9]]) to (%[[VAL_10]]) inclusive step (%[[VAL_11]]) { 45be9f8ffdSDavid Truby! CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_12]] {uniq_name = "_QFreduction_min_intEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 46ca4dbc27SSergio Afonso! CHECK: fir.store %[[VAL_13]] to %[[VAL_8]]#1 : !fir.ref<i32> 47be9f8ffdSDavid Truby! CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_8]]#0 : !fir.ref<i32> 48be9f8ffdSDavid Truby! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> i64 49be9f8ffdSDavid Truby! CHECK: %[[VAL_17:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_16]]) : (!fir.box<!fir.array<?xi32>>, i64) -> !fir.ref<i32> 50be9f8ffdSDavid Truby! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_14]]#0 : !fir.ref<i32> 51be9f8ffdSDavid Truby! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_17]] : !fir.ref<i32> 52be9f8ffdSDavid Truby! CHECK: %[[VAL_20:.*]] = arith.cmpi slt, %[[VAL_18]], %[[VAL_19]] : i32 53be9f8ffdSDavid Truby! CHECK: %[[VAL_21:.*]] = arith.select %[[VAL_20]], %[[VAL_18]], %[[VAL_19]] : i32 54be9f8ffdSDavid Truby! CHECK: hlfir.assign %[[VAL_21]] to %[[VAL_14]]#0 : i32, !fir.ref<i32> 555b66987cSKiran Chandramohan! CHECK: omp.yield 565b66987cSKiran Chandramohan! CHECK: omp.terminator 575b66987cSKiran Chandramohan 58be9f8ffdSDavid Truby! CHECK-LABEL: func.func @_QPreduction_min_real( 59be9f8ffdSDavid Truby! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "y"}) { 60be9f8ffdSDavid Truby! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFreduction_min_realEi"} 61be9f8ffdSDavid Truby! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFreduction_min_realEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 62be9f8ffdSDavid Truby! CHECK: %[[VAL_3:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFreduction_min_realEx"} 63be9f8ffdSDavid Truby! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFreduction_min_realEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) 641710c8cfSSlava Zakharin! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFreduction_min_realEy"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) 65be9f8ffdSDavid Truby! CHECK: %[[VAL_6:.*]] = arith.constant 0.000000e+00 : f32 66be9f8ffdSDavid Truby! CHECK: hlfir.assign %[[VAL_6]] to %[[VAL_4]]#0 : f32, !fir.ref<f32> 67be9f8ffdSDavid Truby! CHECK: omp.parallel { 68*937cbce1SKareem Ergawy! CHECK: %[[VAL_7:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}} 69*937cbce1SKareem Ergawy! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_7]] {uniq_name = "_QFreduction_min_realEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 70be9f8ffdSDavid Truby! CHECK: %[[VAL_9:.*]] = arith.constant 1 : i32 71be9f8ffdSDavid Truby! CHECK: %[[VAL_10:.*]] = arith.constant 100 : i32 72be9f8ffdSDavid Truby! CHECK: %[[VAL_11:.*]] = arith.constant 1 : i32 73*937cbce1SKareem Ergawy! CHECK: omp.wsloop reduction(@min_f32 %[[VAL_4]]#0 -> %[[VAL_12:.*]] : !fir.ref<f32>) { 74ca4dbc27SSergio Afonso! CHECK-NEXT: omp.loop_nest (%[[VAL_13:.*]]) : i32 = (%[[VAL_9]]) to (%[[VAL_10]]) inclusive step (%[[VAL_11]]) { 75be9f8ffdSDavid Truby! CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_12]] {uniq_name = "_QFreduction_min_realEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) 76ca4dbc27SSergio Afonso! CHECK: fir.store %[[VAL_13]] to %[[VAL_8]]#1 : !fir.ref<i32> 77be9f8ffdSDavid Truby! CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_8]]#0 : !fir.ref<i32> 78be9f8ffdSDavid Truby! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> i64 79be9f8ffdSDavid Truby! CHECK: %[[VAL_17:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_16]]) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> 80be9f8ffdSDavid Truby! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_17]] : !fir.ref<f32> 81be9f8ffdSDavid Truby! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_14]]#0 : !fir.ref<f32> 82be9f8ffdSDavid Truby! CHECK: %[[VAL_20:.*]] = arith.cmpf olt, %[[VAL_18]], %[[VAL_19]] fastmath<contract> : f32 83be9f8ffdSDavid Truby! CHECK: %[[VAL_21:.*]] = arith.select %[[VAL_20]], %[[VAL_18]], %[[VAL_19]] : f32 84be9f8ffdSDavid Truby! CHECK: hlfir.assign %[[VAL_21]] to %[[VAL_14]]#0 : f32, !fir.ref<f32> 85be9f8ffdSDavid Truby! CHECK: omp.yield 86be9f8ffdSDavid Truby! CHECK: } 87be9f8ffdSDavid Truby! CHECK: omp.terminator 88be9f8ffdSDavid Truby! CHECK: } 89be9f8ffdSDavid Truby! CHECK: omp.parallel { 90*937cbce1SKareem Ergawy! CHECK: %[[VAL_30:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}} 91*937cbce1SKareem Ergawy! CHECK: %[[VAL_31:.*]]:2 = hlfir.declare %[[VAL_30]] {uniq_name = "_QFreduction_min_realEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 92be9f8ffdSDavid Truby! CHECK: %[[VAL_32:.*]] = arith.constant 1 : i32 93be9f8ffdSDavid Truby! CHECK: %[[VAL_33:.*]] = arith.constant 100 : i32 94be9f8ffdSDavid Truby! CHECK: %[[VAL_34:.*]] = arith.constant 1 : i32 95*937cbce1SKareem Ergawy! CHECK: omp.wsloop reduction(@min_f32 %[[VAL_4]]#0 -> %[[VAL_35:.*]] : !fir.ref<f32>) { 96ca4dbc27SSergio Afonso! CHECK-NEXT: omp.loop_nest (%[[VAL_36:.*]]) : i32 = (%[[VAL_32]]) to (%[[VAL_33]]) inclusive step (%[[VAL_34]]) { 97be9f8ffdSDavid Truby! CHECK: %[[VAL_37:.*]]:2 = hlfir.declare %[[VAL_35]] {uniq_name = "_QFreduction_min_realEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) 98ca4dbc27SSergio Afonso! CHECK: fir.store %[[VAL_36]] to %[[VAL_31]]#1 : !fir.ref<i32> 99be9f8ffdSDavid Truby! CHECK: %[[VAL_38:.*]] = fir.load %[[VAL_31]]#0 : !fir.ref<i32> 100be9f8ffdSDavid Truby! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_38]] : (i32) -> i64 101be9f8ffdSDavid Truby! CHECK: %[[VAL_40:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_39]]) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> 102be9f8ffdSDavid Truby! CHECK: %[[VAL_41:.*]] = fir.load %[[VAL_40]] : !fir.ref<f32> 103be9f8ffdSDavid Truby! CHECK: %[[VAL_42:.*]] = fir.load %[[VAL_37]]#0 : !fir.ref<f32> 104be9f8ffdSDavid Truby! CHECK: %[[VAL_43:.*]] = arith.cmpf ogt, %[[VAL_41]], %[[VAL_42]] fastmath<contract> : f32 105be9f8ffdSDavid Truby! CHECK: fir.if %[[VAL_43]] { 106be9f8ffdSDavid Truby! CHECK: %[[VAL_44:.*]] = fir.load %[[VAL_31]]#0 : !fir.ref<i32> 107be9f8ffdSDavid Truby! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (i32) -> i64 108be9f8ffdSDavid Truby! CHECK: %[[VAL_46:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_45]]) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> 109be9f8ffdSDavid Truby! CHECK: %[[VAL_47:.*]] = fir.load %[[VAL_46]] : !fir.ref<f32> 110be9f8ffdSDavid Truby! CHECK: hlfir.assign %[[VAL_47]] to %[[VAL_37]]#0 : f32, !fir.ref<f32> 111be9f8ffdSDavid Truby! CHECK: } 1125b66987cSKiran Chandramohan! CHECK: omp.yield 1135b66987cSKiran Chandramohan! CHECK: omp.terminator 1145b66987cSKiran Chandramohan 115be9f8ffdSDavid Truby 116be9f8ffdSDavid Truby 1175b66987cSKiran Chandramohansubroutine reduction_min_int(y) 1185b66987cSKiran Chandramohan integer :: x, y(:) 1195b66987cSKiran Chandramohan x = 0 1205b66987cSKiran Chandramohan !$omp parallel 1215b66987cSKiran Chandramohan !$omp do reduction(min:x) 1225b66987cSKiran Chandramohan do i=1, 100 1235b66987cSKiran Chandramohan x = min(x, y(i)) 1245b66987cSKiran Chandramohan end do 1255b66987cSKiran Chandramohan !$omp end do 1265b66987cSKiran Chandramohan !$omp end parallel 1275b66987cSKiran Chandramohan print *, x 1285b66987cSKiran Chandramohanend subroutine 1295b66987cSKiran Chandramohan 1305b66987cSKiran Chandramohansubroutine reduction_min_real(y) 1315b66987cSKiran Chandramohan real :: x, y(:) 1325b66987cSKiran Chandramohan x = 0.0 1335b66987cSKiran Chandramohan !$omp parallel 1345b66987cSKiran Chandramohan !$omp do reduction(min:x) 1355b66987cSKiran Chandramohan do i=1, 100 1365b66987cSKiran Chandramohan x = min(y(i), x) 1375b66987cSKiran Chandramohan end do 1385b66987cSKiran Chandramohan !$omp end do 1395b66987cSKiran Chandramohan !$omp end parallel 1405b66987cSKiran Chandramohan print *, x 1415b66987cSKiran Chandramohan 1425b66987cSKiran Chandramohan !$omp parallel 1435b66987cSKiran Chandramohan !$omp do reduction(min:x) 1445b66987cSKiran Chandramohan do i=1, 100 1455b66987cSKiran Chandramohan if (y(i) .gt. x) x = y(i) 1465b66987cSKiran Chandramohan end do 1475b66987cSKiran Chandramohan !$omp end do 1485b66987cSKiran Chandramohan !$omp end parallel 1495b66987cSKiran Chandramohan print *, x 1505b66987cSKiran Chandramohanend subroutine 151