Skip to content

Commit 7e87d03

Browse files
authored
[MLIR][CF] Fix cf.switch parsing with result numbers (#87658)
This PR should fix the parsing bug reported in #87430. It allows using result number as the `cf.switch` operand.
1 parent beded9b commit 7e87d03

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ static ParseResult parseSwitchOpCases(
531531
failed(parser.parseSuccessor(destination)))
532532
return failure();
533533
if (succeeded(parser.parseOptionalLParen())) {
534-
if (failed(parser.parseOperandList(operands, OpAsmParser::Delimiter::None,
535-
/*allowResultNumber=*/false)) ||
534+
if (failed(parser.parseOperandList(operands,
535+
OpAsmParser::Delimiter::None)) ||
536536
failed(parser.parseColonTypeList(operandTypes)) ||
537537
failed(parser.parseRParen()))
538538
return failure();

mlir/test/Dialect/ControlFlow/ops.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ func.func @switch_i64(%flag : i64, %caseOperand : i32) {
3838
^bb3(%bb3arg : i32):
3939
return
4040
}
41+
42+
// CHECK-LABEL: func @switch_result_number
43+
func.func @switch_result_number(%arg0: i32) {
44+
%0:2 = "test.op_with_two_results"() : () -> (i32, i32)
45+
cf.switch %arg0 : i32, [
46+
default: ^bb2,
47+
0: ^bb1(%0#0 : i32)
48+
]
49+
^bb1(%1: i32):
50+
return
51+
^bb2:
52+
return
53+
}

0 commit comments

Comments
 (0)