Skip to content

Commit bfdbd71

Browse files
committed
add assertions
1 parent 0ce2576 commit bfdbd71

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mlir/include/mlir/Dialect/Arith/IR/Arith.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ Value getReductionOp(AtomicRMWKind op, OpBuilder &builder, Location loc,
155155

156156
arith::CmpIPredicate invertPredicate(arith::CmpIPredicate pred);
157157

158-
/// Creates an `arith.constant` operation with a zero value of type `type`.
158+
/// Creates an `arith.constant` operation with a zero value of type `type`. This
159+
/// method asserts if `type` is invalid for representing zero with
160+
/// `arith.constant`.
159161
Value getZeroConstant(OpBuilder &builder, Location loc, Type type);
160162
} // namespace arith
161163
} // namespace mlir

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ bool arith::ConstantIndexOp::classof(Operation *op) {
294294

295295
Value mlir::arith::getZeroConstant(OpBuilder &builder, Location loc,
296296
Type type) {
297-
return builder.create<arith::ConstantOp>(loc, builder.getZeroAttr(type));
297+
// TODO: Incorporate this check to `FloatAttr::get*`.
298+
assert(!isa<Float8E8M0FNUType>(getElementTypeOrSelf(type)) &&
299+
"type doesn't have a zero representation");
300+
TypedAttr zeroAttr = builder.getZeroAttr(type);
301+
assert(zeroAttr && "unsupported type for zero attribute");
302+
return builder.create<arith::ConstantOp>(loc, zeroAttr);
298303
}
299304

300305
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)