Skip to content

Commit 7aebacb

Browse files
authored
[MLIR][TableGen] Use arg index in InferredResultType constructor. (llvm#122717)
Trying to constrain two results to be of the same type using `AllTypesMatch` would cause `mlir-tablgen` to crash on this assertion[1]. Example: ```tblgen def OpL5 : NS_Op<"op_with_same_but_unconstraint_results", [AllTypesMatch<["result_a", "result_b"]>]> { let results = (outs AnyType:$result_a, AnyType:$result_b); } ``` This is because there was a small bug when constructing the `inferences` graph from these constraints: The sources should be specified by the combined arg/result index (in other words, with results negative) not with the result index. [1] https://github.com/llvm/llvm-project/blob/99612a3a18e0c40aac9c52b68e67b106f97ed4fa/mlir/lib/TableGen/Operator.cpp#L526
1 parent 7059178 commit 7aebacb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

mlir/lib/TableGen/Operator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ void Operator::populateTypeInferenceInfo(
503503
for (int otherResultIndex : resultIndices) {
504504
if (resultIndex == otherResultIndex)
505505
continue;
506-
inference[resultIndex].sources.emplace_back(otherResultIndex,
507-
"$_self");
506+
inference[resultIndex].sources.emplace_back(
507+
InferredResultType::unmapResultIndex(otherResultIndex), "$_self");
508508
}
509509
}
510510
}

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

+21
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ def OpL4 : NS_Op<"two_inference_edges", [
180180
// CHECK: inferredReturnTypes[1] = odsInferredType1
181181
// CHECK: inferredReturnTypes[2] = odsInferredType2
182182

183+
def OpL5 : NS_Op<"op_with_same_but_unconstraint_results",
184+
[AllTypesMatch<["result_a", "result_b"]>]> {
185+
let results = (outs AnyType:$result_a, AnyType:$result_b);
186+
}
187+
188+
// CHECK-NOT: LogicalResult OpL5::inferReturnTypes
189+
190+
def OpL6 : NS_Op<"op_with_same_and_constraint_results",
191+
[AllTypesMatch<["result_a", "result_b", "result_c"]>]> {
192+
let results = (outs AnyType:$result_a, AnyType:$result_b, I32:$result_c);
193+
}
194+
195+
// CHECK-LABEL: LogicalResult OpL6::inferReturnTypes
196+
// CHECK-NOT: }
197+
// CHECK: odsInferredType0 = odsBuilder.getIntegerType(32);
198+
// CHECK: odsInferredType1 = odsBuilder.getIntegerType(32);
199+
// CHECK: odsInferredType2 = odsBuilder.getIntegerType(32);
200+
// CHECK: inferredReturnTypes[0] = odsInferredType0;
201+
// CHECK: inferredReturnTypes[1] = odsInferredType1;
202+
// CHECK: inferredReturnTypes[2] = odsInferredType2;
203+
183204
def OpM : NS_Op<"mix_diff_size_variadic_and_normal_results_op", [AttrSizedResultSegments]> {
184205
let results = (outs Variadic<AnyTensor>:$output1, AnyTensor:$output2, Optional<AnyTensor>:$output3);
185206
}

0 commit comments

Comments
 (0)