[Mlir-commits] [mlir] [mlir][x86vector] Sink Vector.transfer_reads and vector.load before the consumer (PR #169333)
Arun Thangamani
llvmlistbot at llvm.org
Tue Dec 9 21:11:01 PST 2025
================
@@ -0,0 +1,148 @@
+//===- SinkVectorProducerOps.cpp ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Vector/IR/VectorOps.h"
+#include "mlir/Dialect/Vector/Utils/VectorUtils.h"
+#include "mlir/Dialect/X86Vector/Transforms.h"
+#include "mlir/Dialect/X86Vector/X86VectorDialect.h"
+
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Dominance.h"
+#include "mlir/IR/PatternMatch.h"
+
+#include "mlir/Pass/Pass.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+
+using namespace mlir;
+using namespace mlir::vector;
+using namespace mlir::x86vector;
+
+static FailureOr<llvm::SmallVector<Operation *>> getAllUsers(Operation *op) {
+ llvm::SmallVector<Operation *> opUsers;
+ for (OpResult result : op->getResults()) {
+ for (Operation *user : result.getUsers()) {
+ // Check prod and users belongs to same block.
+ if (op->getBlock() != user->getBlock())
+ return failure();
+ opUsers.push_back(user);
+ }
+ }
+
+ return opUsers;
+}
+
+// Prevent pathological looping:
+// If two/three producers are used by same consumer, will end in looping of
+// moving the producers.
+// For example:
+// %1 = prod1
+// %2 = prod2
+// %3 = prod3
+// %4 = op %1, %2, %3
+static bool checkLooping(Operation *op) {
+ llvm::SmallVector<Operation *> operations;
+ operations.push_back(op);
+
+ // Retrive the next immediate two/three operation until it is a vector.load or
+ // a vector.transfer_read
+ Operation *nextOp = op->getNextNode();
+ while (operations.size() < 3 && nextOp) {
----------------
arun-thmn wrote:
Okay. Removed the constant limit.
https://github.com/llvm/llvm-project/pull/169333
More information about the Mlir-commits
mailing list