From bdd56eca49fc56677b06029747835deafa3bca03 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 10 Apr 2019 08:00:34 -0700 Subject: [PATCH] Remove checks guaranteed to be true by the type This addresses the compiler wraning of "comparison of unsigned expression >= 0 is always true [-Wtype-limits]". -- PiperOrigin-RevId: 242868703 --- mlir/lib/Analysis/AffineStructures.cpp | 2 +- mlir/lib/Transforms/MaterializeVectors.cpp | 3 +-- mlir/test/mlir-tblgen/op-operand.td | 19 ++++++++++++++----- mlir/test/mlir-tblgen/op-result.td | 11 +++++++++++ mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 18 ++++++++++-------- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/mlir/lib/Analysis/AffineStructures.cpp b/mlir/lib/Analysis/AffineStructures.cpp index c38881a1..5ffc749 100644 --- a/mlir/lib/Analysis/AffineStructures.cpp +++ b/mlir/lib/Analysis/AffineStructures.cpp @@ -928,7 +928,7 @@ static void eliminateFromConstraint(FlatAffineConstraints *constraints, static void shiftColumnsToLeft(FlatAffineConstraints *constraints, unsigned colStart, unsigned colLimit, bool isEq) { - assert(colStart >= 0 && colLimit <= constraints->getNumIds()); + assert(colLimit <= constraints->getNumIds()); if (colLimit <= colStart) return; diff --git a/mlir/lib/Transforms/MaterializeVectors.cpp b/mlir/lib/Transforms/MaterializeVectors.cpp index df29c8e..76dbdaf 100644 --- a/mlir/lib/Transforms/MaterializeVectors.cpp +++ b/mlir/lib/Transforms/MaterializeVectors.cpp @@ -229,8 +229,7 @@ static SmallVector delinearize(unsigned linearIndex, assert(strides[idx] > 0); auto val = linearIndex / strides[idx]; res.push_back(val); - assert((val >= 0 && val < shape[idx]) && - "delinearization is out of bounds"); + assert(val < shape[idx] && "delinearization is out of bounds"); linearIndex %= strides[idx]; } // Sanity check. diff --git a/mlir/test/mlir-tblgen/op-operand.td b/mlir/test/mlir-tblgen/op-operand.td index 3dd2754..132d382 100644 --- a/mlir/test/mlir-tblgen/op-operand.td +++ b/mlir/test/mlir-tblgen/op-operand.td @@ -2,21 +2,30 @@ include "mlir/IR/OpBase.td" -def OneOperandOp : Op<"one_operand_op", []> { +def OpA : Op<"one_operand_op", []> { let arguments = (ins I32:$input); } -// CHECK-LABEL: OneOperandOp definitions +// CHECK-LABEL: OpA definitions -// CHECK: void OneOperandOp::build +// CHECK: void OpA::build // CHECK-SAME: Value *input // CHECK: tblgen_state->addOperands({input}); -// CHECK: void OneOperandOp::build +// CHECK: void OpA::build // CHECK-SAME: ArrayRef operands // CHECK: assert(operands.size() == 1u && "mismatched number of parameters"); // CHECK: tblgen_state->addOperands(operands); -// CHECK: LogicalResult OneOperandOp::verify() { +// CHECK: LogicalResult OpA::verify() { // CHECK: if (!((this->getOperation()->getOperand(0)->getType().isInteger(32)))) // CHECK-NEXT: return emitOpError("operand #0 must be 32-bit integer"); + +def OpB : Op<"variadic_operand_op", []> { + let arguments = (ins Variadic:$input); +} + +// CHECK-LABEL: OpB::build +// CHECK-SAME: ArrayRef input +// CHECK-NOT: assert +// CHECK: tblgen_state->addOperands(input); diff --git a/mlir/test/mlir-tblgen/op-result.td b/mlir/test/mlir-tblgen/op-result.td index 11b6cc2..06bc3b4 100644 --- a/mlir/test/mlir-tblgen/op-result.td +++ b/mlir/test/mlir-tblgen/op-result.td @@ -56,6 +56,17 @@ def ValueAttrResultTypeOp : Op<"value_attr_as_result_type", [FirstAttrDerivedRes // CHECK: void ValueAttrResultTypeOp::build(Builder *, OperationState *tblgen_state, Value *x, FloatAttr attr) // CHECK: tblgen_state->addTypes({attr.getType()}); +def VariadicResultAloneOp : Op<"variadic_alone_op", []> { + let results = (outs Variadic:$x); +} + +// CHECK-LABEL: VariadicResultAloneOp definitions + +// CHECK-LABEL: void VariadicResultAloneOp::build +// CHECK-SAME: ArrayRef x +// CHECK-NOT: assert +// CHECK: tblgen_state->addTypes(x); + def VariadicResultOp : Op<"variadic_op", []> { let results = (outs I32:$x, Variadic:$y); } diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 7c3a6cf..122e579 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -696,16 +696,18 @@ void OpEmitter::genBuilder() { auto &body = m.body(); // Result types - body << " assert(resultTypes.size()" << (hasVariadicResult ? " >= " : " == ") - << numNonVariadicResults - << "u && \"mismatched number of return types\");\n" - << " " << builderOpState << "->addTypes(resultTypes);\n"; + if (!(hasVariadicResult && numNonVariadicResults == 0)) + body << " assert(resultTypes.size()" + << (hasVariadicResult ? " >= " : " == ") << numNonVariadicResults + << "u && \"mismatched number of return types\");\n"; + body << " " << builderOpState << "->addTypes(resultTypes);\n"; // Operands - body << " assert(operands.size()" << (hasVariadicOperand ? " >= " : " == ") - << numNonVariadicOperands - << "u && \"mismatched number of parameters\");\n" - << " " << builderOpState << "->addOperands(operands);\n\n"; + if (!(hasVariadicOperand && numNonVariadicOperands == 0)) + body << " assert(operands.size()" << (hasVariadicOperand ? " >= " : " == ") + << numNonVariadicOperands + << "u && \"mismatched number of parameters\");\n"; + body << " " << builderOpState << "->addOperands(operands);\n\n"; // Attributes body << " for (const auto& pair : attributes)\n" -- 2.7.4