[Mlir-commits] [mlir] [mlir] Guard sccp pass from crashing with different source type (PR #120656)

donald chen llvmlistbot at llvm.org
Fri Dec 20 01:19:50 PST 2024


================
@@ -2523,8 +2523,16 @@ OpFoldResult BroadcastOp::fold(FoldAdaptor adaptor) {
   if (!adaptor.getSource())
     return {};
   auto vectorType = getResultVectorType();
-  if (llvm::isa<IntegerAttr, FloatAttr>(adaptor.getSource()))
-    return DenseElementsAttr::get(vectorType, adaptor.getSource());
+  if (auto attr = llvm::dyn_cast<IntegerAttr>(adaptor.getSource())) {
+    if (vectorType.getElementType() != attr.getType())
+      return {};
+    return DenseElementsAttr::get(vectorType, attr);
+  }
+  if (auto attr = llvm::dyn_cast<FloatAttr>(adaptor.getSource())) {
+    if (vectorType.getElementType() != attr.getType())
+      return {};
+    return DenseElementsAttr::get(vectorType, attr);
+  }
----------------
cxy-1993 wrote:

What is the reason for separating the handling of int and float types?

https://github.com/llvm/llvm-project/pull/120656


More information about the Mlir-commits mailing list