[Mlir-commits] [mlir] [mlir][Vector] Add patterns to lower `vector.shuffle` (PR #157611)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Mon Sep 15 03:10:06 PDT 2025
================
@@ -0,0 +1,106 @@
+//===- LowerVectorShuffle.cpp - Lower 'vector.shuffle' operation ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the lowering of complex `vector.shuffle` operation to a
+// set of simpler operations supported by LLVM/SPIR-V.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Vector/IR/VectorOps.h"
+#include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h"
+#include "mlir/IR/PatternMatch.h"
+
+#define DEBUG_TYPE "vector-shuffle-lowering"
+
+using namespace mlir;
+using namespace mlir::vector;
+
+namespace {
+
+/// Lowers a `vector.shuffle` operation with mix-size inputs to a new
+/// `vector.shuffle` which promotes the smaller input to the larger vector size
+/// and an updated version of the original `vector.shuffle`.
+///
+/// Example:
+///
+/// %0 = vector.shuffle %v1, %v2 [0, 2, 1, 3] : vector<2xf32>, vector<4xf32>
+///
+/// is lowered to:
+///
+/// %0 = vector.shuffle %v1, %v1 [0, 1, -1, -1] :
+/// vector<2xf32>, vector<2xf32>
+/// %1 = vector.shuffle %0, %v2 [0, 4, 1, 5] :
+/// vector<4xf32>, vector<4xf32>
+///
+struct MixSizeInputShuffleOpRewrite final
+ : OpRewritePattern<vector::ShuffleOp> {
+ using OpRewritePattern::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(vector::ShuffleOp shuffleOp,
+ PatternRewriter &rewriter) const override {
+ auto v1Type = shuffleOp.getV1VectorType();
+ auto v2Type = shuffleOp.getV2VectorType();
+
+ // Only support 1-D shuffle for now.
+ if (v1Type.getRank() != 1 || v2Type.getRank() != 1)
+ return failure();
+
+ // No mix-size inputs.
----------------
banach-space wrote:
Is this comment correct?
https://github.com/llvm/llvm-project/pull/157611
More information about the Mlir-commits
mailing list