[Mlir-commits] [mlir] [mlir][Vector] Add patterns for efficient unsigned i4 -> i8 conversion emulation (PR #89131)

Andrzej WarzyƄski llvmlistbot at llvm.org
Fri Apr 19 09:14:33 PDT 2024


================
@@ -1099,6 +1131,50 @@ struct RewriteAlignedSubByteIntSignedExt : OpRewritePattern<ConversionOpType> {
   }
 };
 
+/// Rewrite the i4 -> i8 part of any unsigned conversion into a sequence of
+/// shuffles and bitwise ops that take advantage of high-level information to
+/// avoid leaving LLVM to scramble with peephole optimizations.
+///
+/// For example:
+///    arith.extui %in : vector<8xi4> to vector<8xi32>
+///      is rewritten as
+///        %0 = vector.bitcast %in : vector<8xi4> to vector<4xi8>
+///        %1 = arith.andi %0, 15 : vector<4xi8>
+///        %2 = arith.shrsi %0, 4 : vector<4xi8>
+///        %3 = vector.interleave %1, %2 : vector<4xi8>
+///        %4 = arith.extsi %3 : vector<8xi8> to vector<8xi32>
----------------
banach-space wrote:

Formatting is off. Also, `arith.extsi` -> `arith.extui` ;-)

```suggestion
///        arith.extui %in : vector<8xi4> to vector<8xi32>
///    is rewritten as
///        %0 = vector.bitcast %in : vector<8xi4> to vector<4xi8>
///        %1 = arith.andi %0, 15 : vector<4xi8>
///        %2 = arith.shrsi %0, 4 : vector<4xi8>
///        %3 = vector.interleave %1, %2 : vector<4xi8>
///        %4 = arith.extsi %3 : vector<8xi8> to vector<8xi32>
```

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


More information about the Mlir-commits mailing list