// Verify fir.array_coor lowering when the base is a block argument. // This used to take a shortcut (convert the element ref result) which kept the // fir.array_coor alive. We prefer converting the base to a memref and // computing indices so that fir.array_coor can be erased when only used by // load/store. // // RUN: fir-opt %s --fir-to-memref --allow-unregistered-dialect | FileCheck %s func.func @block_arg_memref(%arg0: !fir.ref>) { %c32 = arith.constant 32 : index %c1 = arith.constant 1 : index %c1_i32 = arith.constant 1 : i32 %shape = fir.shape %c32 : (index) -> !fir.shape<1> %elt = fir.array_coor %arg0(%shape) %c1 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref fir.store %c1_i32 to %elt : !fir.ref return } // CHECK-LABEL: func.func @block_arg_memref // CHECK: [[BASE:%.+]] = fir.convert %arg0 : (!fir.ref>) -> memref<32xi32> // CHECK: [[ONE:%.+]] = arith.constant 1 : index // CHECK: [[SUB:%.+]] = arith.subi %c1, [[ONE]] : index // CHECK: [[MUL:%.+]] = arith.muli [[SUB]], [[ONE]] : index // CHECK: [[SUB2:%.+]] = arith.subi [[ONE]], [[ONE]] : index // CHECK: [[IDX:%.+]] = arith.addi [[MUL]], [[SUB2]] : index // CHECK: memref.store {{%.+}}, [[BASE]][[[IDX]]] : memref<32xi32> // CHECK-NOT: fir.array_coor // Verify fir.array_coor lowering when the base is a boxed function argument. // The pass must materialize fir.box_addr // first and must not emit an illegal direct box->memref fir.convert. func.func @block_arg_boxed_array(%arg0: !fir.box>) { %c1_i32 = arith.constant 1 : i32 %c1_i64 = arith.constant 1 : i64 %elt = fir.array_coor %arg0 %c1_i64 : (!fir.box>, i64) -> !fir.ref fir.store %c1_i32 to %elt : !fir.ref return } // CHECK-LABEL: func.func @block_arg_boxed_array // CHECK: [[BOXADDR:%.+]] = fir.box_addr %arg0 // CHECK: [[BASE:%.+]] = fir.convert [[BOXADDR]] : (!fir.ref>) -> memref // CHECK-NOT: fir.convert %arg0 : (!fir.box>) -> memref // CHECK: memref.store {{%.+}}, {{%.+}}[{{%.+}}] : memref> // CHECK-NOT: fir.array_coor // Verify fir.array_coor lowering keeps descriptor stride semantics when the // box element type has static extent. A boxed section may still be strided. func.func @block_arg_boxed_static_array(%arg0: !fir.box>) { %c1_i32 = arith.constant 1 : i32 %c2_i64 = arith.constant 2 : i64 %elt = fir.array_coor %arg0 %c2_i64 : (!fir.box>, i64) -> !fir.ref fir.store %c1_i32 to %elt : !fir.ref return } // CHECK-LABEL: func.func @block_arg_boxed_static_array // CHECK: [[BOXADDR:%.+]] = fir.box_addr %arg0 // CHECK: [[BASE:%.+]] = fir.convert [[BOXADDR]] : (!fir.ref>) -> memref<5xi32> // CHECK: [[ELE:%.+]] = fir.box_elesize // CHECK: [[DIMS:%.+]]:3 = fir.box_dims // CHECK: [[DIV:%.+]] = arith.divsi {{%.+}}, [[ELE]] : index // CHECK: [[REINT:%.+]] = memref.reinterpret_cast [[BASE]] // CHECK-SAME: : memref<5xi32> to memref> // CHECK: memref.store {{%.+}}, [[REINT]][{{%.+}}] : memref> // CHECK-NOT: fir.array_coor