1 // Test hlfir.product operation parse, verify (no errors), and unparse
3 // RUN: fir-opt %s | fir-opt | FileCheck %s
5 // array is an expression of known shape
6 func.func @product0(%arg0: !hlfir.expr<42xi32>) {
7 %mask = fir.alloca !fir.logical<4>
8 %c_1 = arith.constant 1 : index
9 %true = arith.constant true
10 %true_logical = fir.convert %true : (i1) -> !fir.logical<4>
11 fir.store %true_logical to %mask : !fir.ref<!fir.logical<4>>
12 %mask_box = fir.embox %mask : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
13 %0 = hlfir.product %arg0 dim %c_1 mask %mask_box : (!hlfir.expr<42xi32>, index, !fir.box<!fir.logical<4>>) -> i32
16 // CHECK: func.func @product0(%[[ARRAY:.*]]: !hlfir.expr<42xi32>) {
17 // CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4>
18 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
19 // CHECK-NEXT: %[[TRUE:.*]] = arith.constant true
20 // CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4>
21 // CHECK-NEXT: fir.store %[[LOGICAL]] to %[[MASK]] : !fir.ref<!fir.logical<4>>
22 // CHECK-NEXT: %[[BOX:.*]] = fir.embox %0 : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
23 // CHECK-NEXT: hlfir.product %[[ARRAY]] dim %[[C1]] mask %[[BOX]] : (!hlfir.expr<42xi32>, index, !fir.box<!fir.logical<4>>) -> i32
27 // array is an expression of assumed shape
28 func.func @product1(%arg0: !hlfir.expr<?xi32>) {
29 %mask = fir.alloca !fir.logical<4>
30 %c_1 = arith.constant 1 : index
31 %true = arith.constant true
32 %true_logical = fir.convert %true : (i1) -> !fir.logical<4>
33 fir.store %true_logical to %mask : !fir.ref<!fir.logical<4>>
34 %mask_box = fir.embox %mask : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
35 %0 = hlfir.product %arg0 dim %c_1 mask %mask_box : (!hlfir.expr<?xi32>, index, !fir.box<!fir.logical<4>>) -> i32
38 // CHECK: func.func @product1(%[[ARRAY:.*]]: !hlfir.expr<?xi32>) {
39 // CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4>
40 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
41 // CHECK-NEXT: %[[TRUE:.*]] = arith.constant true
42 // CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4>
43 // CHECK-NEXT: fir.store %[[LOGICAL:.*]] to %[[MASK:.*]] : !fir.ref<!fir.logical<4>>
44 // CHECK-NEXT: %[[BOX:.*]] = fir.embox %[[MASK:.*]] : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
45 // CHECK-NEXT: hlfir.product %[[ARRAY:.*]] dim %[[C1]] mask %[[BOX]] : (!hlfir.expr<?xi32>, index, !fir.box<!fir.logical<4>>) -> i32
50 func.func @product2(%arg0: !fir.box<!fir.array<42xi32>>) {
51 %mask = fir.alloca !fir.logical<4>
52 %c_1 = arith.constant 1 : index
53 %true = arith.constant true
54 %true_logical = fir.convert %true : (i1) -> !fir.logical<4>
55 fir.store %true_logical to %mask : !fir.ref<!fir.logical<4>>
56 %mask_box = fir.embox %mask : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
57 %0 = hlfir.product %arg0 dim %c_1 mask %mask_box : (!fir.box<!fir.array<42xi32>>, index, !fir.box<!fir.logical<4>>) -> i32
60 // CHECK: func.func @product2(%[[ARRAY:.*]]: !fir.box<!fir.array<42xi32>>) {
61 // CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4>
62 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
63 // CHECK-NEXT: %[[TRUE:.*]] = arith.constant true
64 // CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4>
65 // CHECK-NEXT: fir.store %[[LOGICAL:.*]] to %[[MASK:.*]] : !fir.ref<!fir.logical<4>>
66 // CHECK-NEXT: %[[BOX:.*]] = fir.embox %[[MASK:.*]] : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
67 // CHECK-NEXT: hlfir.product %[[ARRAY:.*]] dim %[[C1]] mask %[[BOX]] : (!fir.box<!fir.array<42xi32>>, index, !fir.box<!fir.logical<4>>) -> i32
71 // assumed shape boxed array
72 func.func @product3(%arg0: !fir.box<!fir.array<?xi32>>) {
73 %mask = fir.alloca !fir.logical<4>
74 %c_1 = arith.constant 1 : index
75 %true = arith.constant true
76 %true_logical = fir.convert %true : (i1) -> !fir.logical<4>
77 fir.store %true_logical to %mask : !fir.ref<!fir.logical<4>>
78 %mask_box = fir.embox %mask : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
79 %0 = hlfir.product %arg0 dim %c_1 mask %mask_box : (!fir.box<!fir.array<?xi32>>, index, !fir.box<!fir.logical<4>>) -> i32
82 // CHECK: func.func @product3(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>) {
83 // CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4>
84 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
85 // CHECK-NEXT: %[[TRUE:.*]] = arith.constant true
86 // CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4>
87 // CHECK-NEXT: fir.store %[[LOGICAL:.*]] to %[[MASK:.*]] : !fir.ref<!fir.logical<4>>
88 // CHECK-NEXT: %[[BOX:.*]] = fir.embox %[[MASK:.*]] : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
89 // CHECK-NEXT: hlfir.product %[[ARRAY:.*]] dim %[[C1]] mask %[[BOX]] : (!fir.box<!fir.array<?xi32>>, index, !fir.box<!fir.logical<4>>) -> i32
93 // known shape expr mask
94 func.func @product4(%arg0: !fir.box<!fir.array<?xi32>>, %arg1: !hlfir.expr<42x!fir.logical<4>>) {
95 %c_1 = arith.constant 1 : index
96 %0 = hlfir.product %arg0 dim %c_1 mask %arg1 : (!fir.box<!fir.array<?xi32>>, index, !hlfir.expr<42x!fir.logical<4>>) -> i32
99 // CHECK: func.func @product4(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>, %[[MASK:.*]]: !hlfir.expr<42x!fir.logical<4>>) {
100 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
101 // CHECK-NEXT: hlfir.product %[[ARRAY]] dim %[[C1]] mask %[[MASK]] : (!fir.box<!fir.array<?xi32>>, index, !hlfir.expr<42x!fir.logical<4>>) -> i32
102 // CHECK-NEXT: return
105 // assumed shape expr mask
106 func.func @product5(%arg0: !fir.box<!fir.array<?xi32>>, %arg1: !hlfir.expr<?x!fir.logical<4>>) {
107 %c_1 = arith.constant 1 : index
108 %0 = hlfir.product %arg0 dim %c_1 mask %arg1 : (!fir.box<!fir.array<?xi32>>, index, !hlfir.expr<?x!fir.logical<4>>) -> i32
111 // CHECK: func.func @product5(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>, %[[MASK:.*]]: !hlfir.expr<?x!fir.logical<4>>) {
112 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
113 // CHECK-NEXT: hlfir.product %[[ARRAY]] dim %[[C1]] mask %[[MASK]] : (!fir.box<!fir.array<?xi32>>, index, !hlfir.expr<?x!fir.logical<4>>) -> i32
114 // CHECK-NEXT: return
117 // known shape array mask
118 func.func @product6(%arg0: !fir.box<!fir.array<?xi32>>, %arg1: !fir.box<!fir.array<42x!fir.logical<4>>>) {
119 %c_1 = arith.constant 1 : index
120 %0 = hlfir.product %arg0 dim %c_1 mask %arg1 : (!fir.box<!fir.array<?xi32>>, index, !fir.box<!fir.array<42x!fir.logical<4>>>) -> i32
123 // CHECK: func.func @product6(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>, %[[MASK:.*]]: !fir.box<!fir.array<42x!fir.logical<4>>>) {
124 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
125 // CHECK-NEXT: hlfir.product %[[ARRAY]] dim %[[C1]] mask %[[MASK]] : (!fir.box<!fir.array<?xi32>>, index, !fir.box<!fir.array<42x!fir.logical<4>>>) -> i32
126 // CHECK-NEXT: return
129 // assumed shape array mask
130 func.func @product7(%arg0: !fir.box<!fir.array<?xi32>>, %arg1: !fir.box<!fir.array<?x!fir.logical<4>>>) {
131 %c_1 = arith.constant 1 : index
132 %0 = hlfir.product %arg0 dim %c_1 mask %arg1 : (!fir.box<!fir.array<?xi32>>, index, !fir.box<!fir.array<?x!fir.logical<4>>>) -> i32
135 // CHECK: func.func @product7(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>, %[[MASK:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>>) {
136 // CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
137 // CHECK-NEXT: hlfir.product %[[ARRAY]] dim %[[C1]] mask %[[MASK]] : (!fir.box<!fir.array<?xi32>>, index, !fir.box<!fir.array<?x!fir.logical<4>>>) -> i32
138 // CHECK-NEXT: return
141 // known shape expr return
142 func.func @product8(%arg0: !fir.box<!fir.array<2x2xi32>>, %arg1: i32) {
143 %mask = fir.alloca !fir.logical<4>
144 %true = arith.constant true
145 %true_logical = fir.convert %true : (i1) -> !fir.logical<4>
146 fir.store %true_logical to %mask : !fir.ref<!fir.logical<4>>
147 %mask_box = fir.embox %mask : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
148 %0 = hlfir.product %arg0 dim %arg1 mask %mask_box : (!fir.box<!fir.array<2x2xi32>>, i32, !fir.box<!fir.logical<4>>) -> !hlfir.expr<2xi32>
151 // CHECK: func.func @product8(%[[ARRAY:.*]]: !fir.box<!fir.array<2x2xi32>>, %[[DIM:.*]]: i32) {
152 // CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4>
153 // CHECK-NEXT: %[[TRUE:.*]] = arith.constant true
154 // CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4>
155 // CHECK-NEXT: fir.store %[[LOGICAL]] to %[[MASK]] : !fir.ref<!fir.logical<4>>
156 // CHECK-NEXT: %[[BOX:.*]] = fir.embox %0 : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
157 // CHECK-NEXT: hlfir.product %[[ARRAY]] dim %[[DIM]] mask %[[BOX]] : (!fir.box<!fir.array<2x2xi32>>, i32, !fir.box<!fir.logical<4>>) -> !hlfir.expr<2xi32>
158 // CHECK-NEXT: return
162 // assumed shape expr return
163 func.func @product9(%arg0: !fir.box<!fir.array<?x?xi32>>, %arg1: i32) {
164 %mask = fir.alloca !fir.logical<4>
165 %true = arith.constant true
166 %true_logical = fir.convert %true : (i1) -> !fir.logical<4>
167 fir.store %true_logical to %mask : !fir.ref<!fir.logical<4>>
168 %mask_box = fir.embox %mask : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
169 %0 = hlfir.product %arg0 dim %arg1 mask %mask_box : (!fir.box<!fir.array<?x?xi32>>, i32, !fir.box<!fir.logical<4>>) -> !hlfir.expr<?xi32>
172 // CHECK: func.func @product9(%[[ARRAY:.*]]: !fir.box<!fir.array<?x?xi32>>, %[[DIM:.*]]: i32) {
173 // CHECK-NEXT: %[[MASK:.*]] = fir.alloca !fir.logical<4>
174 // CHECK-NEXT: %[[TRUE:.*]] = arith.constant true
175 // CHECK-NEXT: %[[LOGICAL:.*]] = fir.convert %[[TRUE]] : (i1) -> !fir.logical<4>
176 // CHECK-NEXT: fir.store %[[LOGICAL]] to %[[MASK]] : !fir.ref<!fir.logical<4>>
177 // CHECK-NEXT: %[[BOX:.*]] = fir.embox %0 : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
178 // CHECK-NEXT: hlfir.product %[[ARRAY]] dim %[[DIM]] mask %[[BOX]] : (!fir.box<!fir.array<?x?xi32>>, i32, !fir.box<!fir.logical<4>>) -> !hlfir.expr<?xi32>
179 // CHECK-NEXT: return
182 // hlfir.product with only an array argument
183 func.func @product10(%arg0: !fir.box<!fir.array<?x?xi32>>) {
184 %product = hlfir.product %arg0 : (!fir.box<!fir.array<?x?xi32>>) -> i32
187 // CHECK: func.func @product10(%[[ARRAY:.*]]: !fir.box<!fir.array<?x?xi32>>
188 // CHECK-NEXT: %[[PRODUCT:.*]] = hlfir.product %[[ARRAY]] : (!fir.box<!fir.array<?x?xi32>>) -> i32
189 // CHECK-NEXT: return
192 // hlfir.product with array and dim argument
193 func.func @product11(%arg0: !fir.box<!fir.array<?x?xi32>>, %arg1: i32) {
194 %product = hlfir.product %arg0 dim %arg1 : (!fir.box<!fir.array<?x?xi32>>, i32) -> !hlfir.expr<?xi32>
197 // CHECK: func.func @product11(%[[ARRAY:.*]]: !fir.box<!fir.array<?x?xi32>>, %[[DIM:.*]]: i32
198 // CHECK-NEXT: %[[PRODUCT:.*]] = hlfir.product %[[ARRAY]] dim %[[DIM]] : (!fir.box<!fir.array<?x?xi32>>, i32) -> !hlfir.expr<?xi32>
199 // CHECK-NEXT: return
202 // hlfir.product with array and mask argument
203 func.func @product12(%arg0: !fir.box<!fir.array<?xi32>>, %arg1: !fir.logical<4>) {
204 %product = hlfir.product %arg0 mask %arg1 : (!fir.box<!fir.array<?xi32>>, !fir.logical<4>) -> i32
207 // CHECK: func.func @product12(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>, %[[MASK:.*]]: !fir.logical<4>
208 // CHECK-NEXT: %[[PRODUCT:.*]] = hlfir.product %[[ARRAY]] mask %[[MASK]] : (!fir.box<!fir.array<?xi32>>, !fir.logical<4>) -> i32
209 // CHECK-NEXT: return
212 // hlfir.product with dim argument with an unusual type
213 func.func @product13(%arg0: !fir.box<!fir.array<?x?xi32>>, %arg1: index) {
214 %product = hlfir.product %arg0 dim %arg1 : (!fir.box<!fir.array<?x?xi32>>, index) -> !hlfir.expr<?xi32>
217 // CHECK: func.func @product13(%[[ARRAY:.*]]: !fir.box<!fir.array<?x?xi32>>, %[[DIM:.*]]: index
218 // CHECK-NEXT: %[[PRODUCT:.*]] = hlfir.product %[[ARRAY]] dim %[[DIM]] : (!fir.box<!fir.array<?x?xi32>>, index) -> !hlfir.expr<?xi32>
219 // CHECK-NEXT: return
222 // hlfir.product with mask argument of unusual type
223 func.func @product14(%arg0: !fir.box<!fir.array<?xi32>>, %arg1: i1) {
224 %product = hlfir.product %arg0 mask %arg1 : (!fir.box<!fir.array<?xi32>>, i1) -> i32
227 // CHECK: func.func @product14(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>, %[[MASK:.*]]: i1
228 // CHECK-NEXT: %[[PRODUCT:.*]] = hlfir.product %[[ARRAY]] mask %[[MASK]] : (!fir.box<!fir.array<?xi32>>, i1) -> i32
229 // CHECK-NEXT: return
232 // hlfir.product with mask argument of ref<array<>> type
233 func.func @product15(%arg0: !fir.box<!fir.array<?xi32>>, %arg1: !fir.ref<!fir.array<?x!fir.logical<4>>>) {
234 %product = hlfir.product %arg0 mask %arg1 : (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?x!fir.logical<4>>>) -> i32
237 // CHECK: func.func @product15(%[[ARRAY:.*]]: !fir.box<!fir.array<?xi32>>, %[[MASK:.*]]: !fir.ref<!fir.array<?x!fir.logical<4>>>
238 // CHECK-NEXT: %[[PRODUCT:.*]] = hlfir.product %[[ARRAY]] mask %[[MASK]] : (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?x!fir.logical<4>>>) -> i32
239 // CHECK-NEXT: return