32 lines · plain
1// RUN: mlir-opt -shape-to-shape-lowering -split-input-file %s | FileCheck %s2 3// CHECK-LABEL: func @num_elements_to_reduce4// CHECK-SAME: ([[ARG:%.*]]: !shape.shape) -> !shape.size5func.func @num_elements_to_reduce(%shape : !shape.shape) -> !shape.size {6 %num_elements = shape.num_elements %shape : !shape.shape -> !shape.size7 return %num_elements : !shape.size8}9// CHECK: [[C1:%.*]] = shape.const_size 110// CHECK: [[NUM_ELEMENTS:%.*]] = shape.reduce([[ARG]], [[C1]]) : !shape.shape -> !shape.size11// CHECK: ^bb0({{.*}}: index, [[DIM:%.*]]: !shape.size, [[ACC:%.*]]: !shape.size12// CHECK: [[NEW_ACC:%.*]] = shape.mul [[DIM]], [[ACC]]13// CHECK: shape.yield [[NEW_ACC]] : !shape.size14// CHECK: }15// CHECK: return [[NUM_ELEMENTS]] : !shape.size16 17// -----18 19// CHECK-LABEL: func @num_elements_to_reduce_on_index20// CHECK-SAME: ([[ARG:%.*]]: tensor<?xindex>) -> index21func.func @num_elements_to_reduce_on_index(%shape : tensor<?xindex>) -> index {22 %num_elements = shape.num_elements %shape : tensor<?xindex> -> index23 return %num_elements : index24}25// CHECK: [[C1:%.*]] = arith.constant 1 : index26// CHECK: [[NUM_ELEMENTS:%.*]] = shape.reduce([[ARG]], [[C1]]) : tensor<?xindex> -> index27// CHECK: ^bb0({{.*}}: index, [[DIM:%.*]]: index, [[ACC:%.*]]: index28// CHECK: [[NEW_ACC:%.*]] = shape.mul [[DIM]], [[ACC]]29// CHECK: shape.yield [[NEW_ACC]] : index30// CHECK: }31// CHECK: return [[NUM_ELEMENTS]] : index32