| 1 |
! This test focus on cmplx with Y argument that may turn out |
| 2 |
! to be absent at runtime because it is an unallocated allocatable, |
| 3 |
! a disassociated pointer, or an optional argument. |
| 4 |
! CMPLX without such argument is re-written by the front-end as a |
| 5 |
! complex constructor that is tested elsewhere. |
| 6 |
! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s |
| 7 |
|
| 8 |
! CHECK-LABEL: func @_QPcmplx_test_scalar_ptr( |
| 9 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> |
| 10 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.ptr<f32>>> |
| 11 |
subroutine cmplx_test_scalar_ptr(x, y) |
| 12 |
real :: x |
| 13 |
real, pointer :: y |
| 14 |
print *, cmplx(x, y) |
| 15 |
! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref<f32> |
| 16 |
! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<f32>>> |
| 17 |
! CHECK: %[[VAL_9:.*]] = fir.box_addr %[[VAL_8]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32> |
| 18 |
! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (!fir.ptr<f32>) -> i64 |
| 19 |
! CHECK: %[[VAL_11:.*]] = arith.constant 0 : i64 |
| 20 |
! CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_10]], %[[VAL_11]] : i64 |
| 21 |
! CHECK: %[[VAL_13:.*]] = fir.if %[[VAL_12]] -> (f32) { |
| 22 |
! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<f32>>> |
| 23 |
! CHECK: %[[VAL_15:.*]] = fir.box_addr %[[VAL_14]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32> |
| 24 |
! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.ptr<f32> |
| 25 |
! CHECK: fir.result %[[VAL_16]] : f32 |
| 26 |
! CHECK: } else { |
| 27 |
! CHECK: %[[VAL_17:.*]] = arith.constant 0.000000e+00 : f32 |
| 28 |
! CHECK: fir.result %[[VAL_17]] : f32 |
| 29 |
! CHECK: } |
| 30 |
! CHECK: %[[VAL_18:.*]] = fir.undefined !fir.complex<4> |
| 31 |
! CHECK: %[[VAL_19:.*]] = fir.insert_value %[[VAL_18]], %[[VAL_7]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 32 |
! CHECK: fir.insert_value %[[VAL_19]], %[[VAL_21:.*]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 33 |
end subroutine |
| 34 |
|
| 35 |
! CHECK-LABEL: func @_QPcmplx_test_scalar_optional( |
| 36 |
! CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.ref<f32> |
| 37 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f32> |
| 38 |
subroutine cmplx_test_scalar_optional(x, y) |
| 39 |
real :: x |
| 40 |
real, optional :: y |
| 41 |
print *, cmplx(x, y) |
| 42 |
! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref<f32> |
| 43 |
! CHECK: %[[VAL_8:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref<f32>) -> i1 |
| 44 |
! CHECK: %[[VAL_9:.*]] = fir.if %[[VAL_8]] -> (f32) { |
| 45 |
! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_1]] : !fir.ref<f32> |
| 46 |
! CHECK: fir.result %[[VAL_10]] : f32 |
| 47 |
! CHECK: } else { |
| 48 |
! CHECK: %[[VAL_11:.*]] = arith.constant 0.000000e+00 : f32 |
| 49 |
! CHECK: fir.result %[[VAL_11]] : f32 |
| 50 |
! CHECK: } |
| 51 |
! CHECK: %[[VAL_12:.*]] = fir.undefined !fir.complex<4> |
| 52 |
! CHECK: %[[VAL_13:.*]] = fir.insert_value %[[VAL_12]], %[[VAL_7]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 53 |
! CHECK: fir.insert_value %[[VAL_13]], %[[VAL_15:.*]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 54 |
end subroutine |
| 55 |
|
| 56 |
! CHECK-LABEL: func @_QPcmplx_test_scalar_alloc_optional( |
| 57 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> |
| 58 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.heap<i64>>> |
| 59 |
subroutine cmplx_test_scalar_alloc_optional(x, y) |
| 60 |
real :: x |
| 61 |
integer(8), allocatable, optional :: y |
| 62 |
print *, cmplx(x, y) |
| 63 |
! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref<f32> |
| 64 |
! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<i64>>> |
| 65 |
! CHECK: %[[VAL_9:.*]] = fir.box_addr %[[VAL_8]] : (!fir.box<!fir.heap<i64>>) -> !fir.heap<i64> |
| 66 |
! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (!fir.heap<i64>) -> i64 |
| 67 |
! CHECK: %[[VAL_11:.*]] = arith.constant 0 : i64 |
| 68 |
! CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_10]], %[[VAL_11]] : i64 |
| 69 |
! CHECK: %[[VAL_13:.*]] = fir.if %[[VAL_12]] -> (i64) { |
| 70 |
! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<i64>>> |
| 71 |
! CHECK: %[[VAL_15:.*]] = fir.box_addr %[[VAL_14]] : (!fir.box<!fir.heap<i64>>) -> !fir.heap<i64> |
| 72 |
! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.heap<i64> |
| 73 |
! CHECK: fir.result %[[VAL_16]] : i64 |
| 74 |
! CHECK: } else { |
| 75 |
! CHECK: %[[VAL_17:.*]] = arith.constant 0 : i64 |
| 76 |
! CHECK: fir.result %[[VAL_17]] : i64 |
| 77 |
! CHECK: } |
| 78 |
! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_19:.*]] : (i64) -> f32 |
| 79 |
! CHECK: %[[VAL_20:.*]] = fir.undefined !fir.complex<4> |
| 80 |
! CHECK: %[[VAL_21:.*]] = fir.insert_value %[[VAL_20]], %[[VAL_7]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 81 |
! CHECK: fir.insert_value %[[VAL_21]], %[[VAL_18]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 82 |
end subroutine |
| 83 |
|
| 84 |
! CHECK-LABEL: func @_QPcmplx_test_pointer_result( |
| 85 |
! CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.ref<f32> |
| 86 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f32> |
| 87 |
subroutine cmplx_test_pointer_result(x, y) |
| 88 |
real :: x |
| 89 |
interface |
| 90 |
function return_pointer() |
| 91 |
real, pointer :: return_pointer |
| 92 |
end function |
| 93 |
end interface |
| 94 |
print *, cmplx(x, return_pointer()) |
| 95 |
! CHECK: %[[VAL_9:.*]] = fir.call @_QPreturn_pointer() {{.*}}: () -> !fir.box<!fir.ptr<f32>> |
| 96 |
! CHECK: fir.save_result %[[VAL_9]] to %[[VAL_2:.*]] : !fir.box<!fir.ptr<f32>>, !fir.ref<!fir.box<!fir.ptr<f32>>> |
| 97 |
! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.box<!fir.ptr<f32>>> |
| 98 |
! CHECK: %[[VAL_11:.*]] = fir.box_addr %[[VAL_10]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32> |
| 99 |
! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (!fir.ptr<f32>) -> i64 |
| 100 |
! CHECK: %[[VAL_13:.*]] = arith.constant 0 : i64 |
| 101 |
! CHECK: %[[VAL_14:.*]] = arith.cmpi ne, %[[VAL_12]], %[[VAL_13]] : i64 |
| 102 |
! CHECK: %[[VAL_15:.*]] = fir.if %[[VAL_14]] -> (f32) { |
| 103 |
! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.box<!fir.ptr<f32>>> |
| 104 |
! CHECK: %[[VAL_17:.*]] = fir.box_addr %[[VAL_16]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32> |
| 105 |
! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_17]] : !fir.ptr<f32> |
| 106 |
! CHECK: fir.result %[[VAL_18]] : f32 |
| 107 |
! CHECK: } else { |
| 108 |
! CHECK: %[[VAL_19:.*]] = arith.constant 0.000000e+00 : f32 |
| 109 |
! CHECK: fir.result %[[VAL_19]] : f32 |
| 110 |
! CHECK: } |
| 111 |
! CHECK: %[[VAL_20:.*]] = fir.undefined !fir.complex<4> |
| 112 |
! CHECK: %[[VAL_21:.*]] = fir.insert_value %[[VAL_20]], %[[VAL_8]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 113 |
! CHECK: fir.insert_value %[[VAL_21]], %[[VAL_23:.*]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 114 |
end subroutine |
| 115 |
|
| 116 |
! CHECK-LABEL: func @_QPcmplx_array( |
| 117 |
! CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.box<!fir.array<?xf32>> |
| 118 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xf32>> |
| 119 |
subroutine cmplx_array(x, y) |
| 120 |
! Important, note that the shape is taken from `x` and not `y` that |
| 121 |
! may be absent. |
| 122 |
real :: x(:) |
| 123 |
real, optional :: y(:) |
| 124 |
print *, cmplx(x, y) |
| 125 |
! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index |
| 126 |
! CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_7]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 127 |
! CHECK: %[[VAL_9:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32> |
| 128 |
! CHECK: %[[VAL_10:.*]] = fir.is_present %[[VAL_1]] : (!fir.box<!fir.array<?xf32>>) -> i1 |
| 129 |
! CHECK: %[[VAL_11:.*]] = fir.zero_bits !fir.ref<!fir.array<?xf32>> |
| 130 |
! CHECK: %[[VAL_12:.*]] = arith.constant 0 : index |
| 131 |
! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_12]] : (index) -> !fir.shape<1> |
| 132 |
! CHECK: %[[VAL_14:.*]] = fir.embox %[[VAL_11]](%[[VAL_13]]) : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |
| 133 |
! CHECK: %[[VAL_15:.*]] = arith.select %[[VAL_10]], %[[VAL_1]], %[[VAL_14]] : !fir.box<!fir.array<?xf32>> |
| 134 |
! CHECK: %[[VAL_16:.*]] = fir.array_load %[[VAL_15]] {fir.optional} : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32> |
| 135 |
! CHECK: %[[VAL_17:.*]] = fir.allocmem !fir.array<?x!fir.complex<4>>, %[[VAL_8]]#1 {uniq_name = ".array.expr"} |
| 136 |
! CHECK: %[[VAL_18:.*]] = fir.shape %[[VAL_8]]#1 : (index) -> !fir.shape<1> |
| 137 |
! CHECK: %[[VAL_19:.*]] = fir.array_load %[[VAL_17]](%[[VAL_18]]) : (!fir.heap<!fir.array<?x!fir.complex<4>>>, !fir.shape<1>) -> !fir.array<?x!fir.complex<4>> |
| 138 |
! CHECK: %[[VAL_20:.*]] = arith.constant 1 : index |
| 139 |
! CHECK: %[[VAL_21:.*]] = arith.constant 0 : index |
| 140 |
! CHECK: %[[VAL_22:.*]] = arith.subi %[[VAL_8]]#1, %[[VAL_20]] : index |
| 141 |
! CHECK: %[[VAL_23:.*]] = fir.do_loop %[[VAL_24:.*]] = %[[VAL_21]] to %[[VAL_22]] step %[[VAL_20]] unordered iter_args(%[[VAL_25:.*]] = %[[VAL_19]]) -> (!fir.array<?x!fir.complex<4>>) { |
| 142 |
! CHECK: %[[VAL_26:.*]] = fir.array_fetch %[[VAL_9]], %[[VAL_24]] : (!fir.array<?xf32>, index) -> f32 |
| 143 |
! CHECK: %[[VAL_27:.*]] = fir.if %[[VAL_10]] -> (f32) { |
| 144 |
! CHECK: %[[VAL_28:.*]] = fir.array_fetch %[[VAL_16]], %[[VAL_24]] : (!fir.array<?xf32>, index) -> f32 |
| 145 |
! CHECK: fir.result %[[VAL_28]] : f32 |
| 146 |
! CHECK: } else { |
| 147 |
! CHECK: %[[VAL_29:.*]] = arith.constant 0.000000e+00 : f32 |
| 148 |
! CHECK: fir.result %[[VAL_29]] : f32 |
| 149 |
! CHECK: } |
| 150 |
! CHECK: %[[VAL_30:.*]] = fir.undefined !fir.complex<4> |
| 151 |
! CHECK: %[[VAL_31:.*]] = fir.insert_value %[[VAL_30]], %[[VAL_26]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 152 |
! CHECK: %[[VAL_32:.*]] = fir.insert_value %[[VAL_31]], %[[VAL_33:.*]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> |
| 153 |
! CHECK: %[[VAL_34:.*]] = fir.array_update %[[VAL_25]], %[[VAL_32]], %[[VAL_24]] : (!fir.array<?x!fir.complex<4>>, !fir.complex<4>, index) -> !fir.array<?x!fir.complex<4>> |
| 154 |
! CHECK: fir.result %[[VAL_34]] : !fir.array<?x!fir.complex<4>> |
| 155 |
! CHECK: } |
| 156 |
! CHECK: fir.array_merge_store |
| 157 |
end subroutine |