[Mlir-commits] [mlir] [mlir] Rectify mishandling in `InsertOpConstantFolder` causing crash with assertion when using `mlir-opt --canonicalize` (PR #88314)
Mehdi Amini
llvmlistbot at llvm.org
Sat Sep 7 14:30:09 PDT 2024
================
@@ -2896,10 +2896,13 @@ class InsertOpConstantFolder final : public OpRewritePattern<InsertOp> {
linearize(completePositions, computeStrides(destTy.getShape()));
SmallVector<Attribute> insertedValues;
- if (auto denseSource = llvm::dyn_cast<DenseElementsAttr>(sourceCst))
- llvm::append_range(insertedValues, denseSource.getValues<Attribute>());
- else
- insertedValues.push_back(sourceCst);
+ Type destEltType = destTy.getElementType();
+ if (auto denseSource = llvm::dyn_cast<DenseElementsAttr>(sourceCst)) {
+ for (auto value : denseSource.getValues<Attribute>())
+ insertedValues.push_back(castOrConvertAttr(value, destEltType));
+ } else {
+ insertedValues.push_back(castOrConvertAttr(sourceCst, destEltType));
+ }
----------------
joker-eph wrote:
Please document the code block as working around the weirdness of LLVM constant which can hold an attribute with a different type than the return type.
https://github.com/llvm/llvm-project/pull/88314
More information about the Mlir-commits
mailing list