@@ -91,6 +91,45 @@ void sw2(int a) {
9191// OGCG: [[SW_EPILOG]]:
9292// OGCG: ret void
9393
94+ int sw4 (int a) {
95+ switch (a) {
96+ case 42 : {
97+ return 3 ;
98+ }
99+ // TODO: add default case when it is upstreamed
100+ }
101+ return 0 ;
102+ }
103+
104+ // CIR: cir.func @_Z3sw4i
105+ // CIR: cir.switch (%4 : !s32i) {
106+ // CIR-NEXT: cir.case(equal, [#cir.int<42> : !s32i]) {
107+ // CIR-NEXT: cir.scope {
108+ // CIR-NEXT: %5 = cir.const #cir.int<3> : !s32i
109+ // CIR-NEXT: cir.store %5, %1 : !s32i, !cir.ptr<!s32i>
110+ // CIR-NEXT: %6 = cir.load %1 : !cir.ptr<!s32i>, !s32i
111+ // CIR-NEXT: cir.return %6 : !s32i
112+ // CIR-NEXT: }
113+ // CIR-NEXT: cir.yield
114+ // CIR-NEXT: }
115+
116+ // OGCG: define dso_local noundef i32 @_Z3sw4i
117+ // OGCG: entry:
118+ // OGCG: %[[RETVAL:.*]] = alloca i32, align 4
119+ // OGCG: %[[A_ADDR:.*]] = alloca i32, align 4
120+ // OGCG: %[[A_VAL:.*]] = load i32, ptr %[[A_ADDR]], align 4
121+ // OGCG: switch i32 %[[A_VAL]], label %[[EPILOG:.*]] [
122+ // OGCG: i32 42, label %[[SW42:.*]]
123+ // OGCG: ]
124+ // OGCG: [[SW42]]:
125+ // OGCG: br label %[[RETURN:.*]]
126+ // OGCG: [[EPILOG]]:
127+ // OGCG: br label %[[RETURN]]
128+ // OGCG: [[RETURN]]:
129+ // OGCG: %[[RETVAL_LOAD:.*]] = load i32, ptr %[[RETVAL]], align 4
130+ // OGCG: ret i32 %[[RETVAL_LOAD]]
131+
132+
94133void sw5 (int a) {
95134 switch (a) {
96135 case 1 :;
@@ -117,6 +156,76 @@ void sw5(int a) {
117156// OGCG: [[SW_EPILOG]]:
118157// OGCG: ret void
119158
159+ void sw8 (int a) {
160+ switch (a)
161+ {
162+ case 3 :
163+ break ;
164+ case 4 :
165+ // TODO: add default case when it is upstreamed
166+ break ;
167+ }
168+ }
169+
170+ // CIR: cir.func @_Z3sw8i
171+ // CIR: cir.case(equal, [#cir.int<3> : !s32i]) {
172+ // CIR-NEXT: cir.break
173+ // CIR-NEXT: }
174+ // CIR-NEXT: cir.case(equal, [#cir.int<4> : !s32i]) {
175+ // CIR-NEXT: cir.break
176+ // CIR-NEXT: }
177+
178+
179+ // OGCG: define dso_local void @_Z3sw8i
180+ // OGCG: entry:
181+ // OGCG: %[[A_ADDR:.*]] = alloca i32, align 4
182+ // OGCG: %[[A_VAL:.*]] = load i32, ptr %[[A_ADDR]], align 4
183+ // OGCG: switch i32 %[[A_VAL]], label %[[EPILOG:.*]] [
184+ // OGCG: i32 3, label %[[SW3:.*]]
185+ // OGCG: i32 4, label %[[SW4:.*]]
186+ // OGCG: ]
187+ // OGCG: [[SW3]]:
188+ // OGCG: br label %[[EPILOG]]
189+ // OGCG: [[SW4]]:
190+ // OGCG: br label %[[EPILOG]]
191+ // OGCG: [[EPILOG]]:
192+ // OGCG: ret void
193+
194+
195+ void sw9 (int a) {
196+ switch (a)
197+ {
198+ case 3 :
199+ break ;
200+ // TODO: add default case when it is upstreamed
201+ case 4 :
202+ break ;
203+ }
204+ }
205+
206+ // CIR: cir.func @_Z3sw9i
207+ // CIR: cir.case(equal, [#cir.int<3> : !s32i]) {
208+ // CIR-NEXT: cir.break
209+ // CIR-NEXT: }
210+ // CIR-NEXT: cir.case(equal, [#cir.int<4> : !s32i]) {
211+ // CIR-NEXT: cir.break
212+ // CIR-NEXT: }
213+
214+ // OGCG: define dso_local void @_Z3sw9i
215+ // OGCG: entry:
216+ // OGCG: %[[A_ADDR:.*]] = alloca i32, align 4
217+ // OGCG: %[[A_VAL:.*]] = load i32, ptr %[[A_ADDR]], align 4
218+ // OGCG: switch i32 %[[A_VAL]], label %[[EPILOG:.*]] [
219+ // OGCG: i32 3, label %[[SW3:.*]]
220+ // OGCG: i32 4, label %[[SW4:.*]]
221+ // OGCG: ]
222+ // OGCG: [[SW3]]:
223+ // OGCG: br label %[[EPILOG]]
224+ // OGCG: [[SW4]]:
225+ // OGCG: br label %[[EPILOG]]
226+ // OGCG: [[EPILOG]]:
227+ // OGCG: ret void
228+
120229void sw12 (int a) {
121230 switch (a)
122231 {
0 commit comments