[Mlir-commits] [mlir] 77655f4 - [mlir][arith] Assert preconditions in `BitcastOp::fold`. (#100743)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jul 29 05:34:51 PDT 2024


Author: Ingo Müller
Date: 2024-07-29T14:34:47+02:00
New Revision: 77655f42d58e85875c4b4e28a73208b64a653c2a

URL: https://github.com/llvm/llvm-project/commit/77655f42d58e85875c4b4e28a73208b64a653c2a
DIFF: https://github.com/llvm/llvm-project/commit/77655f42d58e85875c4b4e28a73208b64a653c2a.diff

LOG: [mlir][arith] Assert preconditions in `BitcastOp::fold`. (#100743)

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 at google.com>

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index aa5eb95a3d22e..641b7d7e2d13b 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -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,


        


More information about the Mlir-commits mailing list