| 1 |
// Test hlfir.shape_of lowering |
| 2 |
// RUN: fir-opt %s -bufferize-hlfir | FileCheck %s |
| 3 |
|
| 4 |
func.func @shapeof_asexpr(%arg0: !fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.shape<1> { |
| 5 |
%c0 = arith.constant 0 : index |
| 6 |
%59:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index) |
| 7 |
%60 = fir.box_addr %arg0 : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>> |
| 8 |
%61 = fir.shape_shift %59#0, %59#1 : (index, index) -> !fir.shapeshift<1> |
| 9 |
%62:2 = hlfir.declare %60(%61) {uniq_name = ".tmp.intrinsic_result"} : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.heap<!fir.array<?xf32>>) |
| 10 |
%true = arith.constant true |
| 11 |
%63 = hlfir.as_expr %62#0 move %true : (!fir.box<!fir.array<?xf32>>, i1) -> !hlfir.expr<?xf32> |
| 12 |
%64 = hlfir.shape_of %63 : (!hlfir.expr<?xf32>) -> !fir.shape<1> |
| 13 |
return %64 : !fir.shape<1> |
| 14 |
} |
| 15 |
// CHECK-LABEL: @shapeof_asexpr |
| 16 |
// CHECK: %[[ARG0:.*]]: !fir.box<!fir.heap<!fir.array<?xf32>>> |
| 17 |
// CHECK-NEXT: %[[C0:.*]] = arith.constant 0 |
| 18 |
// CHECK-NEXT: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[ARG0]], %[[C0]] |
| 19 |
// CHECK-NEXT: %[[BOX_ADDR:.*]] = fir.box_addr %[[ARG0]] |
| 20 |
// CHECK-NEXT: %[[SHPE_SHFT:.*]] = fir.shape_shift %[[BOX_DIMS]]#0, %[[BOX_DIMS]]#1 |
| 21 |
// CHECK-NEXT: %[[VAR:.*]]:2 = hlfir.declare %[[BOX_ADDR]](%[[SHPE_SHFT]]) |
| 22 |
// CHECK-NEXT: %[[TRUE:.*]] = arith.constant true |
| 23 |
// CHECK-NEXT: %[[TUPLE0:.*]] = fir.undefined tuple |
| 24 |
// CHECK-NEXT: %[[TUPLE1:.*]] = fir.insert_value %[[TUPLE0]], %[[TRUE]] |
| 25 |
// CHECK-NEXT: %[[TUPLE2:.*]] = fir.insert_value %[[TUPLE1]], %[[VAR]]#0 |
| 26 |
// CHECK-NEXT: %[[SHAPE:.*]] = fir.shape %[[BOX_DIMS]]#1 |
| 27 |
// CHECK-NEXT: return %[[SHAPE]] |
| 28 |
|
| 29 |
func.func @shapeof_elemental() -> !fir.shape<1> { |
| 30 |
%c1 = arith.constant 1 : index |
| 31 |
%0 = fir.shape %c1 : (index) -> !fir.shape<1> |
| 32 |
%1 = hlfir.elemental %0 : (!fir.shape<1>) -> !hlfir.expr<?xindex> { |
| 33 |
^bb0(%arg3: index): |
| 34 |
hlfir.yield_element %arg3 : index |
| 35 |
} |
| 36 |
%2 = hlfir.shape_of %1 : (!hlfir.expr<?xindex>) -> !fir.shape<1> |
| 37 |
return %2 : !fir.shape<1> |
| 38 |
} |
| 39 |
// CHECK-LABEL: @shapeof_elemental |
| 40 |
// CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 41 |
// CHECK-NEXT: %[[SHAPE:.*]] = fir.shape %[[C1]] |
| 42 |
// CHECK: fir.do_loop %{{.*}} = %{{.*}} to %[[C1:.*]] |
| 43 |
// CHECK: return %[[SHAPE]] |
| 44 |
|
| 45 |
func.func @shapeof_fallback(%arg0: !hlfir.expr<1x2x3xi32>) -> !fir.shape<3> { |
| 46 |
%shape = hlfir.shape_of %arg0 : (!hlfir.expr<1x2x3xi32>) -> !fir.shape<3> |
| 47 |
return %shape : !fir.shape<3> |
| 48 |
} |
| 49 |
// CHECK-LABEL: @shapeof_fallback |
| 50 |
// CHECK: %[[EXPR:.*]]: !hlfir.expr<1x2x3xi32> |
| 51 |
// CHECK-NEXT: %[[C1:.*]] = arith.constant 1 : index |
| 52 |
// CHECK-NEXT: %[[C2:.*]] = arith.constant 2 : index |
| 53 |
// CHECK-NEXT: %[[C3:.*]] = arith.constant 3 : index |
| 54 |
// CHECK-NEXT: %[[SHAPE:.*]] = fir.shape %[[C1]], %[[C2]], %[[C3]] : |
| 55 |
// CHECK-NEXT: return %[[SHAPE]] |