[Mlir-commits] [mlir] [MLIR] Allowing unsupported conv2d op to fail gracefully from vectorization (PR #130181)
Han-Chung Wang
llvmlistbot at llvm.org
Mon Mar 10 15:50:26 PDT 2025
================
@@ -1939,6 +1939,127 @@ vectorizeInsertSliceOpPrecondition(tensor::InsertSliceOp sliceOp,
return success();
}
+namespace {
+bool isCastOfBlockArgument(Operation *op) {
+ return isa<CastOpInterface>(op) && op->getNumOperands() == 1 &&
+ isa<BlockArgument>(op->getOperand(0));
+}
+
+// Returns true iff it is a valid conv/pooling op.
+// If (region has 2 ops (reduction + yield) or 3 ops (extension + reduction
+// + yield) and rhs is not used) then it is the body of a pooling
+// If conv, check for single `mul` predecessor. The `mul` operands must be
+// block arguments or extension of block arguments.
+// Otherwise, check for one or zero `ext` predecessor. The `ext` operands
+// must be block arguments or extension of block arguments.
+enum OperKind { Conv, Pool };
+bool getOperKind(Operation *reduceOp, OperKind &oper) {
+ int numBlockArguments =
+ llvm::count_if(reduceOp->getOperands(), llvm::IsaPred<BlockArgument>);
+
+ switch (numBlockArguments) {
+ case 1: {
+ // Will be convolution if feeder is a MulOp.
+ // A strength reduced version of MulOp for i1 type is AndOp which is also
+ // supported. Otherwise, it can be pooling. This strength reduction logic
+ // is in `buildBinaryFn` helper in the Linalg dialect.
+ auto feedValIt = llvm::find_if_not(reduceOp->getOperands(),
+ llvm::IsaPred<BlockArgument>);
+ Operation *feedOp = (*feedValIt).getDefiningOp();
+ // llvm::outs() << "feedOp: " << *feedOp << "\n";
----------------
hanhanW wrote:
delete the debug code?
https://github.com/llvm/llvm-project/pull/130181
More information about the Mlir-commits
mailing list