103 lines · plain
1// RUN: fir-opt --array-value-copy %s | FileCheck --check-prefix=NOOPT %s2// RUN: fir-opt --array-value-copy="optimize-conflicts=true" %s | FileCheck --check-prefix=OPT %s3 4// Reproducer from SPEC CPU2017/527.cam4_r:5// module cam46// type, public :: pbuf_fld7// real*8, pointer, dimension(:,:,:,:,:) :: fld_ptr8// end type pbuf_fld9// contains10// subroutine test(pbuf, ncol, lchnk, time_index, kvh_idx)11// implicit none12// interface13// subroutine init(kvh)14// real*8, intent(out) :: kvh(4,27)15// end subroutine init16// end interface17// type(pbuf_fld), intent(inout), dimension(1000) :: pbuf18// real*8 :: kvh(4,27)19// integer kvh_idx, ncol, lchnk, time_index20// call init(kvh)21// pbuf(kvh_idx)%fld_ptr(1,1:ncol,1:27,lchnk,time_index) = kvh(:ncol,:)22// end subroutine test23// end module cam424 25// Verify that no memory is allocated for the temporary array,26// when compiling with optimizations:27// OPT-NOT: fir.allocmem28// NOOPT: fir.allocmem29 30module {31 func.func @_QMcam4Ptest(%arg0: !fir.ref<!fir.array<1000x!fir.type<_QMcam4Tpbuf_fld{fld_ptr:!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>}>>> {fir.bindc_name = "pbuf"}, %arg1: !fir.ref<i32> {fir.bindc_name = "ncol"}, %arg2: !fir.ref<i32> {fir.bindc_name = "lchnk"}, %arg3: !fir.ref<i32> {fir.bindc_name = "time_index"}, %arg4: !fir.ref<i32> {fir.bindc_name = "kvh_idx"}) {32 %c4 = arith.constant 4 : index33 %c27 = arith.constant 27 : index34 %0 = fir.alloca !fir.array<4x27xf64> {bindc_name = "kvh", uniq_name = "_QMcam4FtestEkvh"}35 fir.call @_QPinit(%0) fastmath<contract> : (!fir.ref<!fir.array<4x27xf64>>) -> ()36 %1 = fir.load %arg4 : !fir.ref<i32>37 %2 = fir.convert %1 : (i32) -> i6438 %c1_i64 = arith.constant 1 : i6439 %3 = arith.subi %2, %c1_i64 : i6440 %4 = fir.coordinate_of %arg0, %3 : (!fir.ref<!fir.array<1000x!fir.type<_QMcam4Tpbuf_fld{fld_ptr:!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>}>>>, i64) -> !fir.ref<!fir.type<_QMcam4Tpbuf_fld{fld_ptr:!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>}>>41 %5 = fir.field_index fld_ptr, !fir.type<_QMcam4Tpbuf_fld{fld_ptr:!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>}>42 %6 = fir.coordinate_of %4, %5 : (!fir.ref<!fir.type<_QMcam4Tpbuf_fld{fld_ptr:!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>>43 %7 = fir.load %6 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>>44 %c0 = arith.constant 0 : index45 %8:3 = fir.box_dims %7, %c0 : (!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>, index) -> (index, index, index)46 %c1 = arith.constant 1 : index47 %9:3 = fir.box_dims %7, %c1 : (!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>, index) -> (index, index, index)48 %c2 = arith.constant 2 : index49 %10:3 = fir.box_dims %7, %c2 : (!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>, index) -> (index, index, index)50 %c3 = arith.constant 3 : index51 %11:3 = fir.box_dims %7, %c3 : (!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>, index) -> (index, index, index)52 %12:3 = fir.box_dims %7, %c4 : (!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>, index) -> (index, index, index)53 %13 = fir.undefined index54 %14 = fir.convert %c1_i64 : (i64) -> index55 %15 = arith.subi %14, %8#0 : index56 %16 = fir.load %arg1 : !fir.ref<i32>57 %17 = fir.convert %16 : (i32) -> i6458 %18 = fir.convert %17 : (i64) -> index59 %19 = arith.subi %18, %14 : index60 %20 = arith.addi %19, %14 : index61 %21 = arith.divsi %20, %14 : index62 %22 = arith.cmpi sgt, %21, %c0 : index63 %23 = arith.select %22, %21, %c0 : index64 %c27_i64 = arith.constant 27 : i6465 %24 = fir.convert %c27_i64 : (i64) -> index66 %25 = arith.subi %24, %14 : index67 %26 = arith.addi %25, %14 : index68 %27 = arith.divsi %26, %14 : index69 %28 = arith.cmpi sgt, %27, %c0 : index70 %29 = arith.select %28, %27, %c0 : index71 %30 = fir.load %arg2 : !fir.ref<i32>72 %31 = fir.convert %30 : (i32) -> i6473 %32 = fir.convert %31 : (i64) -> index74 %33 = arith.subi %32, %11#0 : index75 %34 = fir.load %arg3 : !fir.ref<i32>76 %35 = fir.convert %34 : (i32) -> i6477 %36 = fir.convert %35 : (i64) -> index78 %37 = arith.subi %36, %12#0 : index79 %38 = fir.shift %8#0, %9#0, %10#0, %11#0, %12#0 : (index, index, index, index, index) -> !fir.shift<5>80 %39 = fir.slice %c1_i64, %13, %13, %14, %18, %14, %14, %24, %14, %31, %13, %13, %35, %13, %13 : (i64, index, index, index, index, index, index, index, index, i64, index, index, i64, index, index) -> !fir.slice<5>81 %40 = fir.array_load %7(%38) [%39] : (!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>, !fir.shift<5>, !fir.slice<5>) -> !fir.array<?x?x?x?x?xf64>82 %41 = arith.addi %c1, %c27 : index83 %42 = arith.subi %41, %c1 : index84 %43 = fir.shape %c4, %c27 : (index, index) -> !fir.shape<2>85 %44 = fir.slice %c1, %18, %14, %c1, %42, %14 : (index, index, index, index, index, index) -> !fir.slice<2>86 %45 = fir.array_load %0(%43) [%44] : (!fir.ref<!fir.array<4x27xf64>>, !fir.shape<2>, !fir.slice<2>) -> !fir.array<4x27xf64>87 %46 = arith.subi %23, %c1 : index88 %47 = arith.subi %29, %c1 : index89 %48 = fir.do_loop %arg5 = %c0 to %47 step %c1 unordered iter_args(%arg6 = %40) -> (!fir.array<?x?x?x?x?xf64>) {90 %49 = fir.do_loop %arg7 = %c0 to %46 step %c1 unordered iter_args(%arg8 = %arg6) -> (!fir.array<?x?x?x?x?xf64>) {91 %50 = fir.array_fetch %45, %arg7, %arg5 : (!fir.array<4x27xf64>, index, index) -> f6492 %51 = fir.array_update %arg8, %50, %15, %arg7, %arg5, %33, %37 : (!fir.array<?x?x?x?x?xf64>, f64, index, index, index, index, index) -> !fir.array<?x?x?x?x?xf64>93 fir.result %51 : !fir.array<?x?x?x?x?xf64>94 }95 fir.result %49 : !fir.array<?x?x?x?x?xf64>96 }97 fir.array_merge_store %40, %48 to %7[%39] : !fir.array<?x?x?x?x?xf64>, !fir.array<?x?x?x?x?xf64>, !fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>, !fir.slice<5>98 return99 }100 func.func private @_QPinit(!fir.ref<!fir.array<4x27xf64>>)101 fir.type_info @_QMcam4Tpbuf_fld : !fir.type<_QMcam4Tpbuf_fld{fld_ptr:!fir.box<!fir.ptr<!fir.array<?x?x?x?x?xf64>>>}>102}103