Debian Codegraph @

flang/test/Lower/HLFIR/elemental-call-vector-subscripts.f90

raw
1 ! Test passing of vector subscripted entities inside elemental
2 ! procedures.
3 ! RUN: bbc --emit-hlfir -o - %s | FileCheck %s
4
5 subroutine test()
6 interface
7 elemental subroutine foo(x, y)
8 real, intent(in) :: x
9 real, value :: y
10 end subroutine
11 end interface
12 real :: x(10)
13 call foo(x([1,3,7]), 0.)
14 end subroutine
15 ! CHECK-LABEL: func.func @_QPtest() {
16 ! CHECK: %[[VAL_0:.*]] = arith.constant 10 : index
17 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.array<10xf32> {bindc_name = "x", uniq_name = "_QFtestEx"}
18 ! CHECK: %[[VAL_2:.*]] = fir.shape %[[VAL_0]] : (index) -> !fir.shape<1>
19 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_2]]) {uniq_name = "_QFtestEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>)
20 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QQro.3xi8.0) : !fir.ref<!fir.array<3xi64>>
21 ! CHECK: %[[VAL_5:.*]] = arith.constant 3 : index
22 ! CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
23 ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_4]](%[[VAL_6]])
24 ! CHECK: %[[VAL_8:.*]] = arith.constant 3 : index
25 ! CHECK: %[[VAL_9:.*]] = arith.constant 0.000000e+00 : f32
26 ! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index
27 ! CHECK: fir.do_loop %[[VAL_11:.*]] = %[[VAL_10]] to %[[VAL_8]] step %[[VAL_10]] unordered {
28 ! CHECK: %[[VAL_12:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_11]]) : (!fir.ref<!fir.array<3xi64>>, index) -> !fir.ref<i64>
29 ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_12]] : !fir.ref<i64>
30 ! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_13]]) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
31 ! CHECK: fir.call @_QPfoo(%[[VAL_14]], %[[VAL_9]]) {{.*}}: (!fir.ref<f32>, f32) -> ()
32 ! CHECK: }
33 ! CHECK: return
34 ! CHECK: }
35
36 subroutine test_value()
37 interface
38 elemental subroutine foo_value(x, y)
39 real, value :: x
40 real, value :: y
41 end subroutine
42 end interface
43 real :: x(10)
44 call foo_value(x([1,3,7]), 0.)
45 end subroutine
46
47 ! CHECK-LABEL: func.func @_QPtest_value() {
48 ! CHECK: %[[VAL_0:.*]] = arith.constant 10 : index
49 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.array<10xf32> {bindc_name = "x", uniq_name = "_QFtest_valueEx"}
50 ! CHECK: %[[VAL_2:.*]] = fir.shape %[[VAL_0]] : (index) -> !fir.shape<1>
51 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_2]]) {uniq_name = "_QFtest_valueEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>)
52 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QQro.3xi8.0) : !fir.ref<!fir.array<3xi64>>
53 ! CHECK: %[[VAL_5:.*]] = arith.constant 3 : index
54 ! CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
55 ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_4]](%[[VAL_6]])
56 ! CHECK: %[[VAL_8:.*]] = arith.constant 3 : index
57 ! CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_8]] : (index) -> !fir.shape<1>
58 ! CHECK: %[[VAL_10:.*]] = hlfir.elemental %[[VAL_9]] unordered : (!fir.shape<1>) -> !hlfir.expr<3xf32> {
59 ! CHECK: ^bb0(%[[VAL_11:.*]]: index):
60 ! CHECK: %[[VAL_12:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_11]]) : (!fir.ref<!fir.array<3xi64>>, index) -> !fir.ref<i64>
61 ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_12]] : !fir.ref<i64>
62 ! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_13]]) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
63 ! CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_14]] : !fir.ref<f32>
64 ! CHECK: hlfir.yield_element %[[VAL_15]] : f32
65 ! CHECK: }
66 ! CHECK: %[[VAL_16:.*]] = arith.constant 0.000000e+00 : f32
67 ! CHECK: %[[VAL_17:.*]] = arith.constant 1 : index
68 ! CHECK: fir.do_loop %[[VAL_18:.*]] = %[[VAL_17]] to %[[VAL_8]] step %[[VAL_17]] unordered {
69 ! CHECK: %[[VAL_19:.*]] = hlfir.apply %[[VAL_10]], %[[VAL_18]] : (!hlfir.expr<3xf32>, index) -> f32
70 ! CHECK: fir.call @_QPfoo_value(%[[VAL_19]], %[[VAL_16]]) {{.*}}: (f32, f32) -> ()
71 ! CHECK: }
72 ! CHECK: hlfir.destroy %[[VAL_10]] : !hlfir.expr<3xf32>
73 ! CHECK: return
74
75 subroutine test_not_a_variable(i)
76 interface
77 elemental subroutine foo2(j)
78 integer(8), intent(in) :: j
79 end subroutine
80 end interface
81 integer(8) :: i(:)
82 call foo2((i(i)))
83 end subroutine
84 ! CHECK-LABEL: func.func @_QPtest_not_a_variable(
85 ! CHECK: hlfir.elemental
86 ! CHECK: %[[VAL_16:.*]] = hlfir.elemental
87 ! CHECK: %[[VAL_20:.*]] = arith.constant 1 : index
88 ! CHECK: fir.do_loop %[[VAL_21:.*]] = {{.*}}
89 ! CHECK: %[[VAL_22:.*]] = hlfir.apply %[[VAL_16]], %[[VAL_21]] : (!hlfir.expr<?xi64>, index) -> i64
90 ! CHECK: %[[VAL_23:.*]]:3 = hlfir.associate %[[VAL_22]] {adapt.valuebyref} : (i64) -> (!fir.ref<i64>, !fir.ref<i64>, i1)
91 ! CHECK: fir.call @_QPfoo2(%[[VAL_23]]#1){{.*}}: (!fir.ref<i64>) -> ()
92 ! CHECK: hlfir.end_associate %[[VAL_23]]#1, %[[VAL_23]]#2 : !fir.ref<i64>, i1
93 ! CHECK: }