Skip to content

Commit

Permalink
changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
gitoleg committed Apr 17, 2024
1 parent 8e107d7 commit e43c387
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
16 changes: 10 additions & 6 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,21 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return create<mlir::cir::StoreOp>(loc, val, dst, _volatile, order);
}

mlir::Value createSub(mlir::Value lhs, mlir::Value rhs) {
return createBinop(lhs, mlir::cir::BinOpKind::Sub, rhs);
}

mlir::Value createNSWSub(mlir::Value lhs, mlir::Value rhs) {
mlir::Value createSub(mlir::Value lhs, mlir::Value rhs,
bool hasNUW = false, bool hasNSW = false) {
auto op = create<mlir::cir::BinOp>(lhs.getLoc(), lhs.getType(),
mlir::cir::BinOpKind::Sub, lhs, rhs);
op.setNoSignedWrap(true);
if (hasNUW)
op.setNoUnsignedWrap(true);
if (hasNSW)
op.setNoSignedWrap(true);
return op;
}

mlir::Value createNSWSub(mlir::Value lhs, mlir::Value rhs) {
return createSub(lhs, rhs, false, true);
}

//===--------------------------------------------------------------------===//
// Cast/Conversion Operators
//===--------------------------------------------------------------------===//
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2777,8 +2777,8 @@ LogicalResult BinOp::verify() {
getKind() == mlir::cir::BinOpKind::Mul;

if (noWrap && !noWrapOps)
return emitError() << "The nsw/nuw flags are applicable to Add, Sub and "
"Mul operations only";
return emitError() <<
"The nsw/nuw flags are applicable to opcodes: 'add', 'sub' and 'mul'";

return mlir::success();
}
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1033,3 +1033,19 @@ cir.func @bad_fetch(%x: !cir.ptr<!cir.float>, %y: !cir.float) -> () {
%12 = cir.atomic.fetch(xor, %x : !cir.ptr<!cir.float>, %y : !cir.float, seq_cst) : !cir.float
cir.return
}

// -----

cir.func @bad_operands_for_nowrap(%x: !cir.float, %y: !cir.float) {
// expected-error@+1 {{only operations on integer values may have nsw/nuw flags}}
%0 = cir.binop(add, %x, %y) nsw : !cir.float
}

// -----

!u32i = !cir.int<u, 32>

cir.func @bad_binop_for_nowrap(%x: !u32i, %y: !u32i) {
// expected-error@+1 {{The nsw/nuw flags are applicable to opcodes: 'add', 'sub' and 'mul'}}
%0 = cir.binop(div, %x, %y) nsw : !u32i
}

0 comments on commit e43c387

Please sign in to comment.