1 ! Test lowering of array constructors as hlfir.elemental.
2 ! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
4 subroutine test_as_simple_elemental(n
)
6 call takes_int([(n
+i
, i
=1,4)])
8 ! CHECK-LABEL: func.func @_QPtest_as_simple_elemental(
9 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}En
10 ! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
11 ! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
12 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i64
13 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i64) -> index
14 ! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
15 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> index
16 ! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
17 ! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<4xi32> {
18 ! CHECK: ^bb0(%[[VAL_10:.*]]: index):
19 ! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %[[VAL_8]] : index
20 ! CHECK: %[[VAL_12:.*]] = arith.muli %[[VAL_11]], %[[VAL_7]] : index
21 ! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_5]], %[[VAL_12]] : index
22 ! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i32>
23 ! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_13]] : (index) -> i32
24 ! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_14]], %[[VAL_15]] : i32
25 ! CHECK: hlfir.yield_element %[[VAL_16]] : i32
28 ! CHECK: hlfir.destroy %[[VAL_9]] : !hlfir.expr<4xi32>
30 subroutine test_as_strided_elemental(lb
, ub
, stride
)
31 integer(8) :: lb
, ub
, stride
32 call takes_int([(i
, i
=lb
,ub
,stride
)])
34 ! CHECK-LABEL: func.func @_QPtest_as_strided_elemental(
35 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}Elb
36 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}Estride
37 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare {{.*}}Eub
38 ! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i64
39 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i64>
40 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
41 ! CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_7]], %[[VAL_8]] : i64
42 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
43 ! CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_9]], %[[VAL_10]] : i64
44 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
45 ! CHECK: %[[VAL_13:.*]] = arith.divsi %[[VAL_11]], %[[VAL_12]] : i64
46 ! CHECK: %[[VAL_14:.*]] = arith.constant 0 : i64
47 ! CHECK: %[[VAL_15:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_14]] : i64
48 ! CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_13]], %[[VAL_14]] : i64
49 ! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_6]], %[[VAL_16]] : i64
50 ! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i64) -> index
51 ! CHECK: %[[VAL_19:.*]] = fir.shape %[[VAL_18]] : (index) -> !fir.shape<1>
52 ! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64>
53 ! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i64) -> index
54 ! CHECK: %[[VAL_22:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i64>
55 ! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (i64) -> index
56 ! CHECK: %[[VAL_24:.*]] = arith.constant 1 : index
57 ! CHECK: %[[VAL_25:.*]] = hlfir.elemental %[[VAL_19]] : (!fir.shape<1>) -> !hlfir.expr<?xi32> {
58 ! CHECK: ^bb0(%[[VAL_26:.*]]: index):
59 ! CHECK: %[[VAL_27:.*]] = arith.subi %[[VAL_26]], %[[VAL_24]] : index
60 ! CHECK: %[[VAL_28:.*]] = arith.muli %[[VAL_27]], %[[VAL_23]] : index
61 ! CHECK: %[[VAL_29:.*]] = arith.addi %[[VAL_21]], %[[VAL_28]] : index
62 ! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (index) -> i32
63 ! CHECK: hlfir.yield_element %[[VAL_30]] : i32
66 ! CHECK: hlfir.destroy %[[VAL_25]] : !hlfir.expr<?xi32>
68 subroutine test_as_elemental_with_pure_call(n
)
70 integer pure
function foo(i
)
75 call takes_int([(foo(i
), i
=1,4)])
77 ! CHECK-LABEL: func.func @_QPtest_as_elemental_with_pure_call(
78 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}) {
79 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_as_elemental_with_pure_callEn"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
80 ! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
81 ! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
82 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i64
83 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i64) -> index
84 ! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i64
85 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : (i64) -> index
86 ! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
87 ! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<4xi32> {
88 ! CHECK: ^bb0(%[[VAL_10:.*]]: index):
89 ! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %[[VAL_8]] : index
90 ! CHECK: %[[VAL_12:.*]] = arith.muli %[[VAL_11]], %[[VAL_7]] : index
91 ! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_5]], %[[VAL_12]] : index
92 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (index) -> i32
93 ! CHECK: %[[VAL_15:.*]] = fir.call @_QPfoo(%[[VAL_14]]) fastmath<contract> : (i32) -> i32
94 ! CHECK: hlfir.yield_element %[[VAL_15]] : i32
97 ! CHECK: hlfir.destroy %[[VAL_9]] : !hlfir.expr<4xi32>
99 ! CHECK-LABEL: func.func @_QPtest_with_impure_call(
100 subroutine test_with_impure_call(n
)
102 integer function impure_foo(i
)
107 call takes_int([(impure_foo(i
), i
=1,4)])
109 ! CHECK-NOT: hlfir.elemental