[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:25 PST 2025


================
@@ -1084,8 +1084,8 @@ static LogicalResult alignedConversionPrecondition(PatternRewriter &rewriter,
   unsigned srcElemBitwidth = srcType.getElementTypeBitWidth();
   unsigned dstElemBitwidth = dstType.getElementTypeBitWidth();
 
-  // Only {s}i4 -> (size_of({{s}i/f}) >= 8) are supported for now.
-  if (srcElemBitwidth != 4 || dstElemBitwidth < 8 ||
+  // Only {s}i4/i2 -> (size_of({{s}i/f}) >= 8) are supported for now.
+  if ((srcElemBitwidth != 4 && srcElemBitwidth != 2) || dstElemBitwidth < 8 ||
       (dstElemBitwidth % srcElemBitwidth) != 0)
     return rewriter.notifyMatchFailure(op, "Not a supported aligned case");
----------------
hanhanW wrote:

This statement is becoming more complicated, and it is not easy to parse if the comment match the check or not. How about we break it into three if-statement and collapse the comment into the error message? E.g.,

```cpp
// I feel that it is a requirement for emulation, so we can just say that it must be greater than or equal to 8
if (dstElemBitwidth < 8)
  return rewriter.notifyMatchFailure(op, "the bitwidth of dstType must be greater than or equal to 8");
if (dstElemBitwidth % srcElemBitwidth != 0)
  return ... "unaligned cases are not supported"
if (srcElemBitwidth != 2 && srcElemBitwidth != 4)
  return ... "only support src bitwidth to be 2 or 4 at this moment"
}
```

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


More information about the Mlir-commits mailing list