[OpenMP] Adjust 'printf' handling in the OpenMP runtime (#123670)
[llvm-project.git] / flang / test / Lower / HLFIR / matmul.f90
blob298dd2b800636fc29a609a7b88d083978c0f43b0
1 ! Test lowering of MATMUL intrinsic to HLFIR
2 ! RUN: bbc -emit-hlfir -o - %s 2>&1 | FileCheck %s
4 subroutine matmul1(lhs, rhs, res)
5 integer :: lhs(:,:), rhs(:,:), res(:,:)
6 res = MATMUL(lhs, rhs)
7 endsubroutine
8 ! CHECK-LABEL: func.func @_QPmatmul1
9 ! CHECK: %[[LHS:.*]]: !fir.box<!fir.array<?x?xi32>> {fir.bindc_name = "lhs"}
10 ! CHECK: %[[RHS:.*]]: !fir.box<!fir.array<?x?xi32>> {fir.bindc_name = "rhs"}
11 ! CHECK: %[[RES:.*]]: !fir.box<!fir.array<?x?xi32>> {fir.bindc_name = "res"}
12 ! CHECK-DAG: %[[LHS_VAR:.*]]:2 = hlfir.declare %[[LHS]]
13 ! CHECK-DAG: %[[RHS_VAR:.*]]:2 = hlfir.declare %[[RHS]]
14 ! CHECK-DAG: %[[RES_VAR:.*]]:2 = hlfir.declare %[[RES]]
15 ! CHECK-NEXT: %[[EXPR:.*]] = hlfir.matmul %[[LHS_VAR]]#0 %[[RHS_VAR]]#0 {fastmath = #arith.fastmath<contract>} : (!fir.box<!fir.array<?x?xi32>>, !fir.box<!fir.array<?x?xi32>>) -> !hlfir.expr<?x?xi32>
16 ! CHECK-NEXT: hlfir.assign %[[EXPR]] to %[[RES_VAR]]#0 : !hlfir.expr<?x?xi32>, !fir.box<!fir.array<?x?xi32>>
17 ! CHECK-NEXT: hlfir.destroy %[[EXPR]]
18 ! CHECK-NEXT: return
19 ! CHECK-NEXT: }
21 ! regression test for a case where the AST and FIR have different amounts of
22 ! shape inference
23 subroutine matmul2(c)
24 integer, parameter :: N = 4
25 integer, dimension(:,:), allocatable :: a, b, c
26 integer, dimension(N,N) :: x
28 allocate(a(3*N, N), b(N, N), c(3*N, N))
30 call fill(a)
31 call fill(b)
32 call fill(x)
34 c = matmul(a, b - x)
35 endsubroutine
36 ! CHECK-LABEL: func.func @_QPmatmul2
37 ! CHECK: %[[C_ARG:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>
38 ! CHECK: %[[B_BOX_ALLOC:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x?xi32>>> {bindc_name = "b"
39 ! CHECK: %[[B_BOX_DECL:.*]]:2 = hlfir.declare %[[B_BOX_ALLOC]] {{.*}} uniq_name = "_QFmatmul2Eb"
42 ! CHECK: fir.call @_QPfill
43 ! CHECK: fir.call @_QPfill
44 ! CHECK: fir.call @_QPfill
45 ! CHECK-NEXT: %[[B_BOX:.*]] = fir.load %[[B_BOX_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>
46 ! CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : index
47 ! CHECK-NEXT: %[[B_DIMS_0:.*]]:3 = fir.box_dims %[[B_BOX]], %[[C0]]
48 ! CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index
49 ! CHECK-NEXT: %[[B_DIMS_1:.*]]:3 = fir.box_dims %[[B_BOX]], %[[C1]]
50 ! CHECK-NEXT: %[[B_SHAPE:.*]] = fir.shape %[[B_DIMS_0]]#1, %[[B_DIMS_1]]#1
51 ! CHECK-NEXT: %[[ELEMENTAL:.*]] = hlfir.elemental %[[B_SHAPE]] unordered : (!fir.shape<2>) -> !hlfir.expr<?x?xi32> {
53 ! CHECK: }
54 ! CHECK-NEXT: %[[A_BOX:.*]] = fir.load %{{.*}} : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>
56 ! The shapes in these types are what is being tested:
57 ! CHECK-NEXT: %[[MATMUL:.*]] = hlfir.matmul %[[A_BOX]] %[[ELEMENTAL]] {{.*}} : (!fir.box<!fir.heap<!fir.array<?x?xi32>>>, !hlfir.expr<?x?xi32>) -> !hlfir.expr<?x4xi32>
59 subroutine matmul3(lhs, rhs, res)
60 integer, allocatable :: lhs(:,:), rhs(:,:), res(:,:)
61 res = MATMUL(lhs, rhs)
62 endsubroutine
63 ! CHECK-LABEL: func.func @_QPmatmul3
64 ! CHECK: %[[LHS:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> {fir.bindc_name = "lhs"}
65 ! CHECK: %[[RHS:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> {fir.bindc_name = "rhs"}
66 ! CHECK: %[[RES:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> {fir.bindc_name = "res"}
67 ! CHECK-DAG: %[[LHS_VAR:.*]]:2 = hlfir.declare %[[LHS]]
68 ! CHECK-DAG: %[[RHS_VAR:.*]]:2 = hlfir.declare %[[RHS]]
69 ! CHECK-DAG: %[[RES_VAR:.*]]:2 = hlfir.declare %[[RES]]
70 ! CHECK-NEXT: %[[LHS_LD:.*]] = fir.load %[[LHS_VAR]]#0
71 ! CHECK-NEXT: %[[RHS_LD:.*]] = fir.load %[[RHS_VAR]]#0
72 ! CHECK-NEXT: %[[EXPR:.*]] = hlfir.matmul %[[LHS_LD]] %[[RHS_LD]] {fastmath = #arith.fastmath<contract>} : (!fir.box<!fir.heap<!fir.array<?x?xi32>>>, !fir.box<!fir.heap<!fir.array<?x?xi32>>>) -> !hlfir.expr<?x?xi32>
73 ! CHECK-NEXT: hlfir.assign %[[EXPR]] to %[[RES_VAR]]#0 realloc : !hlfir.expr<?x?xi32>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>
74 ! CHECK-NEXT: hlfir.destroy %[[EXPR]]
75 ! CHECK-NEXT: return
76 ! CHECK-NEXT: }