aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeyi Zhang <Kuree@users.noreply.github.com>2024-04-04 12:32:47 -0700
committerGitHub <noreply@github.com>2024-04-04 21:32:47 +0200
commit7e87d03b45f3ca0f6d9c09e8e9090329cc84592e (patch)
tree9a60513a82f97cef1ef00426a927e159183e85f3
parentbeded9b9ceab19f81320c7cf5e3600a7745c8f05 (diff)
downloadllvm-7e87d03b45f3ca0f6d9c09e8e9090329cc84592e.zip
llvm-7e87d03b45f3ca0f6d9c09e8e9090329cc84592e.tar.gz
llvm-7e87d03b45f3ca0f6d9c09e8e9090329cc84592e.tar.bz2
[MLIR][CF] Fix cf.switch parsing with result numbers (#87658)
This PR should fix the parsing bug reported in https://github.com/llvm/llvm-project/issues/87430. It allows using result number as the `cf.switch` operand.
-rw-r--r--mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp4
-rw-r--r--mlir/test/Dialect/ControlFlow/ops.mlir13
2 files changed, 15 insertions, 2 deletions
diff --git a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
index 5d11f8f6..1320db3 100644
--- a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
@@ -531,8 +531,8 @@ static ParseResult parseSwitchOpCases(
failed(parser.parseSuccessor(destination)))
return failure();
if (succeeded(parser.parseOptionalLParen())) {
- if (failed(parser.parseOperandList(operands, OpAsmParser::Delimiter::None,
- /*allowResultNumber=*/false)) ||
+ if (failed(parser.parseOperandList(operands,
+ OpAsmParser::Delimiter::None)) ||
failed(parser.parseColonTypeList(operandTypes)) ||
failed(parser.parseRParen()))
return failure();
diff --git a/mlir/test/Dialect/ControlFlow/ops.mlir b/mlir/test/Dialect/ControlFlow/ops.mlir
index 8453c2b..c9317c7 100644
--- a/mlir/test/Dialect/ControlFlow/ops.mlir
+++ b/mlir/test/Dialect/ControlFlow/ops.mlir
@@ -38,3 +38,16 @@ func.func @switch_i64(%flag : i64, %caseOperand : i32) {
^bb3(%bb3arg : i32):
return
}
+
+// CHECK-LABEL: func @switch_result_number
+func.func @switch_result_number(%arg0: i32) {
+ %0:2 = "test.op_with_two_results"() : () -> (i32, i32)
+ cf.switch %arg0 : i32, [
+ default: ^bb2,
+ 0: ^bb1(%0#0 : i32)
+ ]
+ ^bb1(%1: i32):
+ return
+ ^bb2:
+ return
+}