[Mlir-commits] [mlir] [mlir] Fix type transformation in DropUnitDimFromElementwiseOps (PR #75430)
Jerry Wu
llvmlistbot at llvm.org
Thu Dec 14 00:03:06 PST 2023
================
@@ -1480,17 +1480,24 @@ struct DropUnitDimFromElementwiseOps final
using OpTraitRewritePattern::OpTraitRewritePattern;
LogicalResult matchAndRewrite(Operation *op,
PatternRewriter &rewriter) const override {
- if (op->getNumResults() != 1)
+ if (op->getNumResults() != 1 || op->getNumRegions() != 0)
return failure();
- // Check the pre-condiitions. For `Elementwise` Ops all operands
- // are guaranteed to have identical shapes and it suffices to only check the
- // first one.
- auto op1 = op->getOperands()[0];
- auto sourceVectorType = dyn_cast<VectorType>(op1.getType());
- if (!sourceVectorType)
+ auto resultVectorType = dyn_cast<VectorType>(op->getResult(0).getType());
+ if (!resultVectorType)
return failure();
+ if (llvm::any_of(op->getOperands(), [](auto operand) {
+ return !isa<VectorType>(operand.getType());
+ })) {
+ return failure();
+ }
----------------
pzread wrote:
I'm not quite clear about the definition of elementwise: https://mlir.llvm.org/doxygen/structmlir_1_1OpTrait_1_1Elementwise.html
It seems like operands mixing vectors and tensors are allowed. I decided to remove it and let the `cast<>` fail below if it ever happens
https://github.com/llvm/llvm-project/pull/75430
More information about the Mlir-commits
mailing list