Integrate LLVM at llvm/llvm-project@eed333149d
Updates LLVM usage to match [eed333149d17](https://github.com/llvm/llvm-project/commit/eed333149d17) PiperOrigin-RevId: 323354988
This commit is contained in:
		
							parent
							
								
									8023baa959
								
							
						
					
					
						commit
						739758f9cc
					
				|  | @ -747,7 +747,8 @@ class DynamicBroadcastInDimOpNotActuallyDynamic | ||||||
| void DynamicBroadcastInDimOp::getCanonicalizationPatterns( | void DynamicBroadcastInDimOp::getCanonicalizationPatterns( | ||||||
|     OwningRewritePatternList& results, MLIRContext* context) { |     OwningRewritePatternList& results, MLIRContext* context) { | ||||||
|   results.insert<DynamicBroadcastInDimOpNotActuallyDynamic, |   results.insert<DynamicBroadcastInDimOpNotActuallyDynamic, | ||||||
|                  DynamicBroadcastToOwnShape>(context); |                  DynamicBroadcastToOwnShape_1, DynamicBroadcastToOwnShape_2>( | ||||||
|  |       context); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //===----------------------------------------------------------------------===//
 | //===----------------------------------------------------------------------===//
 | ||||||
|  |  | ||||||
|  | @ -22,8 +22,11 @@ def EqualBinaryOperands : Constraint<CPred<"$0 == $1">>; | ||||||
| 
 | 
 | ||||||
| // Canonicalization patterns. | // Canonicalization patterns. | ||||||
| 
 | 
 | ||||||
| def DynamicBroadcastToOwnShape : Pat< | def DynamicBroadcastToOwnShape_1 : Pat< | ||||||
|   (HLO_DynamicBroadcastInDimOp:$op $arg0, |    (HLO_DynamicBroadcastInDimOp:$op $arg0, | ||||||
|       (Shape_ToExtentTensorOp (Shape_ShapeOfOp $arg1)), $attr), |        (Shape_ToExtentTensorOp (Shape_ShapeOfOp $arg1)), $attr), | ||||||
|  |   (replaceWithValue $arg0), [(EqualBinaryOperands $arg0, $arg1)]>; | ||||||
|  | def DynamicBroadcastToOwnShape_2 : Pat< | ||||||
|  |   (HLO_DynamicBroadcastInDimOp:$op $arg0, (Shape_ShapeOfOp $arg1), $attr), | ||||||
|   (replaceWithValue $arg0), [(EqualBinaryOperands $arg0, $arg1)]>; |   (replaceWithValue $arg0), [(EqualBinaryOperands $arg0, $arg1)]>; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -29,7 +29,6 @@ limitations under the License. | ||||||
| 
 | 
 | ||||||
| namespace mlir { | namespace mlir { | ||||||
| namespace chlo { | namespace chlo { | ||||||
| 
 |  | ||||||
| namespace { | namespace { | ||||||
| 
 | 
 | ||||||
| // Converts binary ops that statically are determined to not broadcast directly
 | // Converts binary ops that statically are determined to not broadcast directly
 | ||||||
|  |  | ||||||
|  | @ -61,10 +61,9 @@ struct UnaryElementwiseOpConversion : public OpRewritePattern<OpTy> { | ||||||
|     // Generate IR to flatten the operand.
 |     // Generate IR to flatten the operand.
 | ||||||
|     auto loc = op.getLoc(); |     auto loc = op.getLoc(); | ||||||
|     Value shape = rewriter.create<shape::ShapeOfOp>(loc, operand); |     Value shape = rewriter.create<shape::ShapeOfOp>(loc, operand); | ||||||
|     Value numElements = rewriter.create<shape::NumElementsOp>( |     Value numElements = rewriter.create<shape::NumElementsOp>(loc, shape); | ||||||
|         loc, rewriter.getType<shape::SizeType>(), shape); |     Value numElementsAsIndex = | ||||||
|     Value numElementsAsIndex = rewriter.create<shape::SizeToIndexOp>( |         rewriter.create<shape::SizeToIndexOp>(loc, numElements); | ||||||
|         loc, rewriter.getIndexType(), numElements); |  | ||||||
|     Value flatShapeAsDimTensor = |     Value flatShapeAsDimTensor = | ||||||
|         rewriter.create<TensorFromElementsOp>(loc, numElementsAsIndex); |         rewriter.create<TensorFromElementsOp>(loc, numElementsAsIndex); | ||||||
|     auto flatTensorTy = RankedTensorType::get({ShapedType::kDynamicSize}, |     auto flatTensorTy = RankedTensorType::get({ShapedType::kDynamicSize}, | ||||||
|  |  | ||||||
|  | @ -365,11 +365,20 @@ func @dynamic_broadcast_in_dim_op_not_actually_dynamic(%arg0: tensor<4xf32>, %ar | ||||||
|   return %0 : tensor<5x4xf32> |   return %0 : tensor<5x4xf32> | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // CHECK-LABEL: func @dynamic_broadcast_in_dim_to_same_shape | // CHECK-LABEL: func @dynamic_broadcast_in_dim_to_same_shape_1 | ||||||
| func @dynamic_broadcast_in_dim_to_same_shape(%arg0: tensor<?xf32>) -> tensor<?xf32> { | func @dynamic_broadcast_in_dim_to_same_shape_1(%arg0: tensor<?xf32>) -> tensor<?xf32> { | ||||||
| // CHECK-SAME: %[[ARG:.*]]: tensor<?xf32> |   // CHECK-SAME: %[[ARG:.*]]: tensor<?xf32> | ||||||
|   %0 = shape.shape_of %arg0 : tensor<?xf32> |   %0 = shape.shape_of %arg0 : tensor<?xf32> -> tensor<1xindex> | ||||||
|   %1 = shape.to_extent_tensor %0 : tensor<1xindex> |   %2 = "mhlo.dynamic_broadcast_in_dim"(%arg0, %0) { broadcast_dimensions = dense<0> : tensor<1xi64> } : (tensor<?xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
|  |   // CHECK: return %[[ARG]] : tensor<?xf32> | ||||||
|  |   return %2 : tensor<?xf32> | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // CHECK-LABEL: func @dynamic_broadcast_in_dim_to_same_shape_2 | ||||||
|  | func @dynamic_broadcast_in_dim_to_same_shape_2(%arg0: tensor<?xf32>) -> tensor<?xf32> { | ||||||
|  |   // CHECK-SAME: %[[ARG:.*]]: tensor<?xf32> | ||||||
|  |   %0 = shape.shape_of %arg0 : tensor<?xf32> -> !shape.shape | ||||||
|  |   %1 = shape.to_extent_tensor %0 : !shape.shape -> tensor<1xindex> | ||||||
|   %2 = "mhlo.dynamic_broadcast_in_dim"(%arg0, %1) { broadcast_dimensions = dense<0> : tensor<1xi64> } : (tensor<?xf32>, tensor<1xindex>) -> tensor<?xf32> |   %2 = "mhlo.dynamic_broadcast_in_dim"(%arg0, %1) { broadcast_dimensions = dense<0> : tensor<1xi64> } : (tensor<?xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
|   // CHECK: return %[[ARG]] : tensor<?xf32> |   // CHECK: return %[[ARG]] : tensor<?xf32> | ||||||
|   return %2 : tensor<?xf32> |   return %2 : tensor<?xf32> | ||||||
|  |  | ||||||
|  | @ -18,7 +18,9 @@ func @dynamicBroadcast(%arg0: tensor<?xf32>, %arg1: tensor<?x?xf32>) -> tensor<? | ||||||
|   // CHECK-DAG:  %[[ARG1_S:.+]] = shape.shape_of %[[ARG1]] |   // CHECK-DAG:  %[[ARG1_S:.+]] = shape.shape_of %[[ARG1]] | ||||||
|   // CHECK-NEXT: %[[WITNESS:.+]] = shape.cstr_broadcastable %[[ARG0_S]], %[[ARG1_S]] |   // CHECK-NEXT: %[[WITNESS:.+]] = shape.cstr_broadcastable %[[ARG0_S]], %[[ARG1_S]] | ||||||
|   // CHECK-NEXT: %[[FINAL_RESULT:.+]] = shape.assuming %[[WITNESS]] |   // CHECK-NEXT: %[[FINAL_RESULT:.+]] = shape.assuming %[[WITNESS]] | ||||||
|   // CHECK-DAG:    %[[RESULT_S:.+]] = shape.broadcast %[[ARG0_S]], %[[ARG1_S]] |   // CHECK-DAG:  %[[ARG0_SS:.+]] = shape.shape_of %[[ARG0]] | ||||||
|  |   // CHECK-DAG:  %[[ARG1_SS:.+]] = shape.shape_of %[[ARG1]] | ||||||
|  |   // CHECK-DAG:    %[[RESULT_S:.+]] = shape.broadcast %[[ARG0_SS]], %[[ARG1_SS]] | ||||||
|   // CHECK:        %[[RESULT_EXTENTS:.+]] = shape.to_extent_tensor %[[RESULT_S]] |   // CHECK:        %[[RESULT_EXTENTS:.+]] = shape.to_extent_tensor %[[RESULT_S]] | ||||||
|   // CHECK-DAG:    %[[ARG0_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG0]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<1> : tensor<1xi64>} |   // CHECK-DAG:    %[[ARG0_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG0]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<1> : tensor<1xi64>} | ||||||
|   // CHECK-DAG:    %[[ARG1_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG1]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} |   // CHECK-DAG:    %[[ARG1_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG1]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} | ||||||
|  | @ -39,7 +41,9 @@ func @dynamicBroadcastComplex(%arg0: tensor<?xf32>, %arg1: tensor<?x?xf32>) -> t | ||||||
|   // CHECK-DAG:  %[[ARG1_S:.+]] = shape.shape_of %[[ARG1]] |   // CHECK-DAG:  %[[ARG1_S:.+]] = shape.shape_of %[[ARG1]] | ||||||
|   // CHECK-NEXT: %[[WITNESS:.+]] = shape.cstr_broadcastable %[[ARG0_S]], %[[ARG1_S]] |   // CHECK-NEXT: %[[WITNESS:.+]] = shape.cstr_broadcastable %[[ARG0_S]], %[[ARG1_S]] | ||||||
|   // CHECK-NEXT: %[[FINAL_RESULT:.+]] = shape.assuming %[[WITNESS]] |   // CHECK-NEXT: %[[FINAL_RESULT:.+]] = shape.assuming %[[WITNESS]] | ||||||
|   // CHECK-NEXT:   %[[RESULT_S:.+]] = shape.broadcast %[[ARG0_S]], %[[ARG1_S]] |   // CHECK-DAG:  %[[ARG0_SS:.+]] = shape.shape_of %[[ARG0]] | ||||||
|  |   // CHECK-DAG:  %[[ARG1_SS:.+]] = shape.shape_of %[[ARG1]] | ||||||
|  |   // CHECK-NEXT:   %[[RESULT_S:.+]] = shape.broadcast %[[ARG0_SS]], %[[ARG1_SS]] | ||||||
|   // CHECK-NEXT:   %[[RESULT_EXTENTS:.+]] = shape.to_extent_tensor %[[RESULT_S]] |   // CHECK-NEXT:   %[[RESULT_EXTENTS:.+]] = shape.to_extent_tensor %[[RESULT_S]] | ||||||
|   // CHECK-DAG:    %[[ARG0_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG0]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<1> : tensor<1xi64>} : (tensor<?xf32>, tensor<2xindex>) -> tensor<?x?xf32> |   // CHECK-DAG:    %[[ARG0_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG0]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<1> : tensor<1xi64>} : (tensor<?xf32>, tensor<2xindex>) -> tensor<?x?xf32> | ||||||
|   // CHECK-DAG:    %[[ARG1_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG1]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor<?x?xf32>, tensor<2xindex>) -> tensor<?x?xf32> |   // CHECK-DAG:    %[[ARG1_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG1]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor<?x?xf32>, tensor<2xindex>) -> tensor<?x?xf32> | ||||||
|  | @ -60,7 +64,9 @@ func @dynamicBroadcastCompare(%arg0: tensor<?xf32>, %arg1: tensor<?x?xf32>) -> t | ||||||
|   // CHECK-DAG: %[[ARG1_S:.+]] = shape.shape_of %[[ARG1]] |   // CHECK-DAG: %[[ARG1_S:.+]] = shape.shape_of %[[ARG1]] | ||||||
|   // CHECK: %[[WITNESS:.+]] = shape.cstr_broadcastable %[[ARG0_S]], %[[ARG1_S]] |   // CHECK: %[[WITNESS:.+]] = shape.cstr_broadcastable %[[ARG0_S]], %[[ARG1_S]] | ||||||
|   // CHECK: %[[FINAL_RESULT:.+]] = shape.assuming %[[WITNESS]] |   // CHECK: %[[FINAL_RESULT:.+]] = shape.assuming %[[WITNESS]] | ||||||
|   // CHECK: %[[RESULT_S:.+]] = shape.broadcast %[[ARG0_S]], %[[ARG1_S]] |   // CHECK-DAG:  %[[ARG0_SS:.+]] = shape.shape_of %[[ARG0]] | ||||||
|  |   // CHECK-DAG:  %[[ARG1_SS:.+]] = shape.shape_of %[[ARG1]] | ||||||
|  |   // CHECK: %[[RESULT_S:.+]] = shape.broadcast %[[ARG0_SS]], %[[ARG1_SS]] | ||||||
|   // CHECK: %[[RESULT_EXTENTS:.+]] = shape.to_extent_tensor %[[RESULT_S]] |   // CHECK: %[[RESULT_EXTENTS:.+]] = shape.to_extent_tensor %[[RESULT_S]] | ||||||
|   // CHECK-DAG: %[[ARG0_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG0]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<1> : tensor<1xi64>} : (tensor<?xf32>, tensor<2xindex>) -> tensor<?x?xf32> |   // CHECK-DAG: %[[ARG0_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG0]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<1> : tensor<1xi64>} : (tensor<?xf32>, tensor<2xindex>) -> tensor<?x?xf32> | ||||||
|   // CHECK-DAG: %[[ARG1_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG1]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor<?x?xf32>, tensor<2xindex>) -> tensor<?x?xf32> |   // CHECK-DAG: %[[ARG1_B:.+]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG1]], %[[RESULT_EXTENTS]]) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor<?x?xf32>, tensor<2xindex>) -> tensor<?x?xf32> | ||||||
|  | @ -253,8 +259,8 @@ func @addScalarUnranked(%arg0: tensor<f32>, %arg1: tensor<*xf32>) -> tensor<*xf3 | ||||||
| //                  to a 1D tensor. | //                  to a 1D tensor. | ||||||
| // CHECK:           %[[SHAPE_1:.*]] = shape.shape_of %[[ARG_1]] : tensor<*xf32> | // CHECK:           %[[SHAPE_1:.*]] = shape.shape_of %[[ARG_1]] : tensor<*xf32> | ||||||
| // CHECK:           %[[NUM_ELEMENTS:.*]] = shape.num_elements %[[SHAPE_1]] | // CHECK:           %[[NUM_ELEMENTS:.*]] = shape.num_elements %[[SHAPE_1]] | ||||||
| // CHECK:           %[[SIZE:.*]] = shape.size_to_index %[[NUM_ELEMENTS]] | // CHECK:           %[[NUM_ELEMENTS_INDEX:.*]] = shape.size_to_index %[[NUM_ELEMENTS]] | ||||||
| // CHECK:           %[[SIZE_TENSOR:.*]] = tensor_from_elements(%[[SIZE]]) : tensor<1xindex> | // CHECK:           %[[SIZE_TENSOR:.*]] = tensor_from_elements(%[[NUM_ELEMENTS_INDEX]]) : tensor<1xindex> | ||||||
| // CHECK:           %[[RESHAPED:.*]] = "mhlo.dynamic_reshape"(%[[ARG_1]], %[[SIZE_TENSOR]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> | // CHECK:           %[[RESHAPED:.*]] = "mhlo.dynamic_reshape"(%[[ARG_1]], %[[SIZE_TENSOR]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
| //                  The assuming region is part of the second stage of lowering | //                  The assuming region is part of the second stage of lowering | ||||||
| //                  with ranked broadcasting logic. | //                  with ranked broadcasting logic. | ||||||
|  | @ -263,8 +269,9 @@ func @addScalarUnranked(%arg0: tensor<f32>, %arg1: tensor<*xf32>) -> tensor<*xf3 | ||||||
| // CHECK:           %[[WITNESS:.*]] = shape.cstr_broadcastable %[[SHAPE_0]], %[[SHAPE_RESHAPED]] | // CHECK:           %[[WITNESS:.*]] = shape.cstr_broadcastable %[[SHAPE_0]], %[[SHAPE_RESHAPED]] | ||||||
| // CHECK:           %[[ASSUMING_RESULT:.*]] = shape.assuming %[[WITNESS]] -> (tensor<?xf32>) { | // CHECK:           %[[ASSUMING_RESULT:.*]] = shape.assuming %[[WITNESS]] -> (tensor<?xf32>) { | ||||||
| // CHECK:             %[[SCALAR_SHAPE:.*]] = shape.const_shape [] | // CHECK:             %[[SCALAR_SHAPE:.*]] = shape.const_shape [] | ||||||
|  | // CHECK:             %[[SHAPE_RESHAPED:.*]] = shape.shape_of %[[RESHAPED]] : tensor<?xf32> | ||||||
| // CHECK:             %[[BROADCASTED_SHAPE:.*]] = shape.broadcast %[[SCALAR_SHAPE]], %[[SHAPE_RESHAPED]] | // CHECK:             %[[BROADCASTED_SHAPE:.*]] = shape.broadcast %[[SCALAR_SHAPE]], %[[SHAPE_RESHAPED]] | ||||||
| // CHECK:             %[[SHAPE_TENSOR:.*]] = shape.to_extent_tensor %[[BROADCASTED_SHAPE]] : tensor<1xindex> | // CHECK:             %[[SHAPE_TENSOR:.*]] = shape.to_extent_tensor %[[BROADCASTED_SHAPE]] : !shape.shape -> tensor<1xindex> | ||||||
| // CHECK:             %[[BROADCASTED_LHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG_0]], %[[SHAPE_TENSOR]]) {broadcast_dimensions = dense<> : tensor<0xi64>} : (tensor<f32>, tensor<1xindex>) -> tensor<?xf32> | // CHECK:             %[[BROADCASTED_LHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG_0]], %[[SHAPE_TENSOR]]) {broadcast_dimensions = dense<> : tensor<0xi64>} : (tensor<f32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
| // CHECK:             %[[BROADCASTED_RHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[RESHAPED]], %[[SHAPE_TENSOR]]) {broadcast_dimensions = dense<0> : tensor<1xi64>} : (tensor<?xf32>, tensor<1xindex>) -> tensor<?xf32> | // CHECK:             %[[BROADCASTED_RHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[RESHAPED]], %[[SHAPE_TENSOR]]) {broadcast_dimensions = dense<0> : tensor<1xi64>} : (tensor<?xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
| // CHECK:             %[[BROADCASTED_RESULT:.*]] = mhlo.add %[[BROADCASTED_LHS]], %[[BROADCASTED_RHS]] : tensor<?xf32> | // CHECK:             %[[BROADCASTED_RESULT:.*]] = mhlo.add %[[BROADCASTED_LHS]], %[[BROADCASTED_RHS]] : tensor<?xf32> | ||||||
|  | @ -272,8 +279,8 @@ func @addScalarUnranked(%arg0: tensor<f32>, %arg1: tensor<*xf32>) -> tensor<*xf3 | ||||||
| // CHECK:           } | // CHECK:           } | ||||||
| //                  As part of the unranked logic, the result is reshaped back | //                  As part of the unranked logic, the result is reshaped back | ||||||
| //                  to an unranked tensor. | //                  to an unranked tensor. | ||||||
| // CHECK:           %[[PROPER_SHAPE_TENSOR:.*]] = shape.to_extent_tensor %[[SHAPE_1]] : tensor<?xindex> | // CHECK:             %[[SHAPE_2:.*]] = shape.to_extent_tensor %[[SHAPE_1]] : tensor<?xindex> -> tensor<?xindex> | ||||||
| // CHECK:           %[[RESHAPED_RESULT:.*]] = "mhlo.dynamic_reshape"(%[[VAL_19:.*]], %[[PROPER_SHAPE_TENSOR]]) : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> | // CHECK:           %[[RESHAPED_RESULT:.*]] = "mhlo.dynamic_reshape"(%[[ASSUMING_RESULT:.*]], %[[SHAPE_2]]) : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> | ||||||
| // CHECK:           return %[[RESHAPED_RESULT]] : tensor<*xf32> | // CHECK:           return %[[RESHAPED_RESULT]] : tensor<*xf32> | ||||||
| // CHECK:         } | // CHECK:         } | ||||||
| 
 | 
 | ||||||
|  | @ -290,8 +297,8 @@ func @addUnrankedScalar(%arg0: tensor<*xf32>, %arg1: tensor<f32>) -> tensor<*xf3 | ||||||
| //                  to a 1D tensor. | //                  to a 1D tensor. | ||||||
| // CHECK:           %[[SHAPE_0:.*]] = shape.shape_of %[[ARG_0]] : tensor<*xf32> | // CHECK:           %[[SHAPE_0:.*]] = shape.shape_of %[[ARG_0]] : tensor<*xf32> | ||||||
| // CHECK:           %[[NUM_ELEMENTS:.*]] = shape.num_elements %[[SHAPE_0]] | // CHECK:           %[[NUM_ELEMENTS:.*]] = shape.num_elements %[[SHAPE_0]] | ||||||
| // CHECK:           %[[SIZE:.*]] = shape.size_to_index %[[NUM_ELEMENTS]] | // CHECK:           %[[NUM_ELEMENTS_INDEX:.*]] = shape.size_to_index %[[NUM_ELEMENTS]] | ||||||
| // CHECK:           %[[SIZE_TENSOR:.*]] = tensor_from_elements(%[[SIZE]]) : tensor<1xindex> | // CHECK:           %[[SIZE_TENSOR:.*]] = tensor_from_elements(%[[NUM_ELEMENTS_INDEX]]) : tensor<1xindex> | ||||||
| // CHECK:           %[[RESHAPED:.*]] = "mhlo.dynamic_reshape"(%[[ARG_0]], %[[SIZE_TENSOR]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> | // CHECK:           %[[RESHAPED:.*]] = "mhlo.dynamic_reshape"(%[[ARG_0]], %[[SIZE_TENSOR]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
| //                  The assuming region is part of the second stage of lowering | //                  The assuming region is part of the second stage of lowering | ||||||
| //                  with ranked broadcasting logic. | //                  with ranked broadcasting logic. | ||||||
|  | @ -299,15 +306,16 @@ func @addUnrankedScalar(%arg0: tensor<*xf32>, %arg1: tensor<f32>) -> tensor<*xf3 | ||||||
| // CHECK:           %[[SHAPE_1:.*]] = shape.shape_of %[[ARG_1]] : tensor<f32> | // CHECK:           %[[SHAPE_1:.*]] = shape.shape_of %[[ARG_1]] : tensor<f32> | ||||||
| // CHECK:           %[[WITNESS:.*]] = shape.cstr_broadcastable %[[SHAPE_RESHAPED]], %[[SHAPE_1]] | // CHECK:           %[[WITNESS:.*]] = shape.cstr_broadcastable %[[SHAPE_RESHAPED]], %[[SHAPE_1]] | ||||||
| // CHECK:           %[[ASSUMING_RESULT:.*]] = shape.assuming %[[WITNESS]] -> (tensor<?xf32>) { | // CHECK:           %[[ASSUMING_RESULT:.*]] = shape.assuming %[[WITNESS]] -> (tensor<?xf32>) { | ||||||
| // CHECK:             %[[SHAPE_TENSOR:.*]] = shape.to_extent_tensor %[[SHAPE_RESHAPED]] : tensor<1xindex> | // CHECK:             %[[SHAPE_OF:.*]] = shape.shape_of %[[RESHAPED]] : tensor<?xf32> | ||||||
| // CHECK:             %[[BROADCASTED_LHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[RESHAPED]], %[[SHAPE_TENSOR]]) {broadcast_dimensions = dense<0> : tensor<1xi64>} : (tensor<?xf32>, tensor<1xindex>) -> tensor<?xf32> | // CHECK:             %[[SHAPE_RESHAPED:.*]] = shape.to_extent_tensor %[[SHAPE_OF]] | ||||||
| // CHECK:             %[[BROADCASTED_RHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG_1]], %[[SHAPE_TENSOR]]) {broadcast_dimensions = dense<> : tensor<0xi64>} : (tensor<f32>, tensor<1xindex>) -> tensor<?xf32> | // CHECK:             %[[BROADCASTED_LHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[RESHAPED]], %[[SHAPE_RESHAPED]]) {broadcast_dimensions = dense<0> : tensor<1xi64>} : (tensor<?xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
|  | // CHECK:             %[[BROADCASTED_RHS:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[ARG_1]], %[[SHAPE_RESHAPED]]) {broadcast_dimensions = dense<> : tensor<0xi64>} : (tensor<f32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
| // CHECK:             %[[BROADCASTED_RESULT:.*]] = mhlo.add %[[BROADCASTED_LHS]], %[[BROADCASTED_RHS]] : tensor<?xf32> | // CHECK:             %[[BROADCASTED_RESULT:.*]] = mhlo.add %[[BROADCASTED_LHS]], %[[BROADCASTED_RHS]] : tensor<?xf32> | ||||||
| // CHECK:             shape.assuming_yield %[[BROADCASTED_RESULT]] : tensor<?xf32> | // CHECK:             shape.assuming_yield %[[BROADCASTED_RESULT]] : tensor<?xf32> | ||||||
| // CHECK:           } | // CHECK:           } | ||||||
| //                  As part of the unranked logic, the result is reshaped back | //                  As part of the unranked logic, the result is reshaped back | ||||||
| //                  to an unranked tensor. | //                  to an unranked tensor. | ||||||
| // CHECK:           %[[PROPER_SHAPE_TENSOR:.*]] = shape.to_extent_tensor %[[SHAPE_0]] : tensor<?xindex> | // CHECK:             %[[SHAPE_2:.*]] = shape.to_extent_tensor %[[SHAPE_0]] | ||||||
| // CHECK:           %[[RESHAPED_RESULT:.*]] = "mhlo.dynamic_reshape"(%[[VAL_19:.*]], %[[PROPER_SHAPE_TENSOR]]) : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> | // CHECK:           %[[RESHAPED_RESULT:.*]] = "mhlo.dynamic_reshape"(%[[ASSUMING_RESULT:.*]], %[[SHAPE_2]]) : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> | ||||||
| // CHECK:           return %[[RESHAPED_RESULT]] : tensor<*xf32> | // CHECK:           return %[[RESHAPED_RESULT]] : tensor<*xf32> | ||||||
| // CHECK:         } | // CHECK:         } | ||||||
|  |  | ||||||
|  | @ -5,9 +5,9 @@ | ||||||
| func @sqr_transform_result(%a: tensor<*xf32>) -> tensor<*xf32> { | func @sqr_transform_result(%a: tensor<*xf32>) -> tensor<*xf32> { | ||||||
| 
 | 
 | ||||||
|   // Flatten operand shape. |   // Flatten operand shape. | ||||||
|   %shape = shape.shape_of %a : tensor<*xf32> |   %shape = shape.shape_of %a : tensor<*xf32> -> tensor<?xindex> | ||||||
|   %num_elements = shape.num_elements %shape |   %num_elements = shape.num_elements %shape : tensor<?xindex> -> index | ||||||
|   %num_elements_as_index = shape.size_to_index %num_elements |   %num_elements_as_index = shape.size_to_index %num_elements : index | ||||||
|   %flat_shape = tensor_from_elements(%num_elements_as_index) : tensor<1xindex> |   %flat_shape = tensor_from_elements(%num_elements_as_index) : tensor<1xindex> | ||||||
|   %flat_a = "mhlo.dynamic_reshape"(%a, %flat_shape) |   %flat_a = "mhlo.dynamic_reshape"(%a, %flat_shape) | ||||||
|       : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> |       : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
|  | @ -16,7 +16,7 @@ func @sqr_transform_result(%a: tensor<*xf32>) -> tensor<*xf32> { | ||||||
|   %flat_b = "mhlo.sqrt"(%flat_a) : (tensor<?xf32>) -> tensor<?xf32> |   %flat_b = "mhlo.sqrt"(%flat_a) : (tensor<?xf32>) -> tensor<?xf32> | ||||||
| 
 | 
 | ||||||
|   // Restore original shape. |   // Restore original shape. | ||||||
|   %shape_as_extent_tensor = shape.to_extent_tensor %shape : tensor<?xindex> |   %shape_as_extent_tensor = shape.to_extent_tensor %shape : tensor<?xindex> -> tensor<?xindex> | ||||||
|   %b = "mhlo.dynamic_reshape"(%flat_b, %shape_as_extent_tensor) |   %b = "mhlo.dynamic_reshape"(%flat_b, %shape_as_extent_tensor) | ||||||
|       : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> |       : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> | ||||||
| 
 | 
 | ||||||
|  | @ -73,14 +73,14 @@ func @sqrt_static(%a: tensor<2x3xf32>) -> tensor<2x3xf32> { | ||||||
| func @add_unranked(%a : tensor<*xf32>, %b : tensor<*xf32>) -> tensor<*xf32> { | func @add_unranked(%a : tensor<*xf32>, %b : tensor<*xf32>) -> tensor<*xf32> { | ||||||
|   // CHECK: %[[SHAPE_A:.*]] = shape.shape_of %[[A]] |   // CHECK: %[[SHAPE_A:.*]] = shape.shape_of %[[A]] | ||||||
|   // CHECK: %[[SHAPE_B:.*]] = shape.shape_of %[[B]] |   // CHECK: %[[SHAPE_B:.*]] = shape.shape_of %[[B]] | ||||||
|   // CHECK: %[[SHAPE:.*]] = shape.any %[[SHAPE_A]], %[[SHAPE_B]] |   // CHECK: %[[SHAPE:.*]] = "shape.any"(%[[SHAPE_A]], %[[SHAPE_B]]) | ||||||
|   // CHECK: %[[NUM_ELEMENTS:.*]] = shape.num_elements %[[SHAPE]] |   // CHECK: %[[NUM_ELEMENTS:.*]] = shape.num_elements %[[SHAPE]] | ||||||
|   // CHECK: %[[NUM_ELEMENTS_AS_INDEX:.*]] = shape.size_to_index %[[NUM_ELEMENTS]] |   // CHECK: %[[NUM_ELEMENTS_AS_INDEX:.*]] = shape.size_to_index %[[NUM_ELEMENTS]] | ||||||
|   // CHECK: %[[FLAT_SHAPE:.*]] = tensor_from_elements(%[[NUM_ELEMENTS_AS_INDEX]]) : tensor<1xindex> |   // CHECK: %[[FLAT_SHAPE:.*]] = tensor_from_elements(%[[NUM_ELEMENTS_AS_INDEX]]) : tensor<1xindex> | ||||||
|   // CHECK: %[[FLAT_A:.*]] = "mhlo.dynamic_reshape"(%[[A]], %[[FLAT_SHAPE]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> |   // CHECK: %[[FLAT_A:.*]] = "mhlo.dynamic_reshape"(%[[A]], %[[FLAT_SHAPE]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
|   // CHECK: %[[FLAT_B:.*]] = "mhlo.dynamic_reshape"(%[[B]], %[[FLAT_SHAPE]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> |   // CHECK: %[[FLAT_B:.*]] = "mhlo.dynamic_reshape"(%[[B]], %[[FLAT_SHAPE]]) : (tensor<*xf32>, tensor<1xindex>) -> tensor<?xf32> | ||||||
|   // CHECK: %[[FLAT_RESULT:.*]] = mhlo.add %[[FLAT_A]], %[[FLAT_B]] : tensor<?xf32> |   // CHECK: %[[FLAT_RESULT:.*]] = mhlo.add %[[FLAT_A]], %[[FLAT_B]] : tensor<?xf32> | ||||||
|   // CHECK: %[[SHAPE_AS_EXTENT_TENSOR:.*]] = shape.to_extent_tensor %[[SHAPE]] : tensor<?xindex> |   // CHECK: %[[SHAPE_AS_EXTENT_TENSOR:.*]] = shape.to_extent_tensor %[[SHAPE]] | ||||||
|   // CHECK: %[[RESULT:.*]] = "mhlo.dynamic_reshape"(%[[FLAT_RESULT]], %[[SHAPE_AS_EXTENT_TENSOR]]) : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> |   // CHECK: %[[RESULT:.*]] = "mhlo.dynamic_reshape"(%[[FLAT_RESULT]], %[[SHAPE_AS_EXTENT_TENSOR]]) : (tensor<?xf32>, tensor<?xindex>) -> tensor<*xf32> | ||||||
|   // CHECK: return %[[RESULT]] : tensor<*xf32> |   // CHECK: return %[[RESULT]] : tensor<*xf32> | ||||||
|   %result = mhlo.add %a, %b : tensor<*xf32> |   %result = mhlo.add %a, %b : tensor<*xf32> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue