Skip to content

Commit dfbb5a0

Browse files
committed
[mlir] Remove SameOperandsAndResultShape when redundant with ElementwiseMappable
SameOperandsAndResultShape and ElementwiseMappable have similar verification, but in general neither is strictly redundant with the other. Examples: - SameOperandsAndResultShape allows `"foo"(%0) : tensor<2xf32> -> tensor<?xf32> but ElementwiseMappable does not. - ElementwiseMappable allows `select %scalar_pred, %true_tensor, %false_tensor` but SameOperandsAndResultShape does not. SameOperandsAndResultShape is redundant with ElementwiseMappable when we can prove that the mixed scalar/non-scalar case cannot happen. In those situations, `ElementwiseMappable & SameOperandsAndResultShape == ElementwiseMappable`: - Ops with 1 operand: the case of mixed scalar and non-scalar operands cannot happen since there is only one operand. - When SameTypeOperands is also present, the mixed scalar/non-scalar operand case cannot happen. Differential Revision: https://reviews.llvm.org/D91396
1 parent b228e2b commit dfbb5a0

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -991,10 +991,10 @@ def CmpFPredicateAttr : I64EnumAttr<
991991
}
992992

993993
def CmpFOp : Std_Op<"cmpf",
994-
[NoSideEffect, SameTypeOperands,
995-
SameOperandsAndResultShape, TypesMatchWith<
994+
[NoSideEffect, SameTypeOperands, ElementwiseMappable,
995+
TypesMatchWith<
996996
"result type has i1 element type and same shape as operands",
997-
"lhs", "result", "getI1SameShape($_self)">, ElementwiseMappable]> {
997+
"lhs", "result", "getI1SameShape($_self)">]> {
998998
let summary = "floating-point comparison operation";
999999
let description = [{
10001000
The `cmpf` operation compares its two operands according to the float
@@ -1075,10 +1075,10 @@ def CmpIPredicateAttr : I64EnumAttr<
10751075
}
10761076

10771077
def CmpIOp : Std_Op<"cmpi",
1078-
[NoSideEffect, SameTypeOperands,
1079-
SameOperandsAndResultShape, TypesMatchWith<
1078+
[NoSideEffect, SameTypeOperands, ElementwiseMappable,
1079+
TypesMatchWith<
10801080
"result type has i1 element type and same shape as operands",
1081-
"lhs", "result", "getI1SameShape($_self)">, ElementwiseMappable]> {
1081+
"lhs", "result", "getI1SameShape($_self)">]> {
10821082
let summary = "integer comparison operation";
10831083
let description = [{
10841084
The `cmpi` operation is a generic comparison for integer-like types. Its two
@@ -2799,7 +2799,7 @@ def SignedShiftRightOp : IntArithmeticOp<"shift_right_signed"> {
27992799
//===----------------------------------------------------------------------===//
28002800

28012801
def SignExtendIOp : Std_Op<"sexti",
2802-
[NoSideEffect, SameOperandsAndResultShape, ElementwiseMappable]> {
2802+
[NoSideEffect, ElementwiseMappable]> {
28032803
let summary = "integer sign extension operation";
28042804
let description = [{
28052805
The integer sign extension operation takes an integer input of
@@ -3665,9 +3665,7 @@ def TransposeOp : Std_Op<"transpose", [NoSideEffect]>,
36653665
// TruncateIOp
36663666
//===----------------------------------------------------------------------===//
36673667

3668-
def TruncateIOp : Std_Op<"trunci", [NoSideEffect,
3669-
SameOperandsAndResultShape,
3670-
ElementwiseMappable]> {
3668+
def TruncateIOp : Std_Op<"trunci", [NoSideEffect, ElementwiseMappable]> {
36713669
let summary = "integer truncation operation";
36723670
let description = [{
36733671
The integer truncation operation takes an integer input of
@@ -3934,9 +3932,7 @@ def XOrOp : IntArithmeticOp<"xor", [Commutative]> {
39343932
// ZeroExtendIOp
39353933
//===----------------------------------------------------------------------===//
39363934

3937-
def ZeroExtendIOp : Std_Op<"zexti", [NoSideEffect,
3938-
SameOperandsAndResultShape,
3939-
ElementwiseMappable]> {
3935+
def ZeroExtendIOp : Std_Op<"zexti", [NoSideEffect, ElementwiseMappable]> {
39403936
let summary = "integer zero extension operation";
39413937
let description = [{
39423938
The integer zero extension operation takes an integer input of

mlir/test/IR/invalid-ops.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func @func_with_ops(i32, i32) {
236236
func @func_with_ops() {
237237
^bb0:
238238
%c = constant dense<0> : vector<42 x i32>
239-
// expected-error@+1 {{op requires the same shape for all operands and results}}
239+
// expected-error@+1 {{all non-scalar operands/results must have the same shape and base type: found 'vector<41xi1>' and 'vector<42xi32>'}}
240240
%r = "std.cmpi"(%c, %c) {predicate = 0} : (vector<42 x i32>, vector<42 x i32>) -> vector<41 x i1>
241241
}
242242

@@ -514,7 +514,7 @@ func @cmpf_canonical_wrong_result_type(%a : f32, %b : f32) -> f32 {
514514
// -----
515515

516516
func @cmpf_result_shape_mismatch(%a : vector<42xf32>) {
517-
// expected-error@+1 {{op requires the same shape for all operands and results}}
517+
// expected-error@+1 {{all non-scalar operands/results must have the same shape and base type: found 'vector<41xi1>' and 'vector<42xf32>'}}
518518
%r = "std.cmpf"(%a, %a) {predicate = 0} : (vector<42 x f32>, vector<42 x f32>) -> vector<41 x i1>
519519
}
520520

0 commit comments

Comments
 (0)