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
This commit is contained in:
Lei Zhang 2019-04-10 08:00:34 -07:00 committed by Mehdi Amini
parent 2e7895d5f1
commit bdd56eca49
5 changed files with 37 additions and 16 deletions

View File

@ -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;

View File

@ -229,8 +229,7 @@ static SmallVector<unsigned, 8> 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.

View File

@ -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<Value *> 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<I32>:$input);
}
// CHECK-LABEL: OpB::build
// CHECK-SAME: ArrayRef<Value *> input
// CHECK-NOT: assert
// CHECK: tblgen_state->addOperands(input);

View File

@ -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<I32>:$x);
}
// CHECK-LABEL: VariadicResultAloneOp definitions
// CHECK-LABEL: void VariadicResultAloneOp::build
// CHECK-SAME: ArrayRef<Type> x
// CHECK-NOT: assert
// CHECK: tblgen_state->addTypes(x);
def VariadicResultOp : Op<"variadic_op", []> {
let results = (outs I32:$x, Variadic<I32>:$y);
}

View File

@ -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"