[Mlir-commits] [mlir] 474f763 - [mlir] Fix bug in block merging when the types of the operands differ
River Riddle
llvmlistbot at llvm.org
Wed Aug 26 01:17:35 PDT 2020
Author: River Riddle
Date: 2020-08-26T01:17:20-07:00
New Revision: 474f7639e3494d9605f4444b087f48e710fbb0d4
URL: https://github.com/llvm/llvm-project/commit/474f7639e3494d9605f4444b087f48e710fbb0d4
DIFF: https://github.com/llvm/llvm-project/commit/474f7639e3494d9605f4444b087f48e710fbb0d4.diff
LOG: [mlir] Fix bug in block merging when the types of the operands differ
The merging algorithm was previously not checking for type equivalence.
Fixes PR47314
Differential Revision: https://reviews.llvm.org/D86594
Added:
Modified:
mlir/lib/Transforms/Utils/RegionUtils.cpp
mlir/test/Transforms/canonicalize-block-merge.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Transforms/Utils/RegionUtils.cpp b/mlir/lib/Transforms/Utils/RegionUtils.cpp
index d6ecbf23416a..3d1aea837169 100644
--- a/mlir/lib/Transforms/Utils/RegionUtils.cpp
+++ b/mlir/lib/Transforms/Utils/RegionUtils.cpp
@@ -497,6 +497,9 @@ LogicalResult BlockMergeCluster::addToCluster(BlockEquivalenceData &blockData) {
Value rhsOperand = rhsOperands[operand];
if (lhsOperand == rhsOperand)
continue;
+ // Check that the types of the operands match.
+ if (lhsOperand.getType() != rhsOperand.getType())
+ return failure();
// Check that these uses are both external, or both internal.
bool lhsIsInBlock = lhsOperand.getParentBlock() == leaderBlock;
diff --git a/mlir/test/Transforms/canonicalize-block-merge.mlir b/mlir/test/Transforms/canonicalize-block-merge.mlir
index fe028b8af1fc..607f6cafb9de 100644
--- a/mlir/test/Transforms/canonicalize-block-merge.mlir
+++ b/mlir/test/Transforms/canonicalize-block-merge.mlir
@@ -202,3 +202,25 @@ func @mismatch_loop(%cond : i1) {
return
}
+
+// Check that blocks are not merged if the types of the operands
diff er.
+
+// CHECK-LABEL: func @mismatch_operand_types(
+func @mismatch_operand_types(%arg0 : i1, %arg1 : memref<i32>, %arg2 : memref<i1>) {
+ %c0_i32 = constant 0 : i32
+ %true = constant true
+ br ^bb1
+
+^bb1:
+ cond_br %arg0, ^bb2, ^bb3
+
+^bb2:
+ // CHECK: store %{{.*}}, %{{.*}} : memref<i32>
+ store %c0_i32, %arg1[] : memref<i32>
+ br ^bb1
+
+^bb3:
+ // CHECK: store %{{.*}}, %{{.*}} : memref<i1>
+ store %true, %arg2[] : memref<i1>
+ br ^bb1
+}
More information about the Mlir-commits
mailing list