| 1 |
// Test optimized bufferization for hlfir.assign with scalar RHS. |
| 2 |
// RUN: fir-opt --opt-bufferization %s | FileCheck %s |
| 3 |
|
| 4 |
func.func @_QPtest1() { |
| 5 |
%cst = arith.constant 0.000000e+00 : f32 |
| 6 |
%c11 = arith.constant 11 : index |
| 7 |
%c13 = arith.constant 13 : index |
| 8 |
%0 = fir.alloca !fir.array<11x13xf32> {bindc_name = "x", uniq_name = "_QFtest1Ex"} |
| 9 |
%1 = fir.shape %c11, %c13 : (index, index) -> !fir.shape<2> |
| 10 |
%2:2 = hlfir.declare %0(%1) {uniq_name = "_QFtest1Ex"} : (!fir.ref<!fir.array<11x13xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<11x13xf32>>, !fir.ref<!fir.array<11x13xf32>>) |
| 11 |
hlfir.assign %cst to %2#0 : f32, !fir.ref<!fir.array<11x13xf32>> |
| 12 |
return |
| 13 |
} |
| 14 |
// CHECK-LABEL: func.func @_QPtest1() { |
| 15 |
// CHECK: %[[VAL_0:.*]] = arith.constant 1 : index |
| 16 |
// CHECK: %[[VAL_1:.*]] = arith.constant 0.000000e+00 : f32 |
| 17 |
// CHECK: %[[VAL_2:.*]] = arith.constant 11 : index |
| 18 |
// CHECK: %[[VAL_3:.*]] = arith.constant 13 : index |
| 19 |
// CHECK: %[[VAL_4:.*]] = fir.alloca !fir.array<11x13xf32> {bindc_name = "x", uniq_name = "_QFtest1Ex"} |
| 20 |
// CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> |
| 21 |
// CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_4]](%[[VAL_5]]) {uniq_name = "_QFtest1Ex"} : (!fir.ref<!fir.array<11x13xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<11x13xf32>>, !fir.ref<!fir.array<11x13xf32>>) |
| 22 |
// CHECK: fir.do_loop %[[VAL_7:.*]] = %[[VAL_0]] to %[[VAL_3]] step %[[VAL_0]] unordered { |
| 23 |
// CHECK: fir.do_loop %[[VAL_8:.*]] = %[[VAL_0]] to %[[VAL_2]] step %[[VAL_0]] unordered { |
| 24 |
// CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_8]], %[[VAL_7]]) : (!fir.ref<!fir.array<11x13xf32>>, index, index) -> !fir.ref<f32> |
| 25 |
// CHECK: hlfir.assign %[[VAL_1]] to %[[VAL_9]] : f32, !fir.ref<f32> |
| 26 |
// CHECK: } |
| 27 |
// CHECK: } |
| 28 |
// CHECK: return |
| 29 |
// CHECK: } |
| 30 |
|
| 31 |
func.func @_QPtest2(%arg0: !fir.box<!fir.array<?x?xi32>> {fir.bindc_name = "x"}) { |
| 32 |
%c0_i32 = arith.constant 0 : i32 |
| 33 |
%0:2 = hlfir.declare %arg0 {uniq_name = "_QFtest2Ex"} : (!fir.box<!fir.array<?x?xi32>>) -> (!fir.box<!fir.array<?x?xi32>>, !fir.box<!fir.array<?x?xi32>>) |
| 34 |
hlfir.assign %c0_i32 to %0#0 : i32, !fir.box<!fir.array<?x?xi32>> |
| 35 |
return |
| 36 |
} |
| 37 |
// CHECK-LABEL: func.func @_QPtest2( |
| 38 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xi32>> {fir.bindc_name = "x"}) { |
| 39 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 40 |
// CHECK: %[[VAL_2:.*]] = arith.constant 0 : index |
| 41 |
// CHECK: %[[VAL_3:.*]] = arith.constant 0 : i32 |
| 42 |
// CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest2Ex"} : (!fir.box<!fir.array<?x?xi32>>) -> (!fir.box<!fir.array<?x?xi32>>, !fir.box<!fir.array<?x?xi32>>) |
| 43 |
// CHECK: %[[VAL_5:.*]]:3 = fir.box_dims %[[VAL_4]]#0, %[[VAL_2]] : (!fir.box<!fir.array<?x?xi32>>, index) -> (index, index, index) |
| 44 |
// CHECK: %[[VAL_6:.*]]:3 = fir.box_dims %[[VAL_4]]#0, %[[VAL_1]] : (!fir.box<!fir.array<?x?xi32>>, index) -> (index, index, index) |
| 45 |
// CHECK: fir.do_loop %[[VAL_7:.*]] = %[[VAL_1]] to %[[VAL_6]]#1 step %[[VAL_1]] unordered { |
| 46 |
// CHECK: fir.do_loop %[[VAL_8:.*]] = %[[VAL_1]] to %[[VAL_5]]#1 step %[[VAL_1]] unordered { |
| 47 |
// CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_8]], %[[VAL_7]]) : (!fir.box<!fir.array<?x?xi32>>, index, index) -> !fir.ref<i32> |
| 48 |
// CHECK: hlfir.assign %[[VAL_3]] to %[[VAL_9]] : i32, !fir.ref<i32> |
| 49 |
// CHECK: } |
| 50 |
// CHECK: } |
| 51 |
// CHECK: return |
| 52 |
// CHECK: } |
| 53 |
|
| 54 |
func.func @_QPtest4(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> {fir.bindc_name = "x"}) { |
| 55 |
%true = arith.constant true |
| 56 |
%0:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest4Ex"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>) |
| 57 |
%1 = fir.convert %true : (i1) -> !fir.logical<4> |
| 58 |
%2 = fir.load %0#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> |
| 59 |
hlfir.assign %1 to %2 : !fir.logical<4>, !fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>> |
| 60 |
return |
| 61 |
} |
| 62 |
// CHECK-LABEL: func.func @_QPtest4( |
| 63 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> {fir.bindc_name = "x"}) { |
| 64 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 65 |
// CHECK: %[[VAL_2:.*]] = arith.constant 0 : index |
| 66 |
// CHECK: %[[VAL_3:.*]] = arith.constant true |
| 67 |
// CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest4Ex"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>) |
| 68 |
// CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_3]] : (i1) -> !fir.logical<4> |
| 69 |
// CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> |
| 70 |
// CHECK: %[[VAL_7:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_2]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> (index, index, index) |
| 71 |
// CHECK: fir.do_loop %[[VAL_8:.*]] = %[[VAL_1]] to %[[VAL_7]]#1 step %[[VAL_1]] unordered { |
| 72 |
// CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_2]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> (index, index, index) |
| 73 |
// CHECK: %[[VAL_10:.*]] = arith.subi %[[VAL_9]]#0, %[[VAL_1]] : index |
| 74 |
// CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_8]], %[[VAL_10]] : index |
| 75 |
// CHECK: %[[VAL_12:.*]] = hlfir.designate %[[VAL_6]] (%[[VAL_11]]) : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> !fir.ref<!fir.logical<4>> |
| 76 |
// CHECK: hlfir.assign %[[VAL_5]] to %[[VAL_12]] : !fir.logical<4>, !fir.ref<!fir.logical<4>> |
| 77 |
// CHECK: } |
| 78 |
// CHECK: return |
| 79 |
// CHECK: } |
| 80 |
|
| 81 |
func.func @_QPtest3(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {fir.bindc_name = "x"}) { |
| 82 |
%c0_i32 = arith.constant 0 : i32 |
| 83 |
%0:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest3Ex"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) |
| 84 |
hlfir.assign %c0_i32 to %0#0 realloc : i32, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> |
| 85 |
return |
| 86 |
} |
| 87 |
// CHECK-LABEL: func.func @_QPtest3( |
| 88 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {fir.bindc_name = "x"}) { |
| 89 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 90 |
// CHECK: %[[VAL_2:.*]] = arith.constant 0 : index |
| 91 |
// CHECK: %[[VAL_3:.*]] = arith.constant 0 : i32 |
| 92 |
// CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest3Ex"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) |
| 93 |
// CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> |
| 94 |
// CHECK: %[[VAL_6:.*]]:3 = fir.box_dims %[[VAL_5]], %[[VAL_2]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>, index) -> (index, index, index) |
| 95 |
// CHECK: fir.do_loop %[[VAL_7:.*]] = %[[VAL_1]] to %[[VAL_6]]#1 step %[[VAL_1]] unordered { |
| 96 |
// CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_5]], %[[VAL_2]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>, index) -> (index, index, index) |
| 97 |
// CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_8]]#0, %[[VAL_1]] : index |
| 98 |
// CHECK: %[[VAL_10:.*]] = arith.addi %[[VAL_7]], %[[VAL_9]] : index |
| 99 |
// CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_5]] (%[[VAL_10]]) : (!fir.box<!fir.heap<!fir.array<?xi32>>>, index) -> !fir.ref<i32> |
| 100 |
// CHECK: hlfir.assign %[[VAL_3]] to %[[VAL_11]] : i32, !fir.ref<i32> |
| 101 |
// CHECK: } |
| 102 |
// CHECK: return |
| 103 |
// CHECK: } |
| 104 |
|
| 105 |
func.func @_QPtest5(%arg0: !fir.ref<!fir.array<77x!fir.complex<4>>> {fir.bindc_name = "x"}) { |
| 106 |
%cst = arith.constant 0.000000e+00 : f32 |
| 107 |
%c77 = arith.constant 77 : index |
| 108 |
%0 = fir.shape %c77 : (index) -> !fir.shape<1> |
| 109 |
%1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFtest5Ex"} : (!fir.ref<!fir.array<77x!fir.complex<4>>>, !fir.shape<1>) -> (!fir.ref<!fir.array<77x!fir.complex<4>>>, !fir.ref<!fir.array<77x!fir.complex<4>>>) |
| 110 |
%2 = fir.undefined !fir.complex<4> |
| 111 |
%3 = fir.insert_value %2, %cst, [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 112 |
%4 = fir.insert_value %3, %cst, [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 113 |
hlfir.assign %4 to %1#0 : !fir.complex<4>, !fir.ref<!fir.array<77x!fir.complex<4>>> |
| 114 |
return |
| 115 |
} |
| 116 |
// CHECK-LABEL: func.func @_QPtest5( |
| 117 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<77x!fir.complex<4>>> {fir.bindc_name = "x"}) { |
| 118 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 119 |
// CHECK: %[[VAL_2:.*]] = arith.constant 0.000000e+00 : f32 |
| 120 |
// CHECK: %[[VAL_3:.*]] = arith.constant 77 : index |
| 121 |
// CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1> |
| 122 |
// CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_4]]) {uniq_name = "_QFtest5Ex"} : (!fir.ref<!fir.array<77x!fir.complex<4>>>, !fir.shape<1>) -> (!fir.ref<!fir.array<77x!fir.complex<4>>>, !fir.ref<!fir.array<77x!fir.complex<4>>>) |
| 123 |
// CHECK: %[[VAL_6:.*]] = fir.undefined !fir.complex<4> |
| 124 |
// CHECK: %[[VAL_7:.*]] = fir.insert_value %[[VAL_6]], %[[VAL_2]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 125 |
// CHECK: %[[VAL_8:.*]] = fir.insert_value %[[VAL_7]], %[[VAL_2]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 126 |
// CHECK: fir.do_loop %[[VAL_9:.*]] = %[[VAL_1]] to %[[VAL_3]] step %[[VAL_1]] unordered { |
| 127 |
// CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_9]]) : (!fir.ref<!fir.array<77x!fir.complex<4>>>, index) -> !fir.ref<!fir.complex<4>> |
| 128 |
// CHECK: hlfir.assign %[[VAL_8]] to %[[VAL_10]] : !fir.complex<4>, !fir.ref<!fir.complex<4>> |
| 129 |
// CHECK: } |
| 130 |
// CHECK: return |
| 131 |
// CHECK: } |