882 lines · plain
1! RUN: bbc -emit-hlfir %s -o - | FileCheck %s --check-prefixes=CHECK%if target=x86_64{{.*}} %{,CHECK-KIND10%}%if flang-supports-f128-math %{,CHECK-KIND16%}2 3module reduce_mod4 5type :: t16 integer :: a7end type8 9 abstract interface10 pure function red_int1_interface(a, b)11 integer(1), intent(in) :: a, b12 integer(1) :: red_int1_interface13 end function14 pure function red_int1_interface_value(a, b)15 integer(1), value, intent(in) :: a, b16 integer(1) :: red_int1_interface_value17 end function18 end interface19 20 integer, parameter :: kind10 = merge(10, 4, selected_real_kind(p=18).eq.10)21 integer, parameter :: kind16 = merge(16, 4, selected_real_kind(p=33).eq.16)22 23 24contains25 26pure function red_int1(a,b)27 integer(1), intent(in) :: a, b28 integer(1) :: red_int129 red_int1 = a + b30end function31 32pure function red_int1_value(a,b)33 integer(1), value, intent(in) :: a, b34 integer(1) :: red_int1_value35 red_int1_value = a + b36end function37 38subroutine integer1(a, id, d1, d2)39 integer(1), intent(in) :: a(:)40 integer(1) :: res, id41 procedure(red_int1_interface), pointer :: fptr42 procedure(red_int1_interface_value), pointer :: fptr_value43 procedure(red_int1_interface) :: d144 procedure(red_int1_interface_value) :: d245 46 res = reduce(a, red_int1)47 48 res = reduce(a, red_int1, identity=id)49 50 res = reduce(a, red_int1, identity=id, ordered = .true.)51 52 res = reduce(a, red_int1, [.true., .true., .false.])53 54 res = reduce(a, red_int1_value)55 56 fptr => red_int157 res = reduce(a, fptr)58 59 fptr_value => red_int1_value60 res = reduce(a, fptr_value)61 62 !res = reduce(a, d1)63 !res = reduce(a, d2)64end subroutine65 66! CHECK-LABEL: func.func @_QMreduce_modPinteger1(67! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xi8>> {fir.bindc_name = "a"}, %[[ARG1:.*]]: !fir.ref<i8> {fir.bindc_name = "id"}68! CHECK: %[[A:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{.*}} {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QMreduce_modFinteger1Ea"} : (!fir.box<!fir.array<?xi8>>, !fir.dscope) -> (!fir.box<!fir.array<?xi8>>, !fir.box<!fir.array<?xi8>>)69! CHECK: %[[ID:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{.*}} {uniq_name = "_QMreduce_modFinteger1Eid"} : (!fir.ref<i8>, !fir.dscope) -> (!fir.ref<i8>, !fir.ref<i8>)70! CHECK: %[[ALLOC_RES:.*]] = fir.alloca i8 {bindc_name = "res", uniq_name = "_QMreduce_modFinteger1Eres"}71! CHECK: %[[RES:.*]]:2 = hlfir.declare %[[ALLOC_RES]] {uniq_name = "_QMreduce_modFinteger1Eres"} : (!fir.ref<i8>) -> (!fir.ref<i8>, !fir.ref<i8>)72! CHECK: %[[ADDR_OP:.*]] = fir.address_of(@_QMreduce_modPred_int1) : (!fir.ref<i8>, !fir.ref<i8>) -> i873! CHECK: %[[BOX_PROC:.*]] = fir.emboxproc %[[ADDR_OP]] : ((!fir.ref<i8>, !fir.ref<i8>) -> i8) -> !fir.boxproc<() -> ()>74! CHECK: %[[MASK:.*]] = fir.absent !fir.box<i1>75! CHECK: %[[IDENTITY:.*]] = fir.absent !fir.ref<i8>76! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[BOX_PROC]] : (!fir.boxproc<() -> ()>) -> ((!fir.ref<i8>, !fir.ref<i8>) -> !fir.ref<i8>)77! CHECK: %[[A_NONE:.*]] = fir.convert %[[A]]#1 : (!fir.box<!fir.array<?xi8>>) -> !fir.box<none>78! CHECK: %[[MASK_NONE:.*]] = fir.convert %[[MASK]] : (!fir.box<i1>) -> !fir.box<none>79! CHECK: %[[REDUCE_RES:.*]] = fir.call @_FortranAReduceInteger1Ref(%[[A_NONE]], %[[BOX_ADDR]], %{{.*}}, %{{.*}}, %c1{{.*}}, %[[MASK_NONE]], %[[IDENTITY]], %false) fastmath<contract> : (!fir.box<none>, (!fir.ref<i8>, !fir.ref<i8>) -> !fir.ref<i8>, !fir.ref<i8>, i32, i32, !fir.box<none>, !fir.ref<i8>, i1) -> i880! CHECK: hlfir.assign %[[REDUCE_RES]] to %[[RES]]#0 : i8, !fir.ref<i8>81! CHECK: %[[ADDR_OP:.*]] = fir.address_of(@_QMreduce_modPred_int1) : (!fir.ref<i8>, !fir.ref<i8>) -> i882! CHECK: %[[BOX_PROC:.*]] = fir.emboxproc %[[ADDR_OP]] : ((!fir.ref<i8>, !fir.ref<i8>) -> i8) -> !fir.boxproc<() -> ()>83! CHECK: %[[MASK:.*]] = fir.absent !fir.box<i1>84! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[BOX_PROC]] : (!fir.boxproc<() -> ()>) -> ((!fir.ref<i8>, !fir.ref<i8>) -> !fir.ref<i8>)85! CHECK: %[[A_NONE:.*]] = fir.convert %[[A]]#1 : (!fir.box<!fir.array<?xi8>>) -> !fir.box<none>86! CHECK: %[[MASK_NONE:.*]] = fir.convert %[[MASK]] : (!fir.box<i1>) -> !fir.box<none>87! CHECK: %{{.*}} = fir.call @_FortranAReduceInteger1Ref(%[[A_NONE]], %[[BOX_ADDR]], %{{.*}}, %{{.*}}, %c1{{.*}}, %[[MASK_NONE]], %[[ID]]#0, %false{{.*}}) fastmath<contract> : (!fir.box<none>, (!fir.ref<i8>, !fir.ref<i8>) -> !fir.ref<i8>, !fir.ref<i8>, i32, i32, !fir.box<none>, !fir.ref<i8>, i1) -> i888! CHECK: fir.call @_FortranAReduceInteger1Ref(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}#0, %true)89! CHECK: %[[MASK:.*]]:2 = hlfir.declare %{{.*}}(%{{.*}}) {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QQro.3xl4.0"} : (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.shape<1>) -> (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.ref<!fir.array<3x!fir.logical<4>>>)90! CHECK: %[[SHAPE_C3:.*]] = fir.shape %c3{{.*}} : (index) -> !fir.shape<1>91! CHECK: %[[BOXED_MASK:.*]] = fir.embox %[[MASK]]#0(%[[SHAPE_C3]]) : (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.shape<1>) -> !fir.box<!fir.array<3x!fir.logical<4>>>92! CHECK: %[[CONV_MASK:.*]] = fir.convert %[[BOXED_MASK]] : (!fir.box<!fir.array<3x!fir.logical<4>>>) -> !fir.box<none>93! CHECK: fir.call @_FortranAReduceInteger1Ref(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[CONV_MASK]], %{{.*}}, %false{{.*}})94! CHECK: fir.call @_FortranAReduceInteger1Value95! CHECK: fir.call @_FortranAReduceInteger1Ref96! CHECK: fir.call @_FortranAReduceInteger1Value97! TODO fir.call @_FortranAReduceInteger1Ref98! TODO fir.call @_FortranAReduceInteger1Value99 100pure function red_int2(a,b)101 integer(2), intent(in) :: a, b102 integer(2) :: red_int2103 red_int2 = a + b104end function105 106pure function red_int2_value(a,b)107 integer(2), value, intent(in) :: a, b108 integer(2) :: red_int2_value109 red_int2_value = a + b110end function111 112subroutine integer2(a)113 integer(2), intent(in) :: a(:)114 integer(2) :: res115 res = reduce(a, red_int2)116 res = reduce(a, red_int2_value)117end subroutine118 119! CHECK: fir.call @_FortranAReduceInteger2Ref120! CHECK: fir.call @_FortranAReduceInteger2Value121 122pure function red_int4(a,b)123 integer(4), intent(in) :: a, b124 integer(4) :: red_int4125 red_int4 = a + b126end function127 128pure function red_int4_value(a,b)129 integer(4), value, intent(in) :: a, b130 integer(4) :: red_int4_value131 red_int4_value = a + b132end function133 134subroutine integer4(a)135 integer(4), intent(in) :: a(:)136 integer(4) :: res137 res = reduce(a, red_int4)138 res = reduce(a, red_int4_value)139end subroutine140 141! CHECK: fir.call @_FortranAReduceInteger4Ref142! CHECK: fir.call @_FortranAReduceInteger4Value143 144pure function red_int8(a,b)145 integer(8), intent(in) :: a, b146 integer(8) :: red_int8147 red_int8 = a + b148end function149 150pure function red_int8_value(a,b)151 integer(8), value, intent(in) :: a, b152 integer(8) :: red_int8_value153 red_int8_value = a + b154end function155 156subroutine integer8(a)157 integer(8), intent(in) :: a(:)158 integer(8) :: res159 res = reduce(a, red_int8)160 res = reduce(a, red_int8_value)161end subroutine162 163! CHECK: fir.call @_FortranAReduceInteger8Ref164! CHECK: fir.call @_FortranAReduceInteger8Value165 166pure function red_int16(a,b)167 integer(16), intent(in) :: a, b168 integer(16) :: red_int16169 red_int16 = a + b170end function171 172pure function red_int16_value(a,b)173 integer(16), value, intent(in) :: a, b174 integer(16) :: red_int16_value175 red_int16_value = a + b176end function177 178subroutine integer16(a)179 integer(16), intent(in) :: a(:)180 integer(16) :: res181 res = reduce(a, red_int16)182 res = reduce(a, red_int16_value)183end subroutine184 185! CHECK: fir.call @_FortranAReduceInteger16Ref186! CHECK: fir.call @_FortranAReduceInteger16Value187 188pure function red_real2(a,b)189 real(2), intent(in) :: a, b190 real(2) :: red_real2191 red_real2 = a + b192end function193 194pure function red_real2_value(a,b)195 real(2), value, intent(in) :: a, b196 real(2) :: red_real2_value197 red_real2_value = a + b198end function199 200subroutine real2(a)201 real(2), intent(in) :: a(:)202 real(2) :: res203 res = reduce(a, red_real2)204 res = reduce(a, red_real2_value)205end subroutine206 207! CHECK: fir.call @_FortranAReduceReal2Ref208! CHECK: fir.call @_FortranAReduceReal2Value209 210pure function red_real3(a,b)211 real(3), intent(in) :: a, b212 real(3) :: red_real3213 red_real3 = a + b214end function215 216pure function red_real3_value(a,b)217 real(3), value, intent(in) :: a, b218 real(3) :: red_real3_value219 red_real3_value = a + b220end function221 222subroutine real3(a)223 real(3), intent(in) :: a(:)224 real(3) :: res225 res = reduce(a, red_real3)226 res = reduce(a, red_real3_value)227end subroutine228 229! CHECK: fir.call @_FortranAReduceReal3Ref230! CHECK: fir.call @_FortranAReduceReal3Value231 232pure function red_real4(a,b)233 real(4), intent(in) :: a, b234 real(4) :: red_real4235 red_real4 = a + b236end function237 238pure function red_real4_value(a,b)239 real(4), value, intent(in) :: a, b240 real(4) :: red_real4_value241 red_real4_value = a + b242end function243 244subroutine real4(a)245 real(4), intent(in) :: a(:)246 real(4) :: res247 res = reduce(a, red_real4)248 res = reduce(a, red_real4_value)249end subroutine250 251! CHECK: fir.call @_FortranAReduceReal4Ref252! CHECK: fir.call @_FortranAReduceReal4Value253 254pure function red_real8(a,b)255 real(8), intent(in) :: a, b256 real(8) :: red_real8257 red_real8 = a + b258end function259 260pure function red_real8_value(a,b)261 real(8), value, intent(in) :: a, b262 real(8) :: red_real8_value263 red_real8_value = a + b264end function265 266subroutine real8(a)267 real(8), intent(in) :: a(:)268 real(8) :: res269 res = reduce(a, red_real8)270 res = reduce(a, red_real8_value)271end subroutine272 273! CHECK: fir.call @_FortranAReduceReal8Ref274! CHECK: fir.call @_FortranAReduceReal8Value275 276pure function red_real10(a,b)277 real(kind10), intent(in) :: a, b278 real(kind10) :: red_real10279 red_real10 = a + b280end function281 282pure function red_real10_value(a,b)283 real(kind10), value, intent(in) :: a, b284 real(kind10) :: red_real10_value285 red_real10_value = a + b286end function287 288subroutine real10(a)289 real(kind10), intent(in) :: a(:)290 real(kind10) :: res291 res = reduce(a, red_real10)292 res = reduce(a, red_real10_value)293end subroutine294 295! CHECK-KIND10: fir.call @_FortranAReduceReal10Ref296! CHECK-KIND10: fir.call @_FortranAReduceReal10Value297 298pure function red_real16(a,b)299 real(kind16), intent(in) :: a, b300 real(kind16) :: red_real16301 red_real16 = a + b302end function303 304pure function red_real16_value(a,b)305 real(kind16), value, intent(in) :: a, b306 real(kind16) :: red_real16_value307 red_real16_value = a + b308end function309 310subroutine real16(a)311 real(kind16), intent(in) :: a(:)312 real(kind16) :: res313 res = reduce(a, red_real16)314 res = reduce(a, red_real16_value)315end subroutine316 317! CHECK-KIND16: fir.call @_FortranAReduceReal16Ref318! CHECK-KIND16: fir.call @_FortranAReduceReal16Value319 320pure function red_complex2(a,b)321 complex(2), intent(in) :: a, b322 complex(2) :: red_complex2323 red_complex2 = a + b324end function325 326pure function red_complex2_value(a,b)327 complex(2), value, intent(in) :: a, b328 complex(2) :: red_complex2_value329 red_complex2_value = a + b330end function331 332subroutine complex2(a)333 complex(2), intent(in) :: a(:)334 complex(2) :: res335 res = reduce(a, red_complex2)336 res = reduce(a, red_complex2_value)337end subroutine338 339! CHECK: fir.call @_FortranACppReduceComplex2Ref340! CHECK: fir.call @_FortranACppReduceComplex2Value341 342pure function red_complex3(a,b)343 complex(3), intent(in) :: a, b344 complex(3) :: red_complex3345 red_complex3 = a + b346end function347 348pure function red_complex3_value(a,b)349 complex(3), value, intent(in) :: a, b350 complex(3) :: red_complex3_value351 red_complex3_value = a + b352end function353 354subroutine complex3(a)355 complex(3), intent(in) :: a(:)356 complex(3) :: res357 res = reduce(a, red_complex3)358 res = reduce(a, red_complex3_value)359end subroutine360 361! CHECK: fir.call @_FortranACppReduceComplex3Ref362! CHECK: fir.call @_FortranACppReduceComplex3Value363 364pure function red_complex4(a,b)365 complex(4), intent(in) :: a, b366 complex(4) :: red_complex4367 red_complex4 = a + b368end function369 370pure function red_complex4_value(a,b)371 complex(4), value, intent(in) :: a, b372 complex(4) :: red_complex4_value373 red_complex4_value = a + b374end function375 376subroutine complex4(a)377 complex(4), intent(in) :: a(:)378 complex(4) :: res379 res = reduce(a, red_complex4)380 res = reduce(a, red_complex4_value)381end subroutine382 383! CHECK: fir.call @_FortranACppReduceComplex4Ref384! CHECK: fir.call @_FortranACppReduceComplex4Value385 386pure function red_complex8(a,b)387 complex(8), intent(in) :: a, b388 complex(8) :: red_complex8389 red_complex8 = a + b390end function391 392pure function red_complex8_value(a,b)393 complex(8), value, intent(in) :: a, b394 complex(8) :: red_complex8_value395 red_complex8_value = a + b396end function397 398subroutine complex8(a)399 complex(8), intent(in) :: a(:)400 complex(8) :: res401 res = reduce(a, red_complex8)402 res = reduce(a, red_complex8_value)403end subroutine404 405! CHECK: fir.call @_FortranACppReduceComplex8Ref406! CHECK: fir.call @_FortranACppReduceComplex8Value407 408pure function red_complex10(a,b)409 complex(kind10), intent(in) :: a, b410 complex(kind10) :: red_complex10411 red_complex10 = a + b412end function413 414pure function red_complex10_value(a,b)415 complex(kind10), value, intent(in) :: a, b416 complex(kind10) :: red_complex10_value417 red_complex10_value = a + b418end function419 420subroutine complex10(a)421 complex(kind10), intent(in) :: a(:)422 complex(kind10) :: res423 res = reduce(a, red_complex10)424 res = reduce(a, red_complex10_value)425end subroutine426 427! CHECK-KIND10: fir.call @_FortranACppReduceComplex10Ref428! CHECK-KIND10: fir.call @_FortranACppReduceComplex10Value429 430pure function red_complex16(a,b)431 complex(kind16), intent(in) :: a, b432 complex(kind16) :: red_complex16433 red_complex16 = a + b434end function435 436pure function red_complex16_value(a,b)437 complex(kind16), value, intent(in) :: a, b438 complex(kind16) :: red_complex16_value439 red_complex16_value = a + b440end function441 442subroutine complex16(a)443 complex(kind16), intent(in) :: a(:)444 complex(kind16) :: res445 res = reduce(a, red_complex16)446 res = reduce(a, red_complex16_value)447end subroutine448 449! CHECK-KIND16: fir.call @_FortranACppReduceComplex16Ref450! CHECK-KIND16: fir.call @_FortranACppReduceComplex16Value451 452pure function red_log1(a,b)453 logical(1), intent(in) :: a, b454 logical(1) :: red_log1455 red_log1 = a .and. b456end function457 458pure function red_log1_value(a,b)459 logical(1), value, intent(in) :: a, b460 logical(1) :: red_log1_value461 red_log1_value = a .and. b462end function463 464subroutine log1(a)465 logical(1), intent(in) :: a(:)466 logical(1) :: res467 res = reduce(a, red_log1)468 res = reduce(a, red_log1_value)469end subroutine470 471! CHECK: fir.call @_FortranAReduceLogical1Ref472! CHECK: fir.call @_FortranAReduceLogical1Value473 474pure function red_log2(a,b)475 logical(2), intent(in) :: a, b476 logical(2) :: red_log2477 red_log2 = a .and. b478end function479 480pure function red_log2_value(a,b)481 logical(2), value, intent(in) :: a, b482 logical(2) :: red_log2_value483 red_log2_value = a .and. b484end function485 486subroutine log2(a)487 logical(2), intent(in) :: a(:)488 logical(2) :: res489 res = reduce(a, red_log2)490 res = reduce(a, red_log2_value)491end subroutine492 493! CHECK: fir.call @_FortranAReduceLogical2Ref494! CHECK: fir.call @_FortranAReduceLogical2Value495 496pure function red_log4(a,b)497 logical(4), intent(in) :: a, b498 logical(4) :: red_log4499 red_log4 = a .and. b500end function501 502pure function red_log4_value(a,b)503 logical(4), value, intent(in) :: a, b504 logical(4) :: red_log4_value505 red_log4_value = a .and. b506end function507 508subroutine log4(a)509 logical(4), intent(in) :: a(:)510 logical(4) :: res511 res = reduce(a, red_log4)512 res = reduce(a, red_log4_value)513end subroutine514 515! CHECK: fir.call @_FortranAReduceLogical4Ref516! CHECK: fir.call @_FortranAReduceLogical4Value517 518pure function red_log8(a,b)519 logical(8), intent(in) :: a, b520 logical(8) :: red_log8521 red_log8 = a .and. b522end function523 524pure function red_log8_value(a,b)525 logical(8), value, intent(in) :: a, b526 logical(8) :: red_log8_value527 red_log8_value = a .and. b528end function529 530subroutine log8(a)531 logical(8), intent(in) :: a(:)532 logical(8) :: res533 res = reduce(a, red_log8)534 res = reduce(a, red_log8_value)535end subroutine536 537! CHECK: fir.call @_FortranAReduceLogical8Ref538! CHECK: fir.call @_FortranAReduceLogical8Value539 540pure function red_char1(a,b)541 character(1), intent(in) :: a, b542 character(1) :: red_char1543 red_char1 = a // b544end function545 546subroutine char1(a)547 character(1), intent(in) :: a(:)548 character(1) :: res549 res = reduce(a, red_char1)550end subroutine551 552! CHECK: %[[CHRTMP:.*]] = fir.alloca !fir.char<1> {bindc_name = ".chrtmp"}553! CHECK: %[[RESULT:.*]] = fir.convert %[[CHRTMP]] : (!fir.ref<!fir.char<1>>) -> !fir.ref<i8>554! CHECK: fir.call @_FortranAReduceChar1(%[[RESULT]], {{.*}})555 556pure function red_char2(a,b)557 character(kind=2, len=10), intent(in) :: a, b558 character(kind=2, len=10) :: red_char2559 red_char2 = a // b560end function561 562subroutine char2(a)563 character(kind=2, len=10), intent(in) :: a(:)564 character(kind=2, len=10) :: res565 res = reduce(a, red_char2)566end subroutine567 568! CHECK: %[[CHRTMP:.*]] = fir.alloca !fir.char<2,10> {bindc_name = ".chrtmp"}569! CHECK: %[[RESULT:.*]] = fir.convert %[[CHRTMP]] : (!fir.ref<!fir.char<2,10>>) -> !fir.ref<i16>570! CHECK: fir.call @_FortranAReduceChar2(%[[RESULT]], {{.*}})571 572pure function red_char4(a,b)573 character(kind=4), intent(in) :: a, b574 character(kind=4) :: red_char4575 red_char4 = a // b576end function577 578subroutine char4(a)579 character(kind=4), intent(in) :: a(:)580 character(kind=4) :: res581 res = reduce(a, red_char4)582end subroutine583 584! CHECK: fir.call @_FortranAReduceChar4585 586pure function red_type(a,b)587 type(t1), intent(in) :: a, b588 type(t1) :: red_type589 red_type%a = a%a + b%a590end function591 592subroutine testtype(a)593 type(t1), intent(in) :: a(:)594 type(t1) :: res595 res = reduce(a, red_type)596end subroutine597 598! CHECK: fir.call @_FortranAReduceDerivedType599 600subroutine integer1dim(a, id)601 integer(1), intent(in) :: a(:,:)602 integer(1), allocatable :: res(:)603 604 res = reduce(a, red_int1, 2)605 res = reduce(a, red_int1_value, 2)606end subroutine607 608! CHECK: fir.call @_FortranAReduceInteger1DimRef609! CHECK: fir.call @_FortranAReduceInteger1DimValue610 611subroutine integer2dim(a, id)612 integer(2), intent(in) :: a(:,:)613 integer(2), allocatable :: res(:)614 615 res = reduce(a, red_int2, 2)616 res = reduce(a, red_int2_value, 2)617end subroutine618 619! CHECK: fir.call @_FortranAReduceInteger2DimRef620! CHECK: fir.call @_FortranAReduceInteger2DimValue621 622subroutine integer4dim(a, id)623 integer(4), intent(in) :: a(:,:)624 integer(4), allocatable :: res(:)625 626 res = reduce(a, red_int4, 2)627 res = reduce(a, red_int4_value, 2)628end subroutine629 630! CHECK: fir.call @_FortranAReduceInteger4DimRef631! CHECK: fir.call @_FortranAReduceInteger4DimValue632 633subroutine integer8dim(a, id)634 integer(8), intent(in) :: a(:,:)635 integer(8), allocatable :: res(:)636 637 res = reduce(a, red_int8, 2)638 res = reduce(a, red_int8_value, 2)639end subroutine640 641! CHECK: fir.call @_FortranAReduceInteger8DimRef642! CHECK: fir.call @_FortranAReduceInteger8DimValue643 644subroutine integer16dim(a, id)645 integer(16), intent(in) :: a(:,:)646 integer(16), allocatable :: res(:)647 648 res = reduce(a, red_int16, 2)649 res = reduce(a, red_int16_value, 2)650end subroutine651 652! CHECK: fir.call @_FortranAReduceInteger16DimRef653! CHECK: fir.call @_FortranAReduceInteger16DimValue654 655subroutine real2dim(a, id)656 real(2), intent(in) :: a(:,:)657 real(2), allocatable :: res(:)658 659 res = reduce(a, red_real2, 2)660 res = reduce(a, red_real2_value, 2)661end subroutine662 663! CHECK: fir.call @_FortranAReduceReal2DimRef664! CHECK: fir.call @_FortranAReduceReal2DimValue665 666subroutine real3dim(a, id)667 real(3), intent(in) :: a(:,:)668 real(3), allocatable :: res(:)669 670 res = reduce(a, red_real3, 2)671 res = reduce(a, red_real3_value, 2)672end subroutine673 674! CHECK: fir.call @_FortranAReduceReal3DimRef675! CHECK: fir.call @_FortranAReduceReal3DimValue676 677subroutine real4dim(a, id)678 real(4), intent(in) :: a(:,:)679 real(4), allocatable :: res(:)680 681 res = reduce(a, red_real4, 2)682 res = reduce(a, red_real4_value, 2)683end subroutine684 685! CHECK: fir.call @_FortranAReduceReal4DimRef686! CHECK: fir.call @_FortranAReduceReal4DimValue687 688subroutine real8dim(a, id)689 real(8), intent(in) :: a(:,:)690 real(8), allocatable :: res(:)691 692 res = reduce(a, red_real8, 2)693 res = reduce(a, red_real8_value, 2)694end subroutine695 696! CHECK: fir.call @_FortranAReduceReal8DimRef697! CHECK: fir.call @_FortranAReduceReal8DimValue698 699subroutine real10dim(a, id)700 real(kind10), intent(in) :: a(:,:)701 real(kind10), allocatable :: res(:)702 703 res = reduce(a, red_real10, 2)704 res = reduce(a, red_real10_value, 2)705end subroutine706 707! CHECK-KIND10: fir.call @_FortranAReduceReal10DimRef708! CHECK-KIND10: fir.call @_FortranAReduceReal10DimValue709 710subroutine real16dim(a, id)711 real(kind16), intent(in) :: a(:,:)712 real(kind16), allocatable :: res(:)713 714 res = reduce(a, red_real16, 2)715 res = reduce(a, red_real16_value, 2)716end subroutine717 718! CHECK-KIND16: fir.call @_FortranAReduceReal16DimRef719! CHECK-KIND16: fir.call @_FortranAReduceReal16DimValue720 721subroutine complex2dim(a, id)722 complex(2), intent(in) :: a(:,:)723 complex(2), allocatable :: res(:)724 725 res = reduce(a, red_complex2, 2)726 res = reduce(a, red_complex2_value, 2)727end subroutine728 729! CHECK: fir.call @_FortranACppReduceComplex2DimRef730! CHECK: fir.call @_FortranACppReduceComplex2DimValue731 732subroutine complex3dim(a, id)733 complex(3), intent(in) :: a(:,:)734 complex(3), allocatable :: res(:)735 736 res = reduce(a, red_complex3, 2)737 res = reduce(a, red_complex3_value, 2)738end subroutine739 740! CHECK: fir.call @_FortranACppReduceComplex3DimRef741! CHECK: fir.call @_FortranACppReduceComplex3DimValue742 743subroutine complex4dim(a, id)744 complex(4), intent(in) :: a(:,:)745 complex(4), allocatable :: res(:)746 747 res = reduce(a, red_complex4, 2)748 res = reduce(a, red_complex4_value, 2)749end subroutine750 751! CHECK: fir.call @_FortranACppReduceComplex4DimRef752! CHECK: fir.call @_FortranACppReduceComplex4DimValue753 754subroutine complex8dim(a, id)755 complex(8), intent(in) :: a(:,:)756 complex(8), allocatable :: res(:)757 758 res = reduce(a, red_complex8, 2)759 res = reduce(a, red_complex8_value, 2)760end subroutine761 762! CHECK: fir.call @_FortranACppReduceComplex8DimRef763! CHECK: fir.call @_FortranACppReduceComplex8DimValue764 765subroutine complex10dim(a, id)766 complex(kind10), intent(in) :: a(:,:)767 complex(kind10), allocatable :: res(:)768 769 res = reduce(a, red_complex10, 2)770 res = reduce(a, red_complex10_value, 2)771end subroutine772 773! CHECK-KIND10: fir.call @_FortranACppReduceComplex10DimRef774! CHECK-KIND10: fir.call @_FortranACppReduceComplex10DimValue775 776subroutine complex16dim(a, id)777 complex(kind16), intent(in) :: a(:,:)778 complex(kind16), allocatable :: res(:)779 780 res = reduce(a, red_complex16, 2)781 res = reduce(a, red_complex16_value, 2)782end subroutine783 784! CHECK-KIND16: fir.call @_FortranACppReduceComplex16DimRef785! CHECK-KIND16: fir.call @_FortranACppReduceComplex16DimValue786 787subroutine logical1dim(a, id)788 logical(1), intent(in) :: a(:,:)789 logical(1), allocatable :: res(:)790 791 res = reduce(a, red_log1, 2)792 res = reduce(a, red_log1_value, 2)793end subroutine794 795! CHECK: fir.call @_FortranAReduceLogical1DimRef796! CHECK: fir.call @_FortranAReduceLogical1DimValue797 798subroutine logical2dim(a, id)799 logical(2), intent(in) :: a(:,:)800 logical(2), allocatable :: res(:)801 802 res = reduce(a, red_log2, 2)803 res = reduce(a, red_log2_value, 2)804end subroutine805 806! CHECK: fir.call @_FortranAReduceLogical2DimRef807! CHECK: fir.call @_FortranAReduceLogical2DimValue808 809subroutine logical4dim(a, id)810 logical(4), intent(in) :: a(:,:)811 logical(4), allocatable :: res(:)812 813 res = reduce(a, red_log4, 2)814 res = reduce(a, red_log4_value, 2)815end subroutine816 817! CHECK: fir.call @_FortranAReduceLogical4DimRef818! CHECK: fir.call @_FortranAReduceLogical4DimValue819 820subroutine logical8dim(a, id)821 logical(8), intent(in) :: a(:,:)822 logical(8), allocatable :: res(:)823 824 res = reduce(a, red_log8, 2)825 res = reduce(a, red_log8_value, 2)826end subroutine827 828! CHECK: fir.call @_FortranAReduceLogical8DimRef829! CHECK: fir.call @_FortranAReduceLogical8DimValue830 831subroutine testtypeDim(a)832 type(t1), intent(in) :: a(:,:)833 type(t1), allocatable :: res(:)834 res = reduce(a, red_type, 2)835end subroutine836 837! CHECK: fir.call @_FortranAReduceDerivedTypeDim838 839subroutine char1dim(a)840 character(1), intent(in) :: a(:, :)841 character(1), allocatable :: res(:)842 res = reduce(a, red_char1, 2)843end subroutine844 845! CHECK: fir.call @_FortranAReduceCharacter1Dim846 847subroutine char2dim(a)848 character(kind=2, len=10), intent(in) :: a(:, :)849 character(kind=2, len=10), allocatable :: res(:)850 res = reduce(a, red_char2, 2)851end subroutine852 853! CHECK: fir.call @_FortranAReduceCharacter2Dim854 855subroutine char4dim(a)856 character(kind=4), intent(in) :: a(:, :)857 character(kind=4), allocatable :: res(:)858 res = reduce(a, red_char4, 2)859end subroutine860 861! CHECK: fir.call @_FortranAReduceCharacter4Dim862 863pure function red_char_dyn(a, b)864 character(*), intent(In) :: a, b865 character(max(len(a),len(b))) :: red_char_dyn866 red_char_dyn = max(a, b)867end function868 869subroutine charDyn()870 character(5) :: res871 character(:), allocatable :: a(:)872 allocate(character(10)::a(10))873 res = reduce(a, red_char_dyn)874end subroutine875 876! CHECK: %[[BOX_ELESIZE:.*]] = fir.box_elesize %{{.*}} : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> index877! CHECK: %[[CHRTMP:.*]] = fir.alloca !fir.char<1,?>(%[[BOX_ELESIZE]] : index) {bindc_name = ".chrtmp"}878! CHECK: %[[RESULT:.*]] = fir.convert %[[CHRTMP]] : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>879! CHECK: fir.call @_FortranAReduceChar1(%[[RESULT]], {{.*}})880 881end module882