// RUN: fir-opt %s --fir-to-memref --allow-unregistered-dialect | FileCheck %s // subroutine store_dynamic_1d(x) // real, dimension(:) :: x // x(2) = 3 // end subroutine store_dynamic_1d // CHECK-LABEL: func.func @store_dynamic_1d // CHECK: [[CONST2:%.+]] = arith.constant 2 : index // CHECK: [[CST:%.+]] = arith.constant 3.000000e+00 : f32 // CHECK: [[DUMMY:%[0-9]+]] = fir.dummy_scope : !fir.dscope // CHECK: [[DECLARE:%[0-9]+]] = fir.declare %arg0 dummy_scope [[DUMMY]] {uniq_name = "x"} : (!fir.box>, !fir.dscope) -> !fir.box> // CHECK: [[REBOX:%[0-9]+]] = fir.rebox [[DECLARE]] : (!fir.box>) -> !fir.box> // CHECK: [[BOXADDR:%[0-9]+]] = fir.box_addr [[REBOX]] : (!fir.box>) -> !fir.ref> // CHECK: [[CONVERT:%[0-9]+]] = fir.convert [[BOXADDR]] : (!fir.ref>) -> memref // CHECK: [[CONST1:%.+]] = arith.constant 1 : index // CHECK: [[SUB1:%[0-9]+]] = arith.subi [[CONST2]], [[CONST1]] : index // CHECK: [[MUL1:%[0-9]+]] = arith.muli [[SUB1]], [[CONST1]] : index // CHECK: [[SUB1A:%[0-9]+]] = arith.subi [[CONST1]], [[CONST1]] : index // CHECK: [[ADD1:%[0-9]+]] = arith.addi [[MUL1]], [[SUB1A]] : index // CHECK: [[ELSIZE:%[0-9]+]] = fir.box_elesize [[REBOX]] : (!fir.box>) -> index // CHECK: [[CONST0:%.+]] = arith.constant 0 : index // CHECK: [[DIMS:%[0-9]+]]:3 = fir.box_dims [[REBOX]], [[CONST0]] : (!fir.box>, index) -> (index, index, index) // CHECK: [[DIV:%[0-9]+]] = arith.divsi [[DIMS]]#2, [[ELSIZE]] : index // CHECK: [[CONST0_0:%.+]] = arith.constant 0 : index // CHECK: [[REINTERPRET:%.+]] = memref.reinterpret_cast [[CONVERT]] to offset: [[[CONST0_0]]], sizes: [[[DIMS]]#1], strides: [[[DIV]]] : memref to memref> // CHECK: memref.store [[CST]], [[REINTERPRET]][[[ADD1]]] : memref> func.func @store_dynamic_1d(%arg0: !fir.box> {fir.bindc_name = "x"}) { %c2 = arith.constant 2 : index %cst = arith.constant 3.000000e+00 : f32 %0 = fir.dummy_scope : !fir.dscope %1 = fir.declare %arg0 dummy_scope %0 {uniq_name = "x"} : (!fir.box>, !fir.dscope) -> !fir.box> %2 = fir.rebox %1 : (!fir.box>) -> !fir.box> %3 = fir.array_coor %2 %c2 : (!fir.box>, index) -> !fir.ref fir.store %cst to %3 : !fir.ref return } // subroutine store_dynamic_2d(x) // real, dimension(:, :) :: x // x(2, 2) = 3 // end subroutine store_dynamic_2d // CHECK-LABEL: func.func @store_dynamic_2d // CHECK: [[CONST2:%.+]] = arith.constant 2 : index // CHECK: [[CST:%.+]] = arith.constant 3.000000e+00 : f32 // CHECK: [[DUMMY:%[0-9]+]] = fir.dummy_scope : !fir.dscope // CHECK: [[DECLARE:%[0-9]+]] = fir.declare %arg0 dummy_scope [[DUMMY]] {uniq_name = "x"} : (!fir.box>, !fir.dscope) -> !fir.box> // CHECK: [[REBOX:%[0-9]+]] = fir.rebox [[DECLARE]] : (!fir.box>) -> !fir.box> // CHECK: [[BOXADDR:%[0-9]+]] = fir.box_addr [[REBOX]] : (!fir.box>) -> !fir.ref> // CHECK: [[CONVERT:%[0-9]+]] = fir.convert [[BOXADDR]] : (!fir.ref>) -> memref // CHECK: [[CONST1:%.+]] = arith.constant 1 : index // CHECK: [[SUB1:%[0-9]+]] = arith.subi [[CONST2]], [[CONST1]] : index // CHECK: [[MUL1:%[0-9]+]] = arith.muli [[SUB1]], [[CONST1]] : index // CHECK: [[SUB1A:%[0-9]+]] = arith.subi [[CONST1]], [[CONST1]] : index // CHECK: [[ADD1:%[0-9]+]] = arith.addi [[MUL1]], [[SUB1A]] : index // CHECK: [[SUB2:%[0-9]+]] = arith.subi [[CONST2]], [[CONST1]] : index // CHECK: [[MUL2:%[0-9]+]] = arith.muli [[SUB2]], [[CONST1]] : index // CHECK: [[SUB2A:%[0-9]+]] = arith.subi [[CONST1]], [[CONST1]] : index // CHECK: [[ADD2:%[0-9]+]] = arith.addi [[MUL2]], [[SUB2A]] : index // CHECK: [[ELSIZE:%[0-9]+]] = fir.box_elesize [[REBOX]] : (!fir.box>) -> index // CHECK: [[CONST1_1:%.+]] = arith.constant 1 : index // CHECK: [[DIMS1:%[0-9]+]]:3 = fir.box_dims [[REBOX]], [[CONST1_1]] : (!fir.box>, index) -> (index, index, index) // CHECK: [[DIV1:%[0-9]+]] = arith.divsi [[DIMS1]]#2, [[ELSIZE]] : index // CHECK: [[CONST0:%.+]] = arith.constant 0 : index // CHECK: [[DIMS0:%[0-9]+]]:3 = fir.box_dims [[REBOX]], [[CONST0]] : (!fir.box>, index) -> (index, index, index) // CHECK: [[DIV0:%[0-9]+]] = arith.divsi [[DIMS0]]#2, [[ELSIZE]] : index // CHECK: [[CONST0_2:%.+]] = arith.constant 0 : index // CHECK: [[REINTERPRET:%.+]] = memref.reinterpret_cast [[CONVERT]] to offset: [[[CONST0_2]]], sizes: [[[DIMS1]]#1, [[DIMS0]]#1], strides: [[[DIV1]], [[DIV0]]] : memref to memref> // CHECK: memref.store [[CST]], [[REINTERPRET]][[[ADD2]], [[ADD1]]] : memref> func.func @store_dynamic_2d(%arg0: !fir.box> {fir.bindc_name = "x"}) { %c2 = arith.constant 2 : index %cst = arith.constant 3.000000e+00 : f32 %0 = fir.dummy_scope : !fir.dscope %1 = fir.declare %arg0 dummy_scope %0 {uniq_name = "x"} : (!fir.box>, !fir.dscope) -> !fir.box> %2 = fir.rebox %1 : (!fir.box>) -> !fir.box> %3 = fir.array_coor %2 %c2, %c2 : (!fir.box>, index, index) -> !fir.ref fir.store %cst to %3 : !fir.ref return } // subroutine store_dynamic_3d(x) // real, dimension(:, :, :) :: x // x(2, 2, 3) = 3 // end subroutine store_dynamic_3d // CHECK-LABEL: func.func @store_dynamic_3d // CHECK: [[CONST3:%.+]] = arith.constant 3 : index // CHECK: [[CONST2:%.+]] = arith.constant 2 : index // CHECK: [[CST:%.+]] = arith.constant 3.000000e+00 : f32 // CHECK: [[DUMMY:%[0-9]+]] = fir.dummy_scope : !fir.dscope // CHECK: [[DECLARE:%[0-9]+]] = fir.declare %arg0 dummy_scope [[DUMMY]] {uniq_name = "x"} : (!fir.box>, !fir.dscope) -> !fir.box> // CHECK: [[REBOX:%[0-9]+]] = fir.rebox [[DECLARE]] : (!fir.box>) -> !fir.box> // CHECK: [[BOXADDR:%[0-9]+]] = fir.box_addr [[REBOX]] : (!fir.box>) -> !fir.ref> // CHECK: [[CONVERT:%[0-9]+]] = fir.convert [[BOXADDR]] : (!fir.ref>) -> memref // CHECK: [[CONST1:%.+]] = arith.constant 1 : index // CHECK: [[SUB1:%[0-9]+]] = arith.subi [[CONST2]], [[CONST1]] : index // CHECK: [[MUL1:%[0-9]+]] = arith.muli [[SUB1]], [[CONST1]] : index // CHECK: [[SUB1A:%[0-9]+]] = arith.subi [[CONST1]], [[CONST1]] : index // CHECK: [[ADD1:%[0-9]+]] = arith.addi [[MUL1]], [[SUB1A]] : index // CHECK: [[SUB2:%[0-9]+]] = arith.subi [[CONST2]], [[CONST1]] : index // CHECK: [[MUL2:%[0-9]+]] = arith.muli [[SUB2]], [[CONST1]] : index // CHECK: [[SUB2A:%[0-9]+]] = arith.subi [[CONST1]], [[CONST1]] : index // CHECK: [[ADD2:%[0-9]+]] = arith.addi [[MUL2]], [[SUB2A]] : index // CHECK: [[SUB3:%[0-9]+]] = arith.subi [[CONST3]], [[CONST1]] : index // CHECK: [[MUL3:%[0-9]+]] = arith.muli [[SUB3]], [[CONST1]] : index // CHECK: [[SUB3A:%[0-9]+]] = arith.subi [[CONST1]], [[CONST1]] : index // CHECK: [[ADD3:%[0-9]+]] = arith.addi [[MUL3]], [[SUB3A]] : index // CHECK: [[ELSIZE:%[0-9]+]] = fir.box_elesize [[REBOX]] : (!fir.box>) -> index // CHECK: [[CONST2_0:%.+]] = arith.constant 2 : index // CHECK: [[DIMS2:%[0-9]+]]:3 = fir.box_dims [[REBOX]], [[CONST2_0]] : (!fir.box>, index) -> (index, index, index) // CHECK: [[DIV2:%[0-9]+]] = arith.divsi [[DIMS2]]#2, [[ELSIZE]] : index // CHECK: [[CONST1_1:%.+]] = arith.constant 1 : index // CHECK: [[DIMS1:%[0-9]+]]:3 = fir.box_dims [[REBOX]], [[CONST1_1]] : (!fir.box>, index) -> (index, index, index) // CHECK: [[DIV1:%[0-9]+]] = arith.divsi [[DIMS1]]#2, [[ELSIZE]] : index // CHECK: [[CONST0:%.+]] = arith.constant 0 : index // CHECK: [[DIMS0:%[0-9]+]]:3 = fir.box_dims [[REBOX]], [[CONST0]] : (!fir.box>, index) -> (index, index, index) // CHECK: [[DIV0:%[0-9]+]] = arith.divsi [[DIMS0]]#2, [[ELSIZE]] : index // CHECK: [[CONST0_2:%.+]] = arith.constant 0 : index // CHECK: [[REINTERPRET:%.+]] = memref.reinterpret_cast [[CONVERT]] to offset: [[[CONST0_2]]], sizes: [[[DIMS2]]#1, [[DIMS1]]#1, [[DIMS0]]#1], strides: [[[DIV2]], [[DIV1]], [[DIV0]]] : memref to memref> // CHECK: memref.store [[CST]], [[REINTERPRET]][[[ADD3]], [[ADD2]], [[ADD1]]] : memref> func.func @store_dynamic_3d(%arg0: !fir.box> {fir.bindc_name = "x"}) { %c3 = arith.constant 3 : index %c2 = arith.constant 2 : index %cst = arith.constant 3.000000e+00 : f32 %0 = fir.dummy_scope : !fir.dscope %1 = fir.declare %arg0 dummy_scope %0 {uniq_name = "x"} : (!fir.box>, !fir.dscope) -> !fir.box> %2 = fir.rebox %1 : (!fir.box>) -> !fir.box> %3 = fir.array_coor %2 %c2, %c2, %c3 : (!fir.box>, index, index, index) -> !fir.ref fir.store %cst to %3 : !fir.ref return }