@@ -56,6 +56,57 @@ module {
5656 }
5757}
5858
59+ // Switches that yield multiple values should thread every result through the
60+ // nested if-else chain.
61+
62+ // -----
63+
64+ // CHECK-LABEL: func.func @multi_result(
65+ // CHECK-SAME: %[[ARG:.*]]: index) -> (i32, f32) {
66+ // CHECK: %[[ZERO:.*]] = arith.constant 0 : index
67+ // CHECK: %[[CMP0:.*]] = arith.cmpi eq, %[[ARG]], %[[ZERO]] : index
68+ // CHECK: %[[IF0:[0-9]+]]:2 = scf.if %[[CMP0]] -> (i32, f32) {
69+ // CHECK: %[[C0:.*]] = arith.constant 10 : i32
70+ // CHECK: %[[F0:.*]] = arith.constant 1.000000e+00 : f32
71+ // CHECK: scf.yield %[[C0]], %[[F0]] : i32, f32
72+ // CHECK: } else {
73+ // CHECK: %[[ONE:.*]] = arith.constant 1 : index
74+ // CHECK: %[[CMP1:.*]] = arith.cmpi eq, %[[ARG]], %[[ONE]] : index
75+ // CHECK: %[[IF1:[0-9]+]]:2 = scf.if %[[CMP1]] -> (i32, f32) {
76+ // CHECK: %[[C1:.*]] = arith.constant 20 : i32
77+ // CHECK: %[[F1:.*]] = arith.constant 2.000000e+00 : f32
78+ // CHECK: scf.yield %[[C1]], %[[F1]] : i32, f32
79+ // CHECK: } else {
80+ // CHECK: %[[CDEF:.*]] = arith.constant 30 : i32
81+ // CHECK: %[[FDEF:.*]] = arith.constant 3.000000e+00 : f32
82+ // CHECK: scf.yield %[[CDEF]], %[[FDEF]] : i32, f32
83+ // CHECK: }
84+ // CHECK: scf.yield %[[IF1]]#0, %[[IF1]]#1 : i32, f32
85+ // CHECK: }
86+ // CHECK: return %[[IF0]]#0, %[[IF0]]#1 : i32, f32
87+ // CHECK: }
88+ module {
89+ func.func @multi_result (%arg0 : index ) -> (i32 , f32 ) {
90+ %0 , %1 = scf.index_switch %arg0 -> i32 , f32
91+ case 0 {
92+ %c0 = arith.constant 10 : i32
93+ %f0 = arith.constant 1.0 : f32
94+ scf.yield %c0 , %f0 : i32 , f32
95+ }
96+ case 1 {
97+ %c1 = arith.constant 20 : i32
98+ %f1 = arith.constant 2.0 : f32
99+ scf.yield %c1 , %f1 : i32 , f32
100+ }
101+ default {
102+ %cd = arith.constant 30 : i32
103+ %fd = arith.constant 3.0 : f32
104+ scf.yield %cd , %fd : i32 , f32
105+ }
106+ return %0 , %1 : i32 , f32
107+ }
108+ }
109+
59110// Switch to nested if-else when the yielded result is empty
60111
61112// -----
0 commit comments