1 // RUN: fir-opt --opt-bufferization %s | FileCheck %s
3 // Verify that the shape match is not required for optimizing
4 // elemental assignment, when lhs not an allocatable.
5 // The shapes of lhs and rhs must conform in a legal program.
8 // subroutine test(a,b)
9 // integer :: a(:), b(:)
11 // end subroutine test
13 func.func @_QPtest(%arg0: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "a"}, %arg1: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "b"}) {
14 %c0 = arith.constant 0 : index
15 %c1_i32 = arith.constant 1 : i32
16 %0 = fir.dummy_scope : !fir.dscope
17 %1:2 = hlfir.declare %arg0 dummy_scope %0 {uniq_name = "_QFtestEa"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
18 %2:2 = hlfir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtestEb"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
19 %3:3 = fir.box_dims %2#0, %c0 : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
20 %4 = fir.shape %3#1 : (index) -> !fir.shape<1>
21 %5 = hlfir.elemental %4 unordered : (!fir.shape<1>) -> !hlfir.expr<?xi32> {
23 %6 = hlfir.designate %2#0 (%arg2) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
24 %7 = fir.load %6 : !fir.ref<i32>
25 %8 = arith.addi %7, %c1_i32 : i32
26 hlfir.yield_element %8 : i32
28 hlfir.assign %5 to %1#0 : !hlfir.expr<?xi32>, !fir.box<!fir.array<?xi32>>
29 hlfir.destroy %5 : !hlfir.expr<?xi32>
32 // CHECK-LABEL: func.func @_QPtest(
33 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "a"},
34 // CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "b"}) {
35 // CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
36 // CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
37 // CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
38 // CHECK: %[[VAL_5:.*]] = fir.dummy_scope : !fir.dscope
39 // CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_5]] {uniq_name = "_QFtestEa"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
40 // CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %[[VAL_5]] {uniq_name = "_QFtestEb"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
41 // CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_7]]#0, %[[VAL_3]] : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
42 // CHECK: fir.do_loop %[[VAL_9:.*]] = %[[VAL_2]] to %[[VAL_8]]#1 step %[[VAL_2]] unordered {
43 // CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_9]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
44 // CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
45 // CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_11]], %[[VAL_4]] : i32
46 // CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_9]]) : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
47 // CHECK: hlfir.assign %[[VAL_12]] to %[[VAL_13]] : i32, !fir.ref<i32>