Commit 256d4481 authored by Rahul Joshi's avatar Rahul Joshi
Browse files

[MLIR] [TableGen] Avoid generating an assert which is always true.

- Avoid generating "assert(resultTypes.size() >= 0u)" which is always true

Differential Revision: https://reviews.llvm.org/D83735
parent 322e7cfa
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -943,13 +943,21 @@ void OpEmitter::genSeparateArgParamBuilder() {
             << ");\n";
      }
      return;
    case TypeParamKind::Collective:
    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() "
           << (op.getNumVariableLengthResults() == 0 ? "==" : ">=") << " "
           << (op.getNumResults() - op.getNumVariableLengthResults())
             << (hasVariadicResult ? ">=" : "==") << " "
             << numNonVariadicResults
             << "u && \"mismatched number of results\");\n";
      body << "  " << builderOpState << ".addTypes(resultTypes);\n";
    }
      return;
    }
    llvm_unreachable("unhandled TypeParamKind");