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

Diego Caballero llvmlistbot at llvm.org
Sat Nov 16 18:38:02 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());
----------------
dcaballe wrote:

Could you please check that this works with a 0-D vector?

Also, mind renaming this to something like `getFirstElementAsInt` or similar? The name is misleading as this is not looking for the first integer element found in the list, which is what I would expect from the current name.

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


More information about the Mlir-commits mailing list