[Mlir-commits] [mlir] [mlir][vector] Add i8 to i2 truncation to the narrow type rewrites (PR #221185)
Hung-Kuan Tseng
llvmlistbot at llvm.org
Sun Nov 1 05:31:53 PST 2026
================
@@ -1976,6 +1976,57 @@ static Value rewriteI8ToI4Trunc(PatternRewriter &rewriter, Location loc,
return vector::BitCastOp::create(rewriter, loc, i4VecType, mergedHiLowOp);
}
+/// Rewrite the i8 -> i2 truncation into two levels of deinterleave and a
+/// series of bitwise ops to avoid leaving LLVM to scramble with peephole
+/// optimizations.
+static Value rewriteI8ToI2Trunc(PatternRewriter &rewriter, Location loc,
+ Value srcValue) {
+ VectorType srcVecType = cast<VectorType>(srcValue.getType());
+ assert(srcVecType.getElementType().isSignlessInteger(8) &&
+ "Expected i8 type");
+
+ // 1. De-interleave twice to group the i8 elements by their position within
+ // the destination byte.
+ // in = [0,1,2,3,4,5,6,7],...
+ // evenOdd = [0,2,4,6],... [1,3,5,7],...
+ // vec0 = [0,4],...
+ // vec1 = [1,5],...
+ // vec2 = [2,6],...
+ // vec3 = [3,7],...
----------------
Tim096 wrote:
Updated the comment to `vec02` and `vec13`, since each of them holds two groups.
https://github.com/llvm/llvm-project/pull/221185
More information about the Mlir-commits
mailing list