[Mlir-commits] [mlir] fd8bc37 - [mlir][Vector][NFC] Run `extractInsertFoldConstantOp` earlier in the folder (#140814)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed May 21 13:57:04 PDT 2025


Author: Diego Caballero
Date: 2025-05-21T13:57:01-07:00
New Revision: fd8bc37b45867cb345982d05a46345e514813ccb

URL: https://github.com/llvm/llvm-project/commit/fd8bc37b45867cb345982d05a46345e514813ccb
DIFF: https://github.com/llvm/llvm-project/commit/fd8bc37b45867cb345982d05a46345e514813ccb.diff

LOG: [mlir][Vector][NFC] Run `extractInsertFoldConstantOp` earlier in the folder (#140814)

This PR moves `extractInsertFoldConstantOp` earlier in the folder lists
of `vector.extract` and `vector.insert`. Many folders require having
non-dynamic indices so `extractInsertFoldConstantOp` is a requirement
for them to trigger.

Added: 
    

Modified: 
    mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index bbb366b01fa6e..cf2df1f24f91f 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -2143,11 +2143,16 @@ OpFoldResult ExtractOp::fold(FoldAdaptor adaptor) {
   // mismatch).
   if (getNumIndices() == 0 && getVector().getType() == getResult().getType())
     return getVector();
+  if (auto res = foldPoisonSrcExtractOp(adaptor.getVector()))
+    return res;
+  // Fold `arith.constant` indices into the `vector.extract` operation. Make
+  // sure that patterns requiring constant indices are added after this fold.
+  SmallVector<Value> operands = {getVector()};
+  if (auto val = extractInsertFoldConstantOp(*this, adaptor, operands))
+    return val;
   if (auto res = foldPoisonIndexInsertExtractOp(
           getContext(), adaptor.getStaticPosition(), kPoisonIndex))
     return res;
-  if (auto res = foldPoisonSrcExtractOp(adaptor.getVector()))
-    return res;
   if (auto res = foldDenseElementsAttrSrcExtractOp(*this, adaptor.getVector()))
     return res;
   if (succeeded(foldExtractOpFromExtractChain(*this)))
@@ -2166,9 +2171,6 @@ OpFoldResult ExtractOp::fold(FoldAdaptor adaptor) {
     return val;
   if (auto val = foldScalarExtractFromFromElements(*this))
     return val;
-  SmallVector<Value> operands = {getVector()};
-  if (auto val = extractInsertFoldConstantOp(*this, adaptor, operands))
-    return val;
   return OpFoldResult();
 }
 
@@ -3145,6 +3147,8 @@ OpFoldResult vector::InsertOp::fold(FoldAdaptor adaptor) {
   // (type mismatch).
   if (getNumIndices() == 0 && getValueToStoreType() == getType())
     return getValueToStore();
+  // Fold `arith.constant` indices into the `vector.insert` operation. Make
+  // sure that patterns requiring constant indices are added after this fold.
   SmallVector<Value> operands = {getValueToStore(), getDest()};
   if (auto val = extractInsertFoldConstantOp(*this, adaptor, operands))
     return val;


        


More information about the Mlir-commits mailing list