48 lines · plain
1// Test hlfir.shape_of operation parse, verify (no errors), and unparse2// RUN: fir-opt %s | fir-opt | FileCheck --check-prefix CHECK --check-prefix CHECK-ALL %s3 4// Test canonicalization5// RUN: fir-opt %s --canonicalize | FileCheck --check-prefix CHECK-CANON --check-prefix CHECK-ALL %s6 7func.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 @shapeof12// 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 : index17// 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 extents22func.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 @shapeof227// 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]]30 31// Checks hlfir.elemental -> hlfir.shape_of folding32func.func @shapeof_fold1(%extent: index) -> !fir.shape<1> {33 %shape1 = fir.shape %extent : (index) -> !fir.shape<1>34 %elem = hlfir.elemental %shape1 : (!fir.shape<1>) -> !hlfir.expr<?xindex> {35 hlfir.yield_element %extent : index36 }37 %shape2 = hlfir.shape_of %elem : (!hlfir.expr<?xindex>) -> !fir.shape<1>38 return %shape2 : !fir.shape<1>39}40// CHECK-ALL-LABEL: func.func @shapeof_fold1(41// CHECK-ALL-SAME: %[[VAL_0:.*]]: index) -> !fir.shape<1> {42// CHECK-CANON-NEXT: %[[VAL_1:.*]] = fir.shape %[[VAL_0]] : (index) -> !fir.shape<1>43// CHECK-CANON-NEXT: %[[VAL_2:.*]] = hlfir.elemental %[[VAL_1]] : (!fir.shape<1>) -> !hlfir.expr<?xindex> {44// CHECK-CANON-NEXT: hlfir.yield_element %[[VAL_0]] : index45// CHECK-CANON-NEXT: }46// CHECK-CANON-NEXT: return %[[VAL_1]] : !fir.shape<1>47// CHECK-CANON-NEXT: }48