Skip to content

Commit b41bfb8

Browse files
committed
[mlir][ods] Fix packing in OperandOrAttribute
Wrong combiner was used which led to information loss.
1 parent 5aeca3b commit b41bfb8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

mlir/include/mlir/TableGen/Operator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class Operator {
277277
struct OperandOrAttribute {
278278
enum class Kind { Operand, Attribute };
279279
OperandOrAttribute(Kind kind, int index) {
280-
packed = (index << 1) & (kind == Kind::Attribute);
280+
packed = (index << 1) | (kind == Kind::Attribute);
281281
}
282282
int operandOrAttributeIndex() const { return (packed >> 1); }
283283
Kind kind() { return (packed & 0x1) ? Kind::Attribute : Kind::Operand; }

mlir/test/mlir-tblgen/op-result.td

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,23 @@ def OpK : NS_Op<"only_input_is_variadic_with_same_value_type_op", [SameOperandsA
115115

116116
// Test with inferred shapes and interleaved with operands/attributes.
117117
//
118-
def OpL : NS_Op<"op_with_all_types_constraint",
118+
def OpL1 : NS_Op<"op_with_all_types_constraint",
119119
[AllTypesMatch<["a", "b"]>]> {
120120
let arguments = (ins I32Attr:$attr1, AnyType:$a);
121121
let results = (outs Res<AnyType, "output b", []>:$b);
122122
}
123123

124-
// CHECK-LABEL: LogicalResult OpL::inferReturnTypes
124+
// CHECK-LABEL: LogicalResult OpL1::inferReturnTypes
125125
// CHECK-NOT: }
126126
// CHECK: inferredReturnTypes[0] = operands[0].getType();
127+
128+
def OpL2 : NS_Op<"op_with_all_types_constraint",
129+
[AllTypesMatch<["c", "b"]>, AllTypesMatch<["a", "d"]>]> {
130+
let arguments = (ins I32Attr:$attr1, AnyType:$a, AnyType:$a2, AnyType:$c);
131+
let results = (outs Res<AnyType, "output b", []>:$b, AnyType:$d);
132+
}
133+
134+
// CHECK-LABEL: LogicalResult OpL2::inferReturnTypes
135+
// CHECK-NOT: }
136+
// CHECK: inferredReturnTypes[0] = operands[2].getType();
137+
// CHECK: inferredReturnTypes[1] = operands[0].getType();

0 commit comments

Comments
 (0)