[Mlir-commits] [mlir] c52a5f2 - MLIR][STD] Fold trunci (sexti).
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Mar 28 23:49:18 PDT 2021
Author: KareemErgawy-TomTom
Date: 2021-03-29T08:34:08+02:00
New Revision: c52a5f2aa7966ec6a7acec8e4d026093c927f22c
URL: https://github.com/llvm/llvm-project/commit/c52a5f2aa7966ec6a7acec8e4d026093c927f22c
DIFF: https://github.com/llvm/llvm-project/commit/c52a5f2aa7966ec6a7acec8e4d026093c927f22c.diff
LOG: MLIR][STD] Fold trunci (sexti).
This patch folds the following pattern:
```
%arg0 = ...
%0 = sexti %arg0 : i1 to i8
%1 = trunci %0 : i8 to i1
```
into just `%arg0`.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D99464
Added:
Modified:
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/test/Transforms/canonicalize.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
index 4b53bf47b6e5..3dad958887b5 100644
--- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -2183,7 +2183,9 @@ static LogicalResult verify(TruncateIOp op) {
OpFoldResult TruncateIOp::fold(ArrayRef<Attribute> operands) {
// trunci(zexti(a)) -> a
- if (matchPattern(getOperand(), m_Op<ZeroExtendIOp>()))
+ // trunci(sexti(a)) -> a
+ if (matchPattern(getOperand(), m_Op<ZeroExtendIOp>()) ||
+ matchPattern(getOperand(), m_Op<SignExtendIOp>()))
return getOperand().getDefiningOp()->getOperand(0);
return nullptr;
diff --git a/mlir/test/Transforms/canonicalize.mlir b/mlir/test/Transforms/canonicalize.mlir
index fdf6f880ffec..e1869ac58f52 100644
--- a/mlir/test/Transforms/canonicalize.mlir
+++ b/mlir/test/Transforms/canonicalize.mlir
@@ -1109,3 +1109,14 @@ func @do_not_fold_trunci_vector(%arg0: vector<4xi1>) -> vector<4xi2> attributes
%1 = trunci %0 : vector<4xi8> to vector<4xi2>
return %1 : vector<4xi2>
}
+
+// -----
+
+// CHECK-LABEL: func @fold_trunci_sexti
+// CHECK-SAME: (%[[ARG0:[0-9a-z]*]]: i1)
+func @fold_trunci_sexti(%arg0: i1) -> i1 attributes {} {
+ // CHECK-NEXT: return %[[ARG0]] : i1
+ %0 = sexti %arg0 : i1 to i8
+ %1 = trunci %0 : i8 to i1
+ return %1 : i1
+}
More information about the Mlir-commits
mailing list