• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by update_test_checks.py
2; RUN: opt < %s -simplifycfg -S | FileCheck %s
3
4; Test normal folding
5define i32 @test1() {
6; CHECK-LABEL: @test1(
7; CHECK-NEXT:  TheDest:
8; CHECK-NEXT:    ret i32 1234
9;
10  switch i32 5, label %Default [
11  i32 0, label %Foo
12  i32 1, label %Bar
13  i32 2, label %Baz
14  i32 5, label %TheDest
15  ]
16Default:
17  ret i32 -1
18Foo:
19  ret i32 -2
20Bar:
21  ret i32 -3
22Baz:
23  ret i32 -4
24TheDest:
25  ret i32 1234
26}
27
28; Test folding to default dest
29define i32 @test2() {
30; CHECK-LABEL: @test2(
31; CHECK-NEXT:  Default:
32; CHECK-NEXT:    ret i32 1234
33;
34  switch i32 3, label %Default [
35  i32 0, label %Foo
36  i32 1, label %Bar
37  i32 2, label %Baz
38  i32 5, label %TheDest
39  ]
40Default:
41  ret i32 1234
42Foo:
43  ret i32 -2
44Bar:
45  ret i32 -5
46Baz:
47  ret i32 -6
48TheDest:
49  ret i32 -8
50}
51
52; Test folding all to same dest
53define i32 @test3(i1 %C) {
54; CHECK-LABEL: @test3(
55; CHECK-NEXT:  TheDest:
56; CHECK-NEXT:    ret i32 1234
57;
58  br i1 %C, label %Start, label %TheDest
59Start:          ; preds = %0
60  switch i32 3, label %TheDest [
61  i32 0, label %TheDest
62  i32 1, label %TheDest
63  i32 2, label %TheDest
64  i32 5, label %TheDest
65  ]
66TheDest:
67  ret i32 1234
68}
69
70; Test folding switch -> branch
71define i32 @test4(i32 %C) {
72; CHECK-LABEL: @test4(
73; CHECK-NEXT:  L1:
74; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 %C, 0
75; CHECK-NEXT:    [[DOT:%.*]] = select i1 [[COND]], i32 1, i32 0
76; CHECK-NEXT:    ret i32 [[DOT]]
77;
78  switch i32 %C, label %L1 [
79  i32 0, label %L2
80  ]
81L1:
82  ret i32 0
83L2:
84  ret i32 1
85}
86
87; Can fold into a cond branch!
88define i32 @test5(i32 %C) {
89; CHECK-LABEL: @test5(
90; CHECK-NEXT:  L1:
91; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 %C, 0
92; CHECK-NEXT:    [[DOT:%.*]] = select i1 [[COND]], i32 1, i32 0
93; CHECK-NEXT:    ret i32 [[DOT]]
94;
95  switch i32 %C, label %L1 [
96  i32 0, label %L2
97  i32 123, label %L1
98  ]
99L1:
100  ret i32 0
101L2:
102  ret i32 1
103}
104
105