[Mlir-commits] [mlir] [MLIR] Fix `BubbleDownVectorBitCastForExtract` crash on non-static index (PR #116518)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Nov 16 19:30:05 PST 2024


================
@@ -596,12 +596,18 @@ struct BubbleDownVectorBitCastForExtract
     unsigned expandRatio =
         castDstType.getNumElements() / castSrcType.getNumElements();
 
-    auto getFirstIntValue = [](ArrayRef<OpFoldResult> values) -> uint64_t {
-      assert(values[0].is<Attribute>() && "Unexpected non-constant index");
+    auto getFirstIntValue =
+        [](ArrayRef<OpFoldResult> values) -> std::optional<uint64_t> {
+      if (!values[0].is<Attribute>())
+        return std::nullopt;
       return cast<IntegerAttr>(values[0].get<Attribute>()).getInt();
     };
 
-    uint64_t index = getFirstIntValue(extractOp.getMixedPosition());
+    std::optional<uint64_t> optIndex =
+        getFirstIntValue(extractOp.getMixedPosition());
----------------
lialan wrote:

@dcaballe 0-D vector is already supported, it is being tested here: https://github.com/llvm/llvm-project/blob/91342ccb77fec96a3ce77e8e125090f917272865/mlir/test/Dialect/Vector/vector-transforms.mlir#L432

Some small update: this is a one-use lambda so I inlined it and added some comments. Please take a look again.

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


More information about the Mlir-commits mailing list