diff --git a/mlir/lib/Transforms/Utils/RegionUtils.cpp b/mlir/lib/Transforms/Utils/RegionUtils.cpp --- a/mlir/lib/Transforms/Utils/RegionUtils.cpp +++ b/mlir/lib/Transforms/Utils/RegionUtils.cpp @@ -497,6 +497,9 @@ 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 --- a/mlir/test/Transforms/canonicalize-block-merge.mlir +++ b/mlir/test/Transforms/canonicalize-block-merge.mlir @@ -202,3 +202,25 @@ 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, %arg2 : memref) { + %c0_i32 = constant 0 : i32 + %true = constant true + br ^bb1 + +^bb1: + cond_br %arg0, ^bb2, ^bb3 + +^bb2: + // CHECK: store %{{.*}}, %{{.*}} : memref + store %c0_i32, %arg1[] : memref + br ^bb1 + +^bb3: + // CHECK: store %{{.*}}, %{{.*}} : memref + store %true, %arg2[] : memref + br ^bb1 +}