[Mlir-commits] [mlir] [mlir][Vector] Refactor VectorEmulateNarrowType.cpp (PR #123529)

Andrzej Warzyński llvmlistbot at llvm.org
Mon Mar 10 08:41:34 PDT 2025


================
@@ -1127,7 +1159,8 @@ struct ConvertVectorTransferRead final
     auto origElements = op.getVectorType().getNumElements();
 
     // Note, per-element-alignment was already verified above.
-    bool isFullyAligned = origElements % emulatedPerContainerElem == 0;
+    bool isFullyAligned =
----------------
banach-space wrote:

Are you suggesting to rename it everywhere? Note that ATM this name is quite widely used throughout this file:
```bash 
$ rg "isFullyAligned" mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp | wc -l
      14
```

I am fine renaming it, though I will ask you for a suggestion 😅 

Perhaps let me start by explaining the rationale for this name. Basically, most patterns implement this high level logic (see e.g. [here](https://github.com/llvm/llvm-project/blob/5ce4045384d7c2544185b0dbcb6222d06beb47dc/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp#L499-L504)):

```cpp
    // Check per-element alignment.
    if (containerBits % emulatedBits != 0) {
      return rewriter.notifyMatchFailure(
          op, "impossible to pack emulated elements into container elements "
              "(bit-wise misalignment)");
    }
    
    // (...) Some code here
    
    // Note, per-element-alignment was already verified above.
    bool isFullyAligned = origElements % emulatedPerContainerElem == 0;
```

As a concrete example:
* `vector<3x2xi2>` is "per-element" aligned with `vector<2xi8>` (because we can fit exactly 4 x `i2` into `i8`)
* `vector<3x2xi2>` is not full aligned with `vector<2xi8>` as (3 x 2 = ) **6 % 4** (= 8 / 2) **!= 0**

Let me know if this makes sense. If not, we can iterate :)

https://github.com/llvm/llvm-project/pull/123529


More information about the Mlir-commits mailing list