Skip to content

Commit 2660fef

Browse files
committed
[mlir] Fix DRR either local variable redefinition
Differential Revision: https://reviews.llvm.org/D157771
1 parent 55252ca commit 2660fef

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,24 @@ def : Pat<(TestEitherOpA (either (TestEitherOpB I32:$arg1, $_),
16601660
$x),
16611661
(TestEitherOpB $arg2, $x)>;
16621662

1663+
def TestEitherHelperOpA : TEST_Op<"either_helper_op_a"> {
1664+
let arguments = (ins I32:$arg0);
1665+
let results = (outs I32:$output);
1666+
}
1667+
1668+
def TestEitherHelperOpB : TEST_Op<"either_helper_op_b"> {
1669+
let arguments = (ins I32:$arg0);
1670+
let results = (outs I32:$output);
1671+
}
1672+
1673+
// This test case ensures `emitOpMatch` doesn't redefine `castedOp{0}` local
1674+
// variables. To trigger this, we must ensure the matcher for
1675+
// `TestEitherHelperOpA` and `TestEitherHelperOpB` are not lifted as a static
1676+
// matcher.
1677+
def : Pat<(TestEitherOpB (either (TestEitherHelperOpA I32:$either_helper_0),
1678+
(TestEitherHelperOpB I32:$either_helper_1))),
1679+
(TestEitherOpB $either_helper_0, $either_helper_1)>;
1680+
16631681
//===----------------------------------------------------------------------===//
16641682
// Test Patterns (Location)
16651683

mlir/tools/mlir-tblgen/RewriterGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,20 @@ void PatternEmitter::emitEitherOperandMatch(DagNode tree, DagNode eitherArgTree,
715715

716716
os << formatv("auto {0} = (*v{1}.begin()).getDefiningOp();\n", argName,
717717
i);
718+
719+
// Indent emitMatchCheck and emitMatch because they declare local
720+
// variables.
721+
os << "{\n";
722+
os.indent();
723+
718724
emitMatchCheck(
719725
opName, /*matchStr=*/argName,
720726
formatv("\"There's no operation that defines operand {0} of {1}\"",
721727
operandIndex++, opName));
722728
emitMatch(argTree, argName, depth + 1);
729+
730+
os.unindent() << "}\n";
731+
723732
// `tblgen_ops` is used to collect the matched operations. In either, we
724733
// need to queue the operation only if the matching success. Thus we emit
725734
// the code at the end.

0 commit comments

Comments
 (0)