[Mlir-commits] [mlir] [mlir][vector] Fix invalid IR in `RewriteBitCastOfTruncI` (PR #78146)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jan 15 03:29:52 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-vector
Author: Matthias Springer (matthias-springer)
<details>
<summary>Changes</summary>
This commit fixes `Dialect/Vector/vector-rewrite-narrow-types.mlir` when running with `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS`.
```
within split at llvm-project/mlir/test/Dialect/Vector/vector-rewrite-narrow-types.mlir:1 offset :118:8: error: 'arith.trunci' op operand type 'vector<3xi16>' and result type 'vector<3xi16>' are cast incompatible
%1 = vector.bitcast %0 : vector<16xi3> to vector<3xi16>
^
within split at llvm-project/mlir/test/Dialect/Vector/vector-rewrite-narrow-types.mlir:1 offset :118:8: note: see current operation: %48 = "arith.trunci"(%47) : (vector<3xi16>) -> vector<3xi16>
LLVM ERROR: IR failed to verify after pattern application
```
---
Full diff: https://github.com/llvm/llvm-project/pull/78146.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp (+8)
``````````diff
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
index ead7d645cb5bb3d..a56bcd14eca0fcb 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
@@ -847,11 +847,19 @@ struct RewriteBitCastOfTruncI : OpRewritePattern<vector::BitCastOp> {
bool narrowing = targetVectorType.getElementTypeBitWidth() <=
shuffledElementType.getIntOrFloatBitWidth();
if (narrowing) {
+ if (runningResult.getType() == bitCastOp.getResultVectorType()) {
+ rewriter.replaceOp(bitCastOp, runningResult);
+ } else {
rewriter.replaceOpWithNewOp<arith::TruncIOp>(
bitCastOp, bitCastOp.getResultVectorType(), runningResult);
+ }
} else {
+ if (runningResult.getType() == bitCastOp.getResultVectorType()) {
+ rewriter.replaceOp(bitCastOp, runningResult);
+ } else {
rewriter.replaceOpWithNewOp<arith::ExtUIOp>(
bitCastOp, bitCastOp.getResultVectorType(), runningResult);
+ }
}
return success();
``````````
</details>
https://github.com/llvm/llvm-project/pull/78146
More information about the Mlir-commits
mailing list