1 // Test hlfir.transpose operation parse, verify (no errors), and unparse
3 // RUN: fir-opt %s | fir-opt | FileCheck %s
5 // square matrix of known shape
6 func.func @transpose0(%arg0: !hlfir.expr<2x2xi32>) {
7 %res = hlfir.transpose %arg0 : (!hlfir.expr<2x2xi32>) -> !hlfir.expr<2x2xi32>
10 // CHECK-LABEL: func.func @transpose0
11 // CHECK: %[[ARG0:.*]]: !hlfir.expr<2x2xi32>
12 // CHECK-NEXT: %[[RES:.*]] = hlfir.transpose %[[ARG0]] : (!hlfir.expr<2x2xi32>) -> !hlfir.expr<2x2xi32>
16 // rectangular matrix of known shape
17 func.func @transpose1(%arg0: !hlfir.expr<2x3xi32>) {
18 %res = hlfir.transpose %arg0 : (!hlfir.expr<2x3xi32>) -> !hlfir.expr<3x2xi32>
21 // CHECK-LABEL: func.func @transpose1
22 // CHECK: %[[ARG0:.*]]: !hlfir.expr<2x3xi32>
23 // CHECK-NEXT: %[[RES:.*]] = hlfir.transpose %[[ARG0]] : (!hlfir.expr<2x3xi32>) -> !hlfir.expr<3x2xi32>
27 // matrix of assumed shape
28 func.func @transpose2(%arg0: !hlfir.expr<?x?xi32>) {
29 %res = hlfir.transpose %arg0 : (!hlfir.expr<?x?xi32>) -> !hlfir.expr<?x?xi32>
32 // CHECK-LABEL: func.func @transpose2
33 // CHECK: %[[ARG0:.*]]: !hlfir.expr<?x?xi32>
34 // CHECK-NEXT: %[[RES:.*]] = hlfir.transpose %[[ARG0]] : (!hlfir.expr<?x?xi32>) -> !hlfir.expr<?x?xi32>
38 // matrix where only some dimensions are known #1
39 func.func @transpose3(%arg0: !hlfir.expr<?x2xi32>) {
40 %res = hlfir.transpose %arg0 : (!hlfir.expr<?x2xi32>) -> !hlfir.expr<2x?xi32>
43 // CHECK-LABEL: func.func @transpose3
44 // CHECK: %[[ARG0:.*]]: !hlfir.expr<?x2xi32>
45 // CHECK-NEXT: %[[RES:.*]] = hlfir.transpose %[[ARG0]] : (!hlfir.expr<?x2xi32>) -> !hlfir.expr<2x?xi32>
49 // matrix where only some dimensions are known #2
50 func.func @transpose4(%arg0: !hlfir.expr<2x?xi32>) {
51 %res = hlfir.transpose %arg0 : (!hlfir.expr<2x?xi32>) -> !hlfir.expr<?x2xi32>
54 // CHECK-LABEL: func.func @transpose4
55 // CHECK: %[[ARG0:.*]]: !hlfir.expr<2x?xi32>
56 // CHECK-NEXT: %[[RES:.*]] = hlfir.transpose %[[ARG0]] : (!hlfir.expr<2x?xi32>) -> !hlfir.expr<?x2xi32>
60 // matrix is a boxed array
61 func.func @transpose5(%arg0: !fir.box<!fir.array<1x2xi32>>) {
62 %res = hlfir.transpose %arg0 : (!fir.box<!fir.array<1x2xi32>>) -> !hlfir.expr<2x1xi32>
65 // CHECK-LABEL: func.func @transpose5
66 // CHECK: %[[ARG0:.*]]: !fir.box<!fir.array<1x2xi32>>
67 // CHECK-NEXT: %[[RES:.*]] = hlfir.transpose %[[ARG0]] : (!fir.box<!fir.array<1x2xi32>>) -> !hlfir.expr<2x1xi32>