[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
This commit is contained in:
River Riddle 2020-08-26 01:13:01 -07:00
parent 3050713798
commit 474f7639e3
2 changed files with 25 additions and 0 deletions

View File

@ -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;

View File

@ -202,3 +202,25 @@ func @mismatch_loop(%cond : i1) {
return
}
// Check that blocks are not merged if the types of the operands differ.
// 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
}