Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / Intrinsics / minloc.f90
blob06dcf04cc58adcdbfcc7e02b11c382bbc90bd28b
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
3 ! CHECK-LABEL: func @_QPminloc_test(
4 ! CHECK-SAME: %[[arg0:.*]]: !fir.box<!fir.array<?xi32>>{{.*}}, %[[arg1:.*]]: !fir.box<!fir.array<?xi32>>
5 subroutine minloc_test(arr,res)
6 integer :: arr(:)
7 integer :: res(:)
8 ! CHECK-DAG: %[[c4:.*]] = arith.constant 4 : index
9 ! CHECK-DAG: %[[a0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>>
10 ! CHECK-DAG: %[[a1:.*]] = fir.absent !fir.box<i1>
11 ! CHECK-DAG: %[[a6:.*]] = fir.convert %[[a0]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<none>>
12 ! CHECK-DAG: %[[a7:.*]] = fir.convert %[[arg0]] : (!fir.box<!fir.array<?xi32>>) -> !fir.box<none>
13 ! CHECK-DAG: %[[a8:.*]] = fir.convert %[[c4]] : (index) -> i32
14 ! CHECK-DAG: %[[a10:.*]] = fir.convert %[[a1]] : (!fir.box<i1>) -> !fir.box<none>
15 res = minloc(arr)
16 ! CHECK: %{{.*}} = fir.call @_FortranAMinlocInteger4(%[[a6]], %[[a7]], %[[a8]], %{{.*}}, %{{.*}}, %[[a10]], %false) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, i32, !fir.ref<i8>, i32, !fir.box<none>, i1) -> none
17 ! CHECK-DAG: %[[a12:.*]] = fir.load %[[a0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
18 ! CHECK-DAG: %[[a14:.*]] = fir.box_addr %[[a12]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
19 ! CHECK-DAG: fir.freemem %[[a14]]
20 end subroutine
22 ! CHECK-LABEL: func @_QPminloc_test2(
23 ! CHECK-SAME: %[[arg0:.*]]: !fir.box<!fir.array<?xi32>>{{.*}}, %[[arg1:.*]]: !fir.box<!fir.array<?xi32>>{{.*}}, %[[arg2:.*]]: !fir.ref<i32>
24 subroutine minloc_test2(arr,res,d)
25 integer :: arr(:)
26 integer :: res(:)
27 integer :: d
28 ! CHECK-DAG: %[[c4:.*]] = arith.constant 4 : index
29 ! CHECK-DAG: %[[a0:.*]] = fir.alloca !fir.box<!fir.heap<i32>>
30 ! CHECK-DAG: %[[a1:.*]] = fir.load %arg2 : !fir.ref<i32>
31 ! CHECK-DAG: %[[a2:.*]] = fir.absent !fir.box<i1>
32 ! CHECK-DAG: %[[a6:.*]] = fir.convert %[[a0]] : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> !fir.ref<!fir.box<none>>
33 ! CHECK-DAG: %[[a7:.*]] = fir.convert %arg0 : (!fir.box<!fir.array<?xi32>>) -> !fir.box<none>
34 ! CHECK-DAG: %[[a8:.*]] = fir.convert %[[c4]] : (index) -> i32
35 ! CHECK-DAG: %[[a10:.*]] = fir.convert %[[a2]] : (!fir.box<i1>) -> !fir.box<none>
36 res = minloc(arr, dim=d)
37 ! CHECK: %{{.*}} = fir.call @_FortranAMinlocDim(%[[a6]], %[[a7]], %[[a8]], %[[a1]], %{{.*}}, %{{.*}}, %[[a10]], %false) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, i32, i32, !fir.ref<i8>, i32, !fir.box<none>, i1) -> none
38 ! CHECK: %[[a12:.*]] = fir.load %0 : !fir.ref<!fir.box<!fir.heap<i32>>>
39 ! CHECK: %[[a13:.*]] = fir.box_addr %[[a12]] : (!fir.box<!fir.heap<i32>>) -> !fir.heap<i32>
40 ! CHECK: fir.freemem %[[a13]]
41 end subroutine
43 ! CHECK-LABEL: func @_QPtest_minloc_optional_scalar_mask(
44 ! CHECK-SAME: %[[VAL_0:[^:]+]]: !fir.ref<!fir.logical<4>>
45 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.logical<4>>
46 subroutine test_minloc_optional_scalar_mask(mask, back, array)
47 integer :: array(:)
48 logical, optional :: mask
49 logical, optional :: back
50 print *, minloc(array, mask=mask, back=back)
51 ! CHECK: %[[VAL_9:.*]] = fir.is_present %[[VAL_0]] : (!fir.ref<!fir.logical<4>>) -> i1
52 ! CHECK: %[[VAL_10:.*]] = fir.embox %[[VAL_0]] : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
53 ! CHECK: %[[VAL_11:.*]] = fir.absent !fir.box<!fir.logical<4>>
54 ! CHECK: %[[VAL_12:.*]] = arith.select %[[VAL_9]], %[[VAL_10]], %[[VAL_11]] : !fir.box<!fir.logical<4>>
55 ! CHECK: %[[VAL_13:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref<!fir.logical<4>>) -> i1
56 ! CHECK: %[[VAL_14:.*]] = fir.if %[[VAL_13]] -> (!fir.logical<4>) {
57 ! CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.logical<4>>
58 ! CHECK: fir.result %[[VAL_15]] : !fir.logical<4>
59 ! CHECK: } else {
60 ! CHECK: %[[VAL_16:.*]] = arith.constant false
61 ! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i1) -> !fir.logical<4>
62 ! CHECK: fir.result %[[VAL_17]] : !fir.logical<4>
63 ! CHECK: }
64 ! CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_12]] : (!fir.box<!fir.logical<4>>) -> !fir.box<none>
65 ! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_14]] : (!fir.logical<4>) -> i1
66 ! CHECK: fir.call @_FortranAMinlocInteger4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_29]], %[[VAL_30]]) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, i32, !fir.ref<i8>, i32, !fir.box<none>, i1) -> none
67 end subroutine
69 ! CHECK-LABEL: func @_QPtest_minloc_optional_array_mask(
70 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>>
71 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.logical<4>>
72 subroutine test_minloc_optional_array_mask(mask, back, array)
73 integer :: array(:)
74 logical, optional :: mask(:)
75 logical, optional :: back
76 print *, minloc(array, mask=mask, back=back)
77 ! CHECK: %[[VAL_9:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref<!fir.logical<4>>) -> i1
78 ! CHECK: %[[VAL_10:.*]] = fir.if %[[VAL_9]] -> (!fir.logical<4>) {
79 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.logical<4>>
80 ! CHECK: fir.result %[[VAL_11]] : !fir.logical<4>
81 ! CHECK: } else {
82 ! CHECK: %[[VAL_12:.*]] = arith.constant false
83 ! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i1) -> !fir.logical<4>
84 ! CHECK: fir.result %[[VAL_13]] : !fir.logical<4>
85 ! CHECK: }
86 ! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.logical<4>>>) -> !fir.box<none>
87 ! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_10]] : (!fir.logical<4>) -> i1
88 ! CHECK: fir.call @_FortranAMinlocInteger4(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_25]], %[[VAL_26]]) {{.*}}: (!fir.ref<!fir.box<none>>, !fir.box<none>, i32, !fir.ref<i8>, i32, !fir.box<none>, i1) -> none
89 end subroutine