[Mlir-commits] [mlir] Rewrites for I2 to I8 signed and unsigned extension (PR #121298)

Han-Chung Wang llvmlistbot at llvm.org
Mon Jan 6 23:46:24 PST 2025


================
@@ -1172,70 +1172,167 @@ Value BitCastRewriter::genericRewriteStep(
   return runningResult;
 }
 
+Value bitcastSubByteVectorToI8(PatternRewriter &rewriter, Location loc,
+                               Value srcValue) {
+  VectorType srcVecType = cast<VectorType>(srcValue.getType());
+  int64_t srcBitwidth = srcVecType.getElementType().getIntOrFloatBitWidth();
+  assert(srcBitwidth % 8 != 0 && "Invalid source bitwidth");
+  int64_t bitwidthFactor = 8 / srcBitwidth;
+  SmallVector<int64_t> i8VecShape = llvm::to_vector(srcVecType.getShape());
+  i8VecShape.back() = i8VecShape.back() / bitwidthFactor;
+  auto i8VecType = VectorType::get(i8VecShape, rewriter.getI8Type());
+  return rewriter.create<vector::BitCastOp>(loc, i8VecType, srcValue);
+}
+
+/// Extracts a signed N-bit sequence from each element of an 8-bit vector,
+/// starting at the specified bit index.
+Value extractNBitsFromVectorSigned(PatternRewriter &rewriter, Location loc,
----------------
hanhanW wrote:

nit: add `static` keyword to the local function.
[optional]: it looks better if you can have an example in the doc.

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


More information about the Mlir-commits mailing list