From ec60229cdd57290eea282b503cd0daca9e5c9079 Mon Sep 17 00:00:00 2001 From: hanhanW Date: Thu, 12 Mar 2026 15:14:11 -0700 Subject: [PATCH 1/2] [Codegen] Retire VectorizeIREEVectorExtOps pass. The VectorExt ops implement vectorization through VectorizableOpInterface, and it is fully migrated to GenericVectorization.cpp. Thus, the pass can be retired. Signed-off-by: hanhanW --- .../Dialect/VectorExt/Transforms/BUILD.bazel | 2 - .../VectorExt/Transforms/CMakeLists.txt | 2 - .../Dialect/VectorExt/Transforms/Passes.td | 8 --- .../Transforms/VectorizeIREEVectorExtOps.cpp | 56 ------------------- .../test/vectorize_vector_ext_ops.mlir | 2 +- .../iree/compiler/Codegen/LLVMGPU/Passes.cpp | 3 - 6 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/VectorizeIREEVectorExtOps.cpp diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/BUILD.bazel b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/BUILD.bazel index e6a8d2a5dc00..8827f142ae2f 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/BUILD.bazel +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/BUILD.bazel @@ -40,7 +40,6 @@ iree_compiler_cc_library( "LowerTransferGatherOps.cpp", "Passes.cpp", "VectorExtFoldUnitExtentDims.cpp", - "VectorizeIREEVectorExtOps.cpp", ], hdrs = [ "BufferizationInterfaces.h", @@ -52,7 +51,6 @@ iree_compiler_cc_library( deps = [ ":PassesIncGen", "//compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR:IREEVectorExtDialect", - "//compiler/src/iree/compiler/Codegen/Interfaces:VectorizableOpInterface", "@llvm-project//llvm:Support", "@llvm-project//mlir:ArithDialect", "@llvm-project//mlir:BufferizationDialect", diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/CMakeLists.txt b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/CMakeLists.txt index 232c7de7ef3e..57219b5ebd05 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/CMakeLists.txt +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/CMakeLists.txt @@ -34,7 +34,6 @@ iree_cc_library( "LowerTransferGatherOps.cpp" "Passes.cpp" "VectorExtFoldUnitExtentDims.cpp" - "VectorizeIREEVectorExtOps.cpp" DEPS ::PassesIncGen LLVMSupport @@ -52,7 +51,6 @@ iree_cc_library( MLIRVectorDialect MLIRVectorUtils iree::compiler::Codegen::Dialect::VectorExt::IR::IREEVectorExtDialect - iree::compiler::Codegen::Interfaces::VectorizableOpInterface PUBLIC ) diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/Passes.td b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/Passes.td index 583be30219bb..8c54b88692db 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/Passes.td +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/Passes.td @@ -9,14 +9,6 @@ include "mlir/Pass/PassBase.td" -def VectorizeIREEVectorExtOpsPass : - Pass<"iree-vector-ext-vectorize-ops", ""> { - let summary = "Vectorizes then lowers a few iree_vector_ext ops before vectorization."; - let dependentDialects = [ - "::mlir::iree_compiler::IREE::VectorExt::IREEVectorExtDialect" - ]; -} - def VectorExtFoldUnitExtentDimsPass : Pass<"iree-vector-ext-fold-unit-extent-dims", ""> { let summary = "Folds unit dims for iree_vector_ext ops"; diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/VectorizeIREEVectorExtOps.cpp b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/VectorizeIREEVectorExtOps.cpp deleted file mode 100644 index 4491e6149ed1..000000000000 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/VectorizeIREEVectorExtOps.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2024 The IREE Authors -// -// Licensed 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 "iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtDialect.h" -#include "iree/compiler/Codegen/Dialect/VectorExt/Transforms/Passes.h" -#include "iree/compiler/Codegen/Interfaces/VectorizableOpInterface.h" -#include "mlir/Transforms/GreedyPatternRewriteDriver.h" - -namespace mlir::iree_compiler::IREE::VectorExt { - -#define GEN_PASS_DEF_VECTORIZEIREEVECTOREXTOPSPASS -#include "iree/compiler/Codegen/Dialect/VectorExt/Transforms/Passes.h.inc" - -namespace { - -struct VectorizeToLayoutOpPattern final - : OpRewritePattern { - using Base::Base; - - LogicalResult matchAndRewrite(IREE::VectorExt::ToLayoutOp toLayoutOp, - PatternRewriter &rewriter) const override { - auto vectorizableOp = - cast(toLayoutOp.getOperation()); - SmallVector vectorSizes; - SmallVector scalableDims; - if (!vectorizableOp.isVectorizable(vectorSizes, scalableDims)) { - return failure(); - } - FailureOr> result = - vectorizableOp.vectorize(rewriter, vectorSizes, scalableDims); - if (failed(result)) { - return failure(); - } - rewriter.replaceOp(toLayoutOp, *result); - return success(); - } -}; - -struct VectorizeIREEVectorExtOpsPass final - : impl::VectorizeIREEVectorExtOpsPassBase { - void runOnOperation() override { - MLIRContext *ctx = &getContext(); - RewritePatternSet patterns(ctx); - patterns.add(ctx); - if (failed(applyPatternsGreedily(getOperation(), std::move(patterns)))) { - return signalPassFailure(); - } - } -}; - -} // namespace - -} // namespace mlir::iree_compiler::IREE::VectorExt diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/test/vectorize_vector_ext_ops.mlir b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/test/vectorize_vector_ext_ops.mlir index c18c9ed041f2..7b5d2aa346de 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/test/vectorize_vector_ext_ops.mlir +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/Transforms/test/vectorize_vector_ext_ops.mlir @@ -1,4 +1,4 @@ -// RUN: iree-opt %s -pass-pipeline='builtin.module(func.func(iree-vector-ext-vectorize-ops, iree-codegen-generic-vectorization{enable-vector-masking=true}),canonicalize,cse,func.func(iree-codegen-optimize-tensor-insert-extract-slices),canonicalize)' --split-input-file --mlir-print-local-scope | FileCheck %s +// RUN: iree-opt %s -pass-pipeline='builtin.module(func.func(iree-codegen-generic-vectorization{enable-vector-masking=true}),canonicalize,cse,func.func(iree-codegen-optimize-tensor-insert-extract-slices),canonicalize)' --split-input-file --mlir-print-local-scope | FileCheck %s #layout = #iree_vector_ext.nested_layout< subgroup_tile = [1, 1], diff --git a/compiler/src/iree/compiler/Codegen/LLVMGPU/Passes.cpp b/compiler/src/iree/compiler/Codegen/LLVMGPU/Passes.cpp index 6fe6830674fe..8f54ed19faef 100644 --- a/compiler/src/iree/compiler/Codegen/LLVMGPU/Passes.cpp +++ b/compiler/src/iree/compiler/Codegen/LLVMGPU/Passes.cpp @@ -14,7 +14,6 @@ #include "iree/compiler/Codegen/Common/Passes.h" #include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenOps.h" #include "iree/compiler/Codegen/Dialect/GPU/Transforms/Passes.h" -#include "iree/compiler/Codegen/Dialect/VectorExt/Transforms/Passes.h" #include "iree/compiler/Codegen/LLVMGPU/Passes.h" #include "iree/compiler/Codegen/LLVMGPU/ROCDLPasses.h" #include "iree/compiler/Codegen/Utils/GPUUtils.h" @@ -274,8 +273,6 @@ static void addGPUVectorizationPasses(OpPassManager &funcPassManager, funcPassManager.addPass(IREE::LinalgExt::createDecomposeIm2colPass()); funcPassManager.addPass(createCanonicalizerPass()); funcPassManager.addPass(createCSEPass()); - funcPassManager.addPass( - IREE::VectorExt::createVectorizeIREEVectorExtOpsPass()); funcPassManager.addPass(IREE::GPU::createVectorizeIREEGPUOpsPass()); // Vectorize. GenericVectorizationPassOptions options; From 88328d7be43bcd06be4a10cf14f2e0a7f5b942cb Mon Sep 17 00:00:00 2001 From: hanhanW Date: Fri, 13 Mar 2026 11:19:57 -0700 Subject: [PATCH 2/2] Implemnet ValueBound interface for the op Signed-off-by: hanhanW --- .../iree/compiler/Codegen/Dialect/VectorExt/IR/BUILD.bazel | 2 ++ .../compiler/Codegen/Dialect/VectorExt/IR/CMakeLists.txt | 1 + .../Codegen/Dialect/VectorExt/IR/VectorExtDialect.h | 1 + .../compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.cpp | 6 ++++++ .../compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.td | 5 ++++- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/BUILD.bazel b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/BUILD.bazel index 9116b68ae22d..35f2901b1833 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/BUILD.bazel +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/BUILD.bazel @@ -38,6 +38,7 @@ iree_td_library( "@llvm-project//mlir:InferTypeOpInterfaceTdFiles", "@llvm-project//mlir:OpBaseTdFiles", "@llvm-project//mlir:SideEffectInterfacesTdFiles", + "@llvm-project//mlir:ValueBoundsOpInterfaceTdFiles", "@llvm-project//mlir:VectorInterfacesTdFiles", ], ) @@ -82,6 +83,7 @@ iree_compiler_cc_library( "@llvm-project//mlir:SideEffectInterfaces", "@llvm-project//mlir:Support", "@llvm-project//mlir:TensorDialect", + "@llvm-project//mlir:ValueBoundsOpInterface", "@llvm-project//mlir:VectorDialect", "@llvm-project//mlir:VectorInterfaces", ], diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/CMakeLists.txt b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/CMakeLists.txt index 39eae8917aab..472d6d196e8e 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/CMakeLists.txt +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/CMakeLists.txt @@ -45,6 +45,7 @@ iree_cc_library( MLIRSideEffectInterfaces MLIRSupport MLIRTensorDialect + MLIRValueBoundsOpInterface MLIRVectorDialect MLIRVectorInterfaces iree::compiler::Codegen::Utils::VectorOpUtils diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtDialect.h b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtDialect.h index 7f3fde11568f..9040ebdcd887 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtDialect.h +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtDialect.h @@ -14,6 +14,7 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" #include "mlir/Interfaces/SideEffectInterfaces.h" +#include "mlir/Interfaces/ValueBoundsOpInterface.h" #include "mlir/Interfaces/VectorInterfaces.h" // clang-format off: must be included after all LLVM/MLIR headers diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.cpp b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.cpp index 7f8f1d1eeaff..268768dd8e19 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.cpp +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.cpp @@ -11,6 +11,7 @@ #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/TypeUtilities.h" +#include "mlir/Interfaces/ValueBoundsOpInterface.h" using namespace mlir; using namespace mlir::iree_compiler::IREE::VectorExt; @@ -26,6 +27,11 @@ LogicalResult ToLayoutOp::verify() { return getLayout().isValidLayout(getInput().getType(), getLoc()); } +void ToLayoutOp::populateBoundsForShapedValueDim( + Value value, int64_t dim, ValueBoundsConstraintSet &cstr) { + cstr.bound(value)[dim] == cstr.getExpr(getInput(), dim); +} + // to_simd -> to_simt OpFoldResult ToSIMDOp::fold(FoldAdaptor) { if (auto simtOp = getOperand().getDefiningOp()) { diff --git a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.td b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.td index b7ff3f5f4940..99ecd5a4da99 100644 --- a/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.td +++ b/compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtOps.td @@ -14,6 +14,7 @@ include "iree/compiler/Codegen/Dialect/VectorExt/IR/VectorExtInterfaces.td" include "mlir/IR/OpBase.td" include "mlir/Interfaces/ControlFlowInterfaces.td" include "mlir/Interfaces/SideEffectInterfaces.td" +include "mlir/Interfaces/ValueBoundsOpInterface.td" //===----------------------------------------------------------------------===// // Base class. @@ -29,7 +30,9 @@ class IREEVectorExt_PureOp traits = []> : def IREEVectorExt_ToLayoutOp : IREEVectorExt_PureOp<"to_layout", [ Pure, - AllTypesMatch<["input", "output"]> + AllTypesMatch<["input", "output"]>, + DeclareOpInterfaceMethods ]> { let summary = [{Layout conversion operator.}]; let description = [{