[Mlir-commits] [mlir] 701a282 - [mlir][Vector] Fold consecutive bitcast.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jun 14 19:46:14 PDT 2022


Author: jacquesguan
Date: 2022-06-15T10:45:05+08:00
New Revision: 701a282af47e333be9bd751105599b90cc91fba7

URL: https://github.com/llvm/llvm-project/commit/701a282af47e333be9bd751105599b90cc91fba7
DIFF: https://github.com/llvm/llvm-project/commit/701a282af47e333be9bd751105599b90cc91fba7.diff

LOG: [mlir][Vector] Fold consecutive bitcast.

This patch supports to fold consecutive bitcast into one bitcast.

Differential Revision: https://reviews.llvm.org/D127723

Added: 
    

Modified: 
    mlir/lib/Dialect/Vector/IR/VectorOps.cpp
    mlir/test/Dialect/Vector/canonicalize.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index eb0ba4c9497d0..87ef39272aec9 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -4239,10 +4239,14 @@ OpFoldResult BitCastOp::fold(ArrayRef<Attribute> operands) {
     return getSource();
 
   // Canceling bitcasts.
-  if (auto otherOp = getSource().getDefiningOp<BitCastOp>())
+  if (auto otherOp = getSource().getDefiningOp<BitCastOp>()) {
     if (getResult().getType() == otherOp.getSource().getType())
       return otherOp.getSource();
 
+    setOperand(otherOp.getSource());
+    return getResult();
+  }
+
   Attribute sourceConstant = operands.front();
   if (!sourceConstant)
     return {};

diff  --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index 152d0d241685c..e066e19eb9137 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -1605,3 +1605,14 @@ func.func @dont_reduce_one_element_vector(%a : vector<4xf32>) -> f32 {
   %s = vector.reduction <add>, %a : vector<4xf32> into f32
   return %s : f32
 }
+
+// -----
+
+// CHECK-LABEL: func @bitcast(
+//  CHECK-SAME:               %[[ARG:.*]]: vector<4x8xf32>) -> vector<4x16xi16> {
+//       CHECK: vector.bitcast %[[ARG:.*]] : vector<4x8xf32> to vector<4x16xi16>
+func.func @bitcast(%a: vector<4x8xf32>) -> vector<4x16xi16> {
+  %0 = vector.bitcast %a : vector<4x8xf32> to vector<4x8xi32>
+  %1 = vector.bitcast %0 : vector<4x8xi32> to vector<4x16xi16>
+  return %1 : vector<4x16xi16>
+}


        


More information about the Mlir-commits mailing list