[Mlir-commits] [mlir] 636f772 - [mlir][Arith] Make previous load-bearing assert into a real error

Krzysztof Drewniak llvmlistbot at llvm.org
Thu Jul 13 07:49:33 PDT 2023


Author: Krzysztof Drewniak
Date: 2023-07-13T14:49:29Z
New Revision: 636f7728711450fe8a68c7a9b156caab39880a25

URL: https://github.com/llvm/llvm-project/commit/636f7728711450fe8a68c7a9b156caab39880a25
DIFF: https://github.com/llvm/llvm-project/commit/636f7728711450fe8a68c7a9b156caab39880a25.diff

LOG: [mlir][Arith] Make previous load-bearing assert into a real error

When I landed the EmulateUnsupportedFloats, I'd negligently included
an assert that needed to run for the pass to be correct. Previous
emergency fix commits removed the assert. This commit re-adds the
"can't happen" testing as an emitOpError() and aborting the rewrite,
thus allowing it to function in no-assertions builds.

Reviewed By: kuhar

Differential Revision: https://reviews.llvm.org/D155088

Added: 
    

Modified: 
    mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp b/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp
index fba525813e157c..e768940cc27b5b 100644
--- a/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp
@@ -19,6 +19,7 @@
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/Transforms/DialectConversion.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/ErrorHandling.h"
 #include <optional>
 
 namespace mlir::arith {
@@ -81,8 +82,12 @@ void EmulateFloatPattern::rewrite(Operation *op, ArrayRef<Value> operands,
   Location loc = op->getLoc();
   TypeConverter *converter = getTypeConverter();
   SmallVector<Type> resultTypes;
-  LogicalResult pass = converter->convertTypes(op->getResultTypes(), resultTypes);
-  (void) pass;
+  if (failed(converter->convertTypes(op->getResultTypes(), resultTypes))) {
+    // Note to anyone looking for this error message: this is a "can't happen".
+    // If you're seeing it, there's a bug.
+    op->emitOpError("type conversion failed in float emulation");
+    return;
+  }
   Operation *expandedOp =
       rewriter.create(loc, op->getName().getIdentifier(), operands, resultTypes,
                       op->getAttrs(), op->getSuccessors(), /*regions=*/{});


        


More information about the Mlir-commits mailing list