[mlir][ods] Fix packing in OperandOrAttribute
authorJacques Pienaar <jpienaar@google.com>
Wed, 18 Aug 2021 03:55:48 +0000 (20:55 -0700)
committerJacques Pienaar <jpienaar@google.com>
Wed, 18 Aug 2021 03:55:48 +0000 (20:55 -0700)
Wrong combiner was used which led to information loss.

mlir/include/mlir/TableGen/Operator.h
mlir/test/mlir-tblgen/op-result.td

index 7187daa..4d41d48 100644 (file)
@@ -277,7 +277,7 @@ public:
   struct OperandOrAttribute {
     enum class Kind { Operand, Attribute };
     OperandOrAttribute(Kind kind, int index) {
-      packed = (index << 1) & (kind == Kind::Attribute);
+      packed = (index << 1) | (kind == Kind::Attribute);
     }
     int operandOrAttributeIndex() const { return (packed >> 1); }
     Kind kind() { return (packed & 0x1) ? Kind::Attribute : Kind::Operand; }
index ac8f1cb..63bc5d0 100644 (file)
@@ -115,12 +115,23 @@ def OpK : NS_Op<"only_input_is_variadic_with_same_value_type_op", [SameOperandsA
 
 // Test with inferred shapes and interleaved with operands/attributes.
 //
-def OpL : NS_Op<"op_with_all_types_constraint",
+def OpL1 : NS_Op<"op_with_all_types_constraint",
     [AllTypesMatch<["a", "b"]>]> {
   let arguments = (ins I32Attr:$attr1, AnyType:$a);
   let results = (outs Res<AnyType, "output b", []>:$b);
 }
 
-// CHECK-LABEL: LogicalResult OpL::inferReturnTypes
+// CHECK-LABEL: LogicalResult OpL1::inferReturnTypes
 // CHECK-NOT: }
 // CHECK: inferredReturnTypes[0] = operands[0].getType();
+
+def OpL2 : NS_Op<"op_with_all_types_constraint",
+    [AllTypesMatch<["c", "b"]>, AllTypesMatch<["a", "d"]>]> {
+  let arguments = (ins I32Attr:$attr1, AnyType:$a, AnyType:$a2, AnyType:$c);
+  let results = (outs Res<AnyType, "output b", []>:$b, AnyType:$d);
+}
+
+// CHECK-LABEL: LogicalResult OpL2::inferReturnTypes
+// CHECK-NOT: }
+// CHECK: inferredReturnTypes[0] = operands[2].getType();
+// CHECK: inferredReturnTypes[1] = operands[0].getType();