1// RUN: mlir-opt -convert-shape-constraints <%s | FileCheck %s 2 3// There's not very much useful to check here other than pasting the output. 4// CHECK-LABEL: func @cstr_broadcastable( 5// CHECK-SAME: %[[LHS:.*]]: tensor<?xindex>, 6// CHECK-SAME: %[[RHS:.*]]: tensor<?xindex>) -> !shape.witness { 7// CHECK: %[[C0:.*]] = constant 0 : index 8// CHECK: %[[C1:.*]] = constant 1 : index 9// CHECK: %[[RET:.*]] = shape.const_witness true 10// CHECK: %[[LHS_RANK:.*]] = dim %[[LHS]], %[[C0]] : tensor<?xindex> 11// CHECK: %[[RHS_RANK:.*]] = dim %[[RHS]], %[[C0]] : tensor<?xindex> 12// CHECK: %[[LHS_RANK_ULE:.*]] = cmpi "ule", %[[LHS_RANK]], %[[RHS_RANK]] : index 13// CHECK: %[[LESSER_RANK:.*]] = select %[[LHS_RANK_ULE]], %[[LHS_RANK]], %[[RHS_RANK]] : index 14// CHECK: %[[GREATER_RANK:.*]] = select %[[LHS_RANK_ULE]], %[[RHS_RANK]], %[[LHS_RANK]] : index 15// CHECK: %[[LESSER_RANK_OPERAND:.*]] = select %[[LHS_RANK_ULE]], %[[LHS]], %[[RHS]] : tensor<?xindex> 16// CHECK: %[[GREATER_RANK_OPERAND:.*]] = select %[[LHS_RANK_ULE]], %[[RHS]], %[[LHS]] : tensor<?xindex> 17// CHECK: %[[RANK_DIFF:.*]] = subi %[[GREATER_RANK]], %[[LESSER_RANK]] : index 18// CHECK: scf.for %[[IV:.*]] = %[[RANK_DIFF]] to %[[GREATER_RANK]] step %[[C1]] { 19// CHECK: %[[GREATER_RANK_OPERAND_EXTENT:.*]] = extract_element %[[GREATER_RANK_OPERAND]][%[[IV]]] : tensor<?xindex> 20// CHECK: %[[IVSHIFTED:.*]] = subi %[[IV]], %[[RANK_DIFF]] : index 21// CHECK: %[[LESSER_RANK_OPERAND_EXTENT:.*]] = extract_element %[[LESSER_RANK_OPERAND]][%[[IVSHIFTED]]] : tensor<?xindex> 22// CHECK: %[[GREATER_RANK_OPERAND_EXTENT_IS_ONE:.*]] = cmpi "eq", %[[GREATER_RANK_OPERAND_EXTENT]], %[[C1]] : index 23// CHECK: %[[LESSER_RANK_OPERAND_EXTENT_IS_ONE:.*]] = cmpi "eq", %[[LESSER_RANK_OPERAND_EXTENT]], %[[C1]] : index 24// CHECK: %[[EXTENTS_AGREE:.*]] = cmpi "eq", %[[GREATER_RANK_OPERAND_EXTENT]], %[[LESSER_RANK_OPERAND_EXTENT]] : index 25// CHECK: %[[OR_TMP:.*]] = or %[[GREATER_RANK_OPERAND_EXTENT_IS_ONE]], %[[LESSER_RANK_OPERAND_EXTENT_IS_ONE]] : i1 26// CHECK: %[[BROADCAST_IS_VALID:.*]] = or %[[EXTENTS_AGREE]], %[[OR_TMP]] : i1 27// CHECK: assert %[[BROADCAST_IS_VALID]], "invalid broadcast" 28// CHECK: } 29// CHECK: return %[[RET]] : !shape.witness 30// CHECK: } 31func @cstr_broadcastable(%arg0: tensor<?xindex>, %arg1: tensor<?xindex>) -> !shape.witness { 32 %witness = shape.cstr_broadcastable %arg0, %arg1 : tensor<?xindex>, tensor<?xindex> 33 return %witness : !shape.witness 34} 35 36// CHECK-LABEL: func @cstr_require 37func @cstr_require(%arg0: i1) -> !shape.witness { 38 // CHECK: %[[RET:.*]] = shape.const_witness true 39 // CHECK: assert %arg0, "msg" 40 // CHECK: return %[[RET]] 41 %witness = shape.cstr_require %arg0, "msg" 42 return %witness : !shape.witness 43} 44