[Mlir-commits] [mlir] [mlir][Vector] Fix vector.extract lowering to llvm for 0-d vectors (PR #117731)
Kunwar Grover
llvmlistbot at llvm.org
Fri Nov 29 06:56:07 PST 2024
================
@@ -1096,43 +1096,56 @@ class VectorExtractOpConversion
SmallVector<OpFoldResult> positionVec = getMixedValues(
adaptor.getStaticPosition(), adaptor.getDynamicPosition(), rewriter);
- // Extract entire vector. Should be handled by folder, but just to be safe.
- ArrayRef<OpFoldResult> position(positionVec);
- if (position.empty()) {
- rewriter.replaceOp(extractOp, adaptor.getVector());
- return success();
- }
-
- // One-shot extraction of vector from array (only requires extractvalue).
- // Except for extracting 1-element vectors.
- if (isa<VectorType>(resultType) &&
- position.size() !=
- static_cast<size_t>(extractOp.getSourceVectorType().getRank())) {
- if (extractOp.hasDynamicPosition())
- return failure();
-
- Value extracted = rewriter.create<LLVM::ExtractValueOp>(
- loc, adaptor.getVector(), getAsIntegers(position));
- rewriter.replaceOp(extractOp, extracted);
- return success();
- }
+ // The LLVM lowering models multi dimension vectors as stacked 1-d vectors.
+ // The stacking is modeled using arrays. We do this conversion from a
+ // N-d vector extract to stacked 1-d vector extract in two steps:
+ // - Extract a 1-d vector or a stack of 1-d vectors (llvm.extractvalue)
+ // - Extract a scalar out of the 1-d vector if needed (llvm.extractelement)
+
+ // Determine if we need to extract a slice out of the original vector. We
+ // always need to extract a slice if the input rank >= 2.
+ bool isSlicingExtract = extractOp.getSourceVectorType().getRank() >= 2;
----------------
Groverkss wrote:
Done. Let me know if it is clearer now :)
https://github.com/llvm/llvm-project/pull/117731
More information about the Mlir-commits
mailing list