brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.9 KiB · 73a8885 Raw
156 lines · plain
1! RUN: bbc -emit-hlfir -fopenmp --force-byref-reduction -o - %s 2>&1 | FileCheck %s2! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --force-byref-reduction -o - %s 2>&1 | FileCheck %s3 4! NOTE: Assertions have been autogenerated by utils/generate-test-checks.py5 6!CHECK-LABEL: omp.declare_reduction @max_byref_f32 : !fir.ref<f32>7!CHECK-SAME: alloc {8!CHECK:   %[[REF:.*]] = fir.alloca f329!CHECK:   omp.yield(%[[REF]] : !fir.ref<f32>)10!CHECK-LABEL: } init {11!CHECK:   %[[MINIMUM_VAL:.*]] = arith.constant -3.40282347E+38 : f3212!CHECK:   fir.store %[[MINIMUM_VAL]] to %[[ALLOC:.*]] : !fir.ref<f32>13!CHECK:   omp.yield(%[[ALLOC]] : !fir.ref<f32>)14!CHECK: combiner15!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):16!CHECK:   %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>17!CHECK:   %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<f32>18!CHECK:   %[[RES:.*]] = arith.maxnumf %[[LD0]], %[[LD1]] {{.*}}: f3219!CHECK:   fir.store %[[RES]] to %[[ARG0]] : !fir.ref<f32>20!CHECK:   omp.yield(%[[ARG0]] : !fir.ref<f32>)21 22!CHECK-LABEL: omp.declare_reduction @max_byref_i32 : !fir.ref<i32>23!CHECK-SAME: alloc {24!CHECK:   %[[REF:.*]] = fir.alloca i3225!CHECK:   omp.yield(%[[REF]] : !fir.ref<i32>)26!CHECK-LABEL: } init {27!CHECK:   %[[MINIMUM_VAL:.*]] = arith.constant -2147483648 : i3228!CHECK:   fir.store %[[MINIMUM_VAL]] to %[[ALLOC:.*]] : !fir.ref<i32>29!CHECK:   omp.yield(%[[ALLOC]] : !fir.ref<i32>)30!CHECK: combiner31!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>):32!CHECK:   %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>33!CHECK:   %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>34!CHECK:   %[[RES:.*]] = arith.maxsi %[[LD0]], %[[LD1]] : i3235!CHECK:   fir.store %[[RES]] to %[[ARG0]] : !fir.ref<i32>36!CHECK:   omp.yield(%[[ARG0]] : !fir.ref<i32>)37 38! CHECK-LABEL:   func.func @_QPreduction_max_int(39! CHECK-SAME:                                    %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "y"}) {40! CHECK:           %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFreduction_max_intEi"}41! CHECK:           %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFreduction_max_intEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)42! CHECK:           %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFreduction_max_intEx"}43! CHECK:           %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFreduction_max_intEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)44! CHECK:           %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFreduction_max_intEy"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)45! CHECK:           %[[VAL_6:.*]] = arith.constant 0 : i3246! CHECK:           hlfir.assign %[[VAL_6]] to %[[VAL_4]]#0 : i32, !fir.ref<i32>47! CHECK:           omp.parallel {48! CHECK:             %[[VAL_9:.*]] = arith.constant 1 : i3249! CHECK:             %[[VAL_10:.*]] = arith.constant 100 : i3250! CHECK:             %[[VAL_11:.*]] = arith.constant 1 : i3251! CHECK:             omp.wsloop private(@{{.*}} %{{.*}}#0 -> %[[VAL_7:.*]] : !fir.ref<i32>) reduction(byref @max_byref_i32 %[[VAL_4]]#0 -> %[[VAL_12:.*]] : !fir.ref<i32>) {52! CHECK-NEXT:          omp.loop_nest (%[[VAL_13:.*]]) : i32 = (%[[VAL_9]]) to (%[[VAL_10]]) inclusive step (%[[VAL_11]]) {53! CHECK:                 %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_7]] {uniq_name = "_QFreduction_max_intEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)54! CHECK:                 %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_12]] {uniq_name = "_QFreduction_max_intEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)55! CHECK:                 hlfir.assign %[[VAL_13]] to %[[VAL_8]]#0 : i32, !fir.ref<i32>56! CHECK-DAG:                 %[[VAL_15:.*]] = fir.load %[[VAL_8]]#0 : !fir.ref<i32>57! CHECK-DAG:                 %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> i6458! CHECK-DAG:                 %[[VAL_17:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_16]])  : (!fir.box<!fir.array<?xi32>>, i64) -> !fir.ref<i32>59! CHECK-DAG:                 %[[VAL_18:.*]] = fir.load %[[VAL_14]]#0 : !fir.ref<i32>60! CHECK-DAG:                 %[[VAL_19:.*]] = fir.load %[[VAL_17]] : !fir.ref<i32>61! CHECK:                 %[[VAL_20:.*]] = arith.cmpi sgt, %[[VAL_18]], %[[VAL_19]] : i3262! CHECK:                 %[[VAL_21:.*]] = arith.select %[[VAL_20]], %[[VAL_18]], %[[VAL_19]] : i3263! CHECK:                 hlfir.assign %[[VAL_21]] to %[[VAL_14]]#0 : i32, !fir.ref<i32>64! CHECK:                 omp.yield65! CHECK:             omp.terminator66 67! CHECK-LABEL:   func.func @_QPreduction_max_real(68! CHECK-SAME:                                     %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "y"}) {69! CHECK:           %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFreduction_max_realEi"}70! CHECK:           %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFreduction_max_realEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)71! CHECK:           %[[VAL_3:.*]] = fir.alloca f32 {bindc_name = "x", uniq_name = "_QFreduction_max_realEx"}72! CHECK:           %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFreduction_max_realEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)73! CHECK:           %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFreduction_max_realEy"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)74! CHECK:           %[[VAL_6:.*]] = arith.constant 0.000000e+00 : f3275! CHECK:           hlfir.assign %[[VAL_6]] to %[[VAL_4]]#0 : f32, !fir.ref<f32>76! CHECK:           omp.parallel {77! CHECK:             %[[VAL_9:.*]] = arith.constant 1 : i3278! CHECK:             %[[VAL_10:.*]] = arith.constant 100 : i3279! CHECK:             %[[VAL_11:.*]] = arith.constant 1 : i3280! CHECK:             omp.wsloop private(@{{.*}} %{{.*}}#0 -> %[[VAL_7:.*]] : !fir.ref<i32>) reduction(byref @max_byref_f32 %[[VAL_4]]#0 -> %[[VAL_12:.*]] : !fir.ref<f32>) {81! CHECK-NEXT:          omp.loop_nest (%[[VAL_13:.*]]) : i32 = (%[[VAL_9]]) to (%[[VAL_10]]) inclusive step (%[[VAL_11]]) {82! CHECK:                 %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_7]] {uniq_name = "_QFreduction_max_realEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)83! CHECK:                 %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_12]] {uniq_name = "_QFreduction_max_realEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)84! CHECK:                 hlfir.assign %[[VAL_13]] to %[[VAL_8]]#0 : i32, !fir.ref<i32>85! CHECK:                 %[[VAL_15:.*]] = fir.load %[[VAL_8]]#0 : !fir.ref<i32>86! CHECK:                 %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> i6487! CHECK:                 %[[VAL_17:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_16]])  : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32>88! CHECK:                 %[[VAL_18:.*]] = fir.load %[[VAL_17]] : !fir.ref<f32>89! CHECK:                 %[[VAL_19:.*]] = fir.load %[[VAL_14]]#0 : !fir.ref<f32>90! CHECK:                 %[[VAL_20:.*]] = arith.cmpf ogt, %[[VAL_18]], %[[VAL_19]] fastmath<contract> : f3291! CHECK:                 %[[VAL_21:.*]] = arith.select %[[VAL_20]], %[[VAL_18]], %[[VAL_19]] : f3292! CHECK:                 hlfir.assign %[[VAL_21]] to %[[VAL_14]]#0 : f32, !fir.ref<f32>93! CHECK:                 omp.yield94! CHECK:             omp.terminator95! CHECK:           omp.parallel {96! CHECK:             %[[VAL_32:.*]] = arith.constant 1 : i3297! CHECK:             %[[VAL_33:.*]] = arith.constant 100 : i3298! CHECK:             %[[VAL_34:.*]] = arith.constant 1 : i3299! CHECK:             omp.wsloop private(@{{.*}} %{{.*}}#0 -> %[[VAL_30:.*]] : !fir.ref<i32>) reduction(byref @max_byref_f32 %[[VAL_4]]#0 -> %[[VAL_35:.*]] : !fir.ref<f32>) {100! CHECK-NEXT:          omp.loop_nest (%[[VAL_36:.*]]) : i32 = (%[[VAL_32]]) to (%[[VAL_33]]) inclusive step (%[[VAL_34]]) {101! CHECK:                 %[[VAL_31:.*]]:2 = hlfir.declare %[[VAL_30]] {uniq_name = "_QFreduction_max_realEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)102! CHECK:                 %[[VAL_37:.*]]:2 = hlfir.declare %[[VAL_35]] {uniq_name = "_QFreduction_max_realEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)103! CHECK:                 hlfir.assign %[[VAL_36]] to %[[VAL_31]]#0 : i32, !fir.ref<i32>104! CHECK:                 %[[VAL_38:.*]] = fir.load %[[VAL_31]]#0 : !fir.ref<i32>105! CHECK:                 %[[VAL_39:.*]] = fir.convert %[[VAL_38]] : (i32) -> i64106! CHECK:                 %[[VAL_40:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_39]])  : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32>107! CHECK:                 %[[VAL_41:.*]] = fir.load %[[VAL_40]] : !fir.ref<f32>108! CHECK:                 %[[VAL_42:.*]] = fir.load %[[VAL_37]]#0 : !fir.ref<f32>109! CHECK:                 %[[VAL_43:.*]] = arith.cmpf ogt, %[[VAL_41]], %[[VAL_42]] fastmath<contract> : f32110! CHECK:                 fir.if %[[VAL_43]] {111! CHECK:                   %[[VAL_44:.*]] = fir.load %[[VAL_31]]#0 : !fir.ref<i32>112! CHECK:                   %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (i32) -> i64113! CHECK:                   %[[VAL_46:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_45]])  : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32>114! CHECK:                   %[[VAL_47:.*]] = fir.load %[[VAL_46]] : !fir.ref<f32>115! CHECK:                   hlfir.assign %[[VAL_47]] to %[[VAL_37]]#0 : f32, !fir.ref<f32>116! CHECK:                 }117! CHECK:                 omp.yield118! CHECK:             omp.terminator119 120 121 122subroutine reduction_max_int(y)123  integer :: x, y(:)124  x = 0125  !$omp parallel126  !$omp do reduction(max:x)127  do i=1, 100128    x = max(x, y(i))129  end do130  !$omp end do131  !$omp end parallel132  print *, x133end subroutine134 135subroutine reduction_max_real(y)136  real :: x, y(:)137  x = 0.0138  !$omp parallel139  !$omp do reduction(max:x)140  do i=1, 100141    x = max(y(i), x)142  end do143  !$omp end do144  !$omp end parallel145  print *, x146 147  !$omp parallel148  !$omp do reduction(max:x)149  do i=1, 100150    if (y(i) .gt. x) x = y(i)151  end do152  !$omp end do153  !$omp end parallel154  print *, x155end subroutine156