Skip to content

Commit

Permalink
[mlir][arith] Assert preconditions in BitcastOp::fold. (llvm#100743)
Browse files Browse the repository at this point in the history
This PR adds an assertion to `BitcastOp::fold` that fails if that
function is called on invalid IR. That can happen when patterns, passes,
etc. create (invalid) IR using builders and folding is triggered on that
IR before verification, for example, through `OpBuilder::createOrFold`.
The new assert triggers earlier than previously in order to help getting
to the root cause faster.

Signed-off-by: Ingo Müller <ingomueller@google.com>
  • Loading branch information
ingomueller-net committed Jul 29, 2024
1 parent 13d39cb commit 77655f4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mlir/lib/Dialect/Arith/IR/ArithOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,8 @@ OpFoldResult arith::BitcastOp::fold(FoldAdaptor adaptor) {
APInt bits = llvm::isa<FloatAttr>(operand)
? llvm::cast<FloatAttr>(operand).getValue().bitcastToAPInt()
: llvm::cast<IntegerAttr>(operand).getValue();
assert(resType.getIntOrFloatBitWidth() == bits.getBitWidth() &&
"trying to fold on broken IR: operands have incompatible types");

if (auto resFloatType = llvm::dyn_cast<FloatType>(resType))
return FloatAttr::get(resType,
Expand Down

0 comments on commit 77655f4

Please sign in to comment.