| 1 |
// Test hlfir.shape_of operation parse, verify (no errors), and unparse |
| 2 |
// RUN: fir-opt %s | fir-opt | FileCheck --check-prefix CHECK --check-prefix CHECK-ALL %s |
| 3 |
|
| 4 |
// Test canonicalization |
| 5 |
// RUN: fir-opt %s --canonicalize | FileCheck --check-prefix CHECK-CANON --check-prefix CHECK-ALL %s |
| 6 |
|
| 7 |
func.func @shapeof(%arg0: !hlfir.expr<2x2xi32>) -> !fir.shape<2> { |
| 8 |
%shape = hlfir.shape_of %arg0 : (!hlfir.expr<2x2xi32>) -> !fir.shape<2> |
| 9 |
return %shape : !fir.shape<2> |
| 10 |
} |
| 11 |
// CHECK-ALL-LABEL: func.func @shapeof |
| 12 |
// CHECK-ALL: %[[EXPR:.*]]: !hlfir.expr<2x2xi32> |
| 13 |
|
| 14 |
// CHECK-NEXT: %[[SHAPE:.*]] = hlfir.shape_of %[[EXPR]] : (!hlfir.expr<2x2xi32>) -> !fir.shape<2> |
| 15 |
|
| 16 |
// CHECK-CANON-NEXT: %[[C2:.*]] = arith.constant 2 : index |
| 17 |
// CHECK-CANON-NEXT: %[[SHAPE:.*]] = fir.shape %[[C2]], %[[C2]] : (index, index) -> !fir.shape<2> |
| 18 |
|
| 19 |
// CHECK-ALL-NEXT: return %[[SHAPE]] |
| 20 |
|
| 21 |
// no canonicalization of expressions with unknown extents |
| 22 |
func.func @shapeof2(%arg0: !hlfir.expr<?x2xi32>) -> !fir.shape<2> { |
| 23 |
%shape = hlfir.shape_of %arg0 : (!hlfir.expr<?x2xi32>) -> !fir.shape<2> |
| 24 |
return %shape : !fir.shape<2> |
| 25 |
} |
| 26 |
// CHECK-ALL-LABEL: func.func @shapeof2 |
| 27 |
// CHECK-ALL: %[[EXPR:.*]]: !hlfir.expr<?x2xi32> |
| 28 |
// CHECK-ALL-NEXT: %[[SHAPE:.*]] = hlfir.shape_of %[[EXPR]] : (!hlfir.expr<?x2xi32>) -> !fir.shape<2> |
| 29 |
// CHECK-ALL-NEXT: return %[[SHAPE]] |