diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -943,13 +943,21 @@ << ");\n"; } return; - case TypeParamKind::Collective: - body << " " - << "assert(resultTypes.size() " - << (op.getNumVariableLengthResults() == 0 ? "==" : ">=") << " " - << (op.getNumResults() - op.getNumVariableLengthResults()) - << "u && \"mismatched number of results\");\n"; + case TypeParamKind::Collective: { + int numResults = op.getNumResults(); + int numVariadicResults = op.getNumVariableLengthResults(); + int numNonVariadicResults = numResults - numVariadicResults; + bool hasVariadicResult = numVariadicResults != 0; + + // Avoid emitting "resultTypes.size() >= 0u" which is always true. + if (!(hasVariadicResult && numNonVariadicResults == 0)) + body << " " + << "assert(resultTypes.size() " + << (hasVariadicResult ? ">=" : "==") << " " + << numNonVariadicResults + << "u && \"mismatched number of results\");\n"; body << " " << builderOpState << ".addTypes(resultTypes);\n"; + } return; } llvm_unreachable("unhandled TypeParamKind");