| 1 |
// RUN: fir-opt --array-value-copy %s | FileCheck --check-prefix=NOOPT %s |
| 2 |
// RUN: fir-opt --array-value-copy="optimize-conflicts=true" %s | FileCheck --check-prefix=OPT %s |
| 3 |
|
| 4 |
// Reproducer from SPEC CPU2017/527.cam4_r: |
| 5 |
// module cam4 |
| 6 |
// type, public :: pbuf_fld |
| 7 |
// real*8, pointer, dimension(:,:,:,:,:) :: fld_ptr |
| 8 |
// end type pbuf_fld |
| 9 |
// contains |
| 10 |
// subroutine test(pbuf, ncol, lchnk, time_index, kvh_idx) |
| 11 |
// implicit none |
| 12 |
// interface |
| 13 |
// subroutine init(kvh) |
| 14 |
// real*8, intent(out) :: kvh(4,27) |
| 15 |
// end subroutine init |
| 16 |
// end interface |
| 17 |
// type(pbuf_fld), intent(inout), dimension(1000) :: pbuf |
| 18 |
// real*8 :: kvh(4,27) |
| 19 |
// integer kvh_idx, ncol, lchnk, time_index |
| 20 |
// call init(kvh) |
| 21 |
// pbuf(kvh_idx)%fld_ptr(1,1:ncol,1:27,lchnk,time_index) = kvh(:ncol,:) |
| 22 |
// end subroutine test |
| 23 |
// end module cam4 |
| 24 |
|
| 25 |
// Verify that no memory is allocated for the temporary array, |
| 26 |
// when compiling with optimizations: |
| 27 |
// OPT-NOT: fir.allocmem |
| 28 |
// NOOPT: fir.allocmem |
| 29 |
|
| 30 |
module { |
| 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 : index |
| 33 |
%c27 = arith.constant 27 : index |
| 34 |
%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) -> i64 |
| 38 |
%c1_i64 = arith.constant 1 : i64 |
| 39 |
%3 = arith.subi %2, %c1_i64 : i64 |
| 40 |
%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 : index |
| 45 |
%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 : index |
| 47 |
%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 : index |
| 49 |
%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 : index |
| 51 |
%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 index |
| 54 |
%14 = fir.convert %c1_i64 : (i64) -> index |
| 55 |
%15 = arith.subi %14, %8#0 : index |
| 56 |
%16 = fir.load %arg1 : !fir.ref<i32> |
| 57 |
%17 = fir.convert %16 : (i32) -> i64 |
| 58 |
%18 = fir.convert %17 : (i64) -> index |
| 59 |
%19 = arith.subi %18, %14 : index |
| 60 |
%20 = arith.addi %19, %14 : index |
| 61 |
%21 = arith.divsi %20, %14 : index |
| 62 |
%22 = arith.cmpi sgt, %21, %c0 : index |
| 63 |
%23 = arith.select %22, %21, %c0 : index |
| 64 |
%c27_i64 = arith.constant 27 : i64 |
| 65 |
%24 = fir.convert %c27_i64 : (i64) -> index |
| 66 |
%25 = arith.subi %24, %14 : index |
| 67 |
%26 = arith.addi %25, %14 : index |
| 68 |
%27 = arith.divsi %26, %14 : index |
| 69 |
%28 = arith.cmpi sgt, %27, %c0 : index |
| 70 |
%29 = arith.select %28, %27, %c0 : index |
| 71 |
%30 = fir.load %arg2 : !fir.ref<i32> |
| 72 |
%31 = fir.convert %30 : (i32) -> i64 |
| 73 |
%32 = fir.convert %31 : (i64) -> index |
| 74 |
%33 = arith.subi %32, %11#0 : index |
| 75 |
%34 = fir.load %arg3 : !fir.ref<i32> |
| 76 |
%35 = fir.convert %34 : (i32) -> i64 |
| 77 |
%36 = fir.convert %35 : (i64) -> index |
| 78 |
%37 = arith.subi %36, %12#0 : index |
| 79 |
%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 : index |
| 83 |
%42 = arith.subi %41, %c1 : index |
| 84 |
%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 : index |
| 88 |
%47 = arith.subi %29, %c1 : index |
| 89 |
%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) -> f64 |
| 92 |
%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 |
return |
| 99 |
} |
| 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 |
} |