276 lines · plain
1// RUN: fir-opt --propagate-fortran-attrs --split-input-file %s | FileCheck %s2 3//subroutine test1(x, n, k1, k2)4// real :: x(n)5// x(1:k1) = x(k1+1:k2)6//end subroutine test17 8// CHECK-LABEL: func.func @_QPtest1(9func.func @_QPtest1(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}, %arg2: !fir.ref<i32> {fir.bindc_name = "k1"}, %arg3: !fir.ref<i32> {fir.bindc_name = "k2"}) {10 %c1 = arith.constant 1 : index11 %c1_i32 = arith.constant 1 : i3212 %c0 = arith.constant 0 : index13 %0 = fir.dummy_scope : !fir.dscope14 %1:2 = hlfir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest1Ek1"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)15 %2:2 = hlfir.declare %arg3 dummy_scope %0 {uniq_name = "_QFtest1Ek2"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)16 %3:2 = hlfir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest1En"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)17 %4 = fir.load %3#0 : !fir.ref<i32>18 %5 = fir.convert %4 : (i32) -> index19 %6 = arith.cmpi sgt, %5, %c0 : index20 %7 = arith.select %6, %5, %c0 : index21 %8 = fir.shape %7 : (index) -> !fir.shape<1>22 %9:2 = hlfir.declare %arg0(%8) dummy_scope %0 {uniq_name = "_QFtest1Ex"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)23 %10 = fir.load %1#0 : !fir.ref<i32>24 %11 = arith.addi %10, %c1_i32 overflow<nsw> : i3225 %12 = fir.load %2#0 : !fir.ref<i32>26 %13 = fir.convert %11 : (i32) -> index27 %14 = fir.convert %12 : (i32) -> index28 %15 = arith.subi %14, %13 : index29 %16 = arith.addi %15, %c1 : index30 %17 = arith.cmpi sgt, %16, %c0 : index31 %18 = arith.select %17, %16, %c0 : index32 %19 = fir.shape %18 : (index) -> !fir.shape<1>33// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>34 %20 = hlfir.designate %9#0 (%13:%14:%c1) shape %19 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>35 %21 = fir.convert %10 : (i32) -> index36 %22 = arith.cmpi sgt, %21, %c0 : index37 %23 = arith.select %22, %21, %c0 : index38 %24 = fir.shape %23 : (index) -> !fir.shape<1>39// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>40 %25 = hlfir.designate %9#0 (%c1:%21:%c1) shape %24 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>41 hlfir.assign %20 to %25 : !fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>42 return43}44 45// -----46 47//subroutine test2(x, n, k1, k2)48// real, contiguous :: x(:)49// x(1:k1) = x(k1+1:k2)50//end subroutine test251 52// CHECK-LABEL: func.func @_QPtest2(53func.func @_QPtest2(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.contiguous}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}, %arg2: !fir.ref<i32> {fir.bindc_name = "k1"}, %arg3: !fir.ref<i32> {fir.bindc_name = "k2"}) {54 %c1_i32 = arith.constant 1 : i3255 %c1 = arith.constant 1 : index56 %c0 = arith.constant 0 : index57 %0 = fir.dummy_scope : !fir.dscope58 %1:2 = hlfir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest2Ek1"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)59 %2:2 = hlfir.declare %arg3 dummy_scope %0 {uniq_name = "_QFtest2Ek2"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)60 %3:2 = hlfir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest2En"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)61 %4 = fir.box_addr %arg0 : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>62 %5:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)63 %6 = fir.shape_shift %c1, %5#1 : (index, index) -> !fir.shapeshift<1>64 %7:2 = hlfir.declare %4(%6) dummy_scope %0 {fortran_attrs = #fir.var_attrs<contiguous>, uniq_name = "_QFtest2Ex"} : (!fir.ref<!fir.array<?xf32>>, !fir.shapeshift<1>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)65 %8 = fir.load %1#0 : !fir.ref<i32>66 %9 = arith.addi %8, %c1_i32 overflow<nsw> : i3267 %10 = fir.load %2#0 : !fir.ref<i32>68 %11 = fir.convert %9 : (i32) -> index69 %12 = fir.convert %10 : (i32) -> index70 %13 = arith.subi %12, %11 : index71 %14 = arith.addi %13, %c1 : index72 %15 = arith.cmpi sgt, %14, %c0 : index73 %16 = arith.select %15, %14, %c0 : index74 %17 = fir.shape %16 : (index) -> !fir.shape<1>75// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>76 %18 = hlfir.designate %7#0 (%11:%12:%c1) shape %17 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>77 %19 = fir.convert %8 : (i32) -> index78 %20 = arith.cmpi sgt, %19, %c0 : index79 %21 = arith.select %20, %19, %c0 : index80 %22 = fir.shape %21 : (index) -> !fir.shape<1>81// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>82 %23 = hlfir.designate %7#0 (%c1:%19:%c1) shape %22 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>83 hlfir.assign %18 to %23 : !fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>84 return85}86 87// -----88 89//subroutine test390// real :: x(10:100)91// call inner(x)92//contains93// subroutine inner(x) ! manually inlined94// real :: x(:)95// x(10:20) = x(21:31)96// end subroutine inner97//end subroutine test398 99// CHECK-LABEL: func.func @_QPtest3() {100func.func @_QPtest3() {101 %c91 = arith.constant 91 : index102 %c10 = arith.constant 10 : index103 %0 = fir.dummy_scope : !fir.dscope104 %1 = fir.alloca !fir.array<91xf32> {bindc_name = "x", uniq_name = "_QFtest3Ex"}105 %2 = fir.shape_shift %c10, %c91 : (index, index) -> !fir.shapeshift<1>106 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest3Ex"} : (!fir.ref<!fir.array<91xf32>>, !fir.shapeshift<1>) -> (!fir.box<!fir.array<91xf32>>, !fir.ref<!fir.array<91xf32>>)107 %4 = fir.convert %3#0 : (!fir.box<!fir.array<91xf32>>) -> !fir.box<!fir.array<?xf32>>108 // inner() code:109 %c20 = arith.constant 20 : index110 %c11 = arith.constant 11 : index111 %c1 = arith.constant 1 : index112 %c31 = arith.constant 31 : index113 %c21 = arith.constant 21 : index114 %100 = fir.dummy_scope : !fir.dscope115 %101:2 = hlfir.declare %4 dummy_scope %100 {uniq_name = "_QFtest3FinnerEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)116 %102 = fir.shape %c11 : (index) -> !fir.shape<1>117// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>118 %103 = hlfir.designate %101#0 (%c21:%c31:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>119// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>120 %104 = hlfir.designate %101#0 (%c10:%c20:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>121 hlfir.assign %103 to %104 : !fir.box<!fir.array<11xf32>>, !fir.box<!fir.array<11xf32>>122 return123}124 125// -----126 127//subroutine test4128// real :: x(100)129// call inner(x)130//contains131// subroutine inner(x) ! manually inlined132// real :: x(:)133// x(10:20) = x(21:31)134// end subroutine inner135//end subroutine test4136 137// CHECK-LABEL: func.func @_QPtest4() {138func.func @_QPtest4() {139 %c100 = arith.constant 100 : index140 %0 = fir.dummy_scope : !fir.dscope141 %1 = fir.alloca !fir.array<100xf32> {bindc_name = "x", uniq_name = "_QFtest4Ex"}142 %2 = fir.shape %c100 : (index) -> !fir.shape<1>143 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest4Ex"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>)144 %4 = fir.embox %3#0(%2) : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<100xf32>>145 %5 = fir.convert %4 : (!fir.box<!fir.array<100xf32>>) -> !fir.box<!fir.array<?xf32>>146 // inner() code:147 %c20 = arith.constant 20 : index148 %c10 = arith.constant 10 : index149 %c11 = arith.constant 11 : index150 %c1 = arith.constant 1 : index151 %c31 = arith.constant 31 : index152 %c21 = arith.constant 21 : index153 %100 = fir.dummy_scope : !fir.dscope154// CHECK: hlfir.declare{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>, uniq_name = "_QFtest4FinnerEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)155 %101:2 = hlfir.declare %5 dummy_scope %100 {uniq_name = "_QFtest4FinnerEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)156 %102 = fir.shape %c11 : (index) -> !fir.shape<1>157// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>158 %103 = hlfir.designate %101#0 (%c21:%c31:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>159// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>160 %104 = hlfir.designate %101#0 (%c10:%c20:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>161 hlfir.assign %103 to %104 : !fir.box<!fir.array<11xf32>>, !fir.box<!fir.array<11xf32>>162 return163}164 165// -----166 167//subroutine test5168// real :: x(100)169// call inner(x(1:50))170//contains171// subroutine inner(x) ! manually inlined172// real :: x(:)173// x(10:20) = x(21:31)174// end subroutine inner175//end subroutine test5176 177// CHECK-LABEL: func.func @_QPtest5() {178func.func @_QPtest5() {179 %c50 = arith.constant 50 : index180 %c1 = arith.constant 1 : index181 %c100 = arith.constant 100 : index182 %0 = fir.dummy_scope : !fir.dscope183 %1 = fir.alloca !fir.array<100xf32> {bindc_name = "x", uniq_name = "_QFtest5Ex"}184 %2 = fir.shape %c100 : (index) -> !fir.shape<1>185 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest5Ex"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>)186 %4 = fir.shape %c50 : (index) -> !fir.shape<1>187 %5 = hlfir.designate %3#0 (%c1:%c50:%c1) shape %4 : (!fir.ref<!fir.array<100xf32>>, index, index, index, !fir.shape<1>) -> !fir.ref<!fir.array<50xf32>>188 %6 = fir.embox %5(%4) : (!fir.ref<!fir.array<50xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<50xf32>>189 %7 = fir.convert %6 : (!fir.box<!fir.array<50xf32>>) -> !fir.box<!fir.array<?xf32>>190 // inner() code:191 %c20 = arith.constant 20 : index192 %c10 = arith.constant 10 : index193 %c11 = arith.constant 11 : index194 %c31 = arith.constant 31 : index195 %c21 = arith.constant 21 : index196 %100 = fir.dummy_scope : !fir.dscope197// CHECK: hlfir.declare{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>, uniq_name = "_QFtest5FinnerEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)198 %101:2 = hlfir.declare %7 dummy_scope %100 {uniq_name = "_QFtest5FinnerEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)199 %102 = fir.shape %c11 : (index) -> !fir.shape<1>200// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>201 %103 = hlfir.designate %101#0 (%c21:%c31:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>202// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>203 %104 = hlfir.designate %101#0 (%c10:%c20:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>204 hlfir.assign %103 to %104 : !fir.box<!fir.array<11xf32>>, !fir.box<!fir.array<11xf32>>205 return206}207 208// -----209 210//subroutine test6(x,k)211// real, contiguous :: x(:)212// call inner(x(1:k))213//contains214// subroutine inner(x) ! manually inlined215// real :: x(:)216// x(10:20) = x(21:31)217// end subroutine inner218//end subroutine test6219 220// CHECK-LABEL: func.func @_QPtest6(221func.func @_QPtest6(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.contiguous}, %arg1: !fir.ref<i32> {fir.bindc_name = "k"}) {222 %c1 = arith.constant 1 : index223 %c0 = arith.constant 0 : index224 %0 = fir.dummy_scope : !fir.dscope225 %1:2 = hlfir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest6Ek"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)226 %2 = fir.box_addr %arg0 : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>227 %3:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)228 %4 = fir.shape_shift %c1, %3#1 : (index, index) -> !fir.shapeshift<1>229 %5:2 = hlfir.declare %2(%4) dummy_scope %0 {fortran_attrs = #fir.var_attrs<contiguous>, uniq_name = "_QFtest6Ex"} : (!fir.ref<!fir.array<?xf32>>, !fir.shapeshift<1>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)230 %6 = fir.load %1#0 : !fir.ref<i32>231 %7 = fir.convert %6 : (i32) -> index232 %8 = arith.cmpi sgt, %7, %c0 : index233 %9 = arith.select %8, %7, %c0 : index234 %10 = fir.shape %9 : (index) -> !fir.shape<1>235 // hlfir.designate manually replaced with fir.rebox:236 %slice = fir.slice %c1, %7, %c1 : (index, index, index) -> !fir.slice<1>237 %11 = fir.rebox %5#0 [%slice] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>238 // inner() code:239 %c20 = arith.constant 20 : index240 %c10 = arith.constant 10 : index241 %c11 = arith.constant 11 : index242 %c31 = arith.constant 31 : index243 %c21 = arith.constant 21 : index244 %100 = fir.dummy_scope : !fir.dscope245// CHECK: hlfir.declare{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>, uniq_name = "_QFtest6FinnerEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)246 %101:2 = hlfir.declare %11 dummy_scope %100 {uniq_name = "_QFtest6FinnerEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)247 %102 = fir.shape %c11 : (index) -> !fir.shape<1>248// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>249 %103 = hlfir.designate %101#0 (%c21:%c31:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>250// CHECK: hlfir.designate{{.*}}{fortran_attrs = #fir.var_attrs<contiguous>} : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>251 %104 = hlfir.designate %101#0 (%c10:%c20:%c1) shape %102 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<11xf32>>252 hlfir.assign %103 to %104 : !fir.box<!fir.array<11xf32>>, !fir.box<!fir.array<11xf32>>253 return254}255 256// -----257 258// Make sure contiguous attribute is not set on hlfir.declare:259//subroutine test7()260// real, pointer :: x(:)261//end subroutine test7262 263func.func @_QPtest7() {264 %c0 = arith.constant 0 : index265 %0 = fir.dummy_scope : !fir.dscope266 %1 = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {bindc_name = "x", uniq_name = "_QFtest7Ex"}267 %2 = fir.zero_bits !fir.ptr<!fir.array<?xf32>>268 %3 = fir.shape %c0 : (index) -> !fir.shape<1>269 %4 = fir.embox %2(%3) : (!fir.ptr<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>270 fir.store %4 to %1 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>271 %5:2 = hlfir.declare %1 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest7Ex"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>)272 return273}274// CHECK-LABEL: func.func @_QPtest7(275// CHECK-NOT: contiguous276