OLD | NEW |
1 ; This tests a switch statement, including multiple branches to the | 1 ; This tests a switch statement, including multiple branches to the |
2 ; same label which also results in phi instructions with multiple | 2 ; same label which also results in phi instructions with multiple |
3 ; entries for the same incoming edge. | 3 ; entries for the same incoming edge. |
4 | 4 |
5 ; For x86 see adv-switch-opt.ll | 5 ; For x86 see adv-switch-opt.ll |
6 | 6 |
7 ; TODO(jvoung): Update to -02 once the phi assignments is done for ARM | 7 ; TODO(jvoung): Update to -02 once the phi assignments is done for ARM |
8 ; RUN: %if --need=target_ARM32 --need=allow_dump \ | 8 ; RUN: %if --need=target_ARM32 --need=allow_dump \ |
9 ; RUN: --command %p2i --filetype=asm --assemble --disassemble \ | 9 ; RUN: --command %p2i --filetype=asm --assemble --disassemble \ |
10 ; RUN: --target arm32 -i %s --args -Om1 --skip-unimplemented \ | 10 ; RUN: --target arm32 -i %s --args -Om1 --skip-unimplemented \ |
11 ; RUN: | %if --need=target_ARM32 --need=allow_dump \ | 11 ; RUN: | %if --need=target_ARM32 --need=allow_dump \ |
12 ; RUN: --command FileCheck --check-prefix ARM32 %s | 12 ; RUN: --command FileCheck --check-prefix ARM32 %s |
13 | 13 |
| 14 ; TODO(jaydeep.patil): Using --skip-unimplemented for MIPS32 |
| 15 ; RUN: %if --need=target_MIPS32 --need=allow_dump \ |
| 16 ; RUN: --command %p2i --filetype=asm --assemble --disassemble \ |
| 17 ; RUN: --target mips32 -i %s --args -Om1 --skip-unimplemented \ |
| 18 ; RUN: -allow-externally-defined-symbols \ |
| 19 ; RUN: | %if --need=target_MIPS32 --need=allow_dump \ |
| 20 ; RUN: --command FileCheck --check-prefix MIPS32 %s |
| 21 |
14 define internal i32 @testSwitch(i32 %a) { | 22 define internal i32 @testSwitch(i32 %a) { |
15 entry: | 23 entry: |
16 switch i32 %a, label %sw.default [ | 24 switch i32 %a, label %sw.default [ |
17 i32 1, label %sw.epilog | 25 i32 1, label %sw.epilog |
18 i32 2, label %sw.epilog | 26 i32 2, label %sw.epilog |
19 i32 3, label %sw.epilog | 27 i32 3, label %sw.epilog |
20 i32 7, label %sw.bb1 | 28 i32 7, label %sw.bb1 |
21 i32 8, label %sw.bb1 | 29 i32 8, label %sw.bb1 |
22 i32 15, label %sw.bb2 | 30 i32 15, label %sw.bb2 |
23 i32 14, label %sw.bb2 | 31 i32 14, label %sw.bb2 |
24 ] | 32 ] |
25 | 33 |
26 sw.default: ; preds = %entry | 34 sw.default: ; preds = %entry |
27 %add = add i32 %a, 27 | 35 %add = add i32 %a, 27 |
28 br label %sw.epilog | 36 br label %sw.epilog |
29 | 37 |
30 sw.bb1: ; preds = %entry, %entry | 38 sw.bb1: ; preds = %entry, %entry |
31 %phitmp = sub i32 21, %a | 39 %phitmp = sub i32 21, %a |
32 br label %sw.bb2 | 40 br label %sw.bb2 |
33 | 41 |
34 sw.bb2: ; preds = %sw.bb1, %entry, %en
try | 42 sw.bb2: ; preds = %sw.bb1, %entry, %en
try |
35 %result.0 = phi i32 [ 1, %entry ], [ 1, %entry ], [ %phitmp, %sw.bb1 ] | 43 %result.0 = phi i32 [ 1, %entry ], [ 1, %entry ], [ %phitmp, %sw.bb1 ] |
36 br label %sw.epilog | 44 br label %sw.epilog |
37 | 45 |
38 sw.epilog: ; preds = %sw.bb2, %sw.default
, %entry, %entry, %entry | 46 sw.epilog: ; preds = %sw.bb2, %sw.default
, %entry, %entry, %entry |
39 %result.1 = phi i32 [ %add, %sw.default ], [ %result.0, %sw.bb2 ], [ 17, %entr
y ], [ 17, %entry ], [ 17, %entry ] | 47 %result.1 = phi i32 [ %add, %sw.default ], [ %result.0, %sw.bb2 ], [ 17, %entr
y ], [ 17, %entry ], [ 17, %entry ] |
40 ret i32 %result.1 | 48 ret i32 %result.1 |
41 } | 49 } |
42 | 50 |
| 51 ; MIPS32-LABEL: testSwitch |
| 52 ; MIPS32: li {{.*}},1 |
| 53 ; MIPS32: li {{.*}},17 |
| 54 ; MIPS32: li {{.*}},1 |
| 55 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <[[SW_EPILOG:.*]]> |
| 56 ; MIPS32: li {{.*}},2 |
| 57 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <[[SW_EPILOG]]> |
| 58 ; MIPS32: li {{.*}},3 |
| 59 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <[[SW_EPILOG]]> |
| 60 ; MIPS32: li {{.*}},7 |
| 61 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <[[SW_BB1:.*]]> |
| 62 ; MIPS32: li {{.*}},8 |
| 63 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <[[SW_BB1]]> |
| 64 ; MIPS32: li {{.*}},15 |
| 65 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <[[SW_BB2:.*]]> |
| 66 ; MIPS32: li {{.*}},14 |
| 67 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <[[SW_BB2]]> |
| 68 ; MIPS32: b {{.*}} <[[SW_DEFAULT:.*]]> |
| 69 ; MIPS32: <[[SW_DEFAULT]]> |
| 70 ; MIPS32: li {{.*}},27 |
| 71 ; MIPS32: b {{.*}} <[[SW_EPILOG]]> |
| 72 ; MIPS32: <[[SW_BB1]]> |
| 73 ; MIPS32: li {{.*}},21 |
| 74 ; MIPS32: b {{.*}} <[[SW_BB2]]> |
| 75 ; MIPS32: <[[SW_BB2]]> |
| 76 ; MIPS32: b {{.*}} <[[SW_EPILOG]]> |
| 77 ; MIPS32: <[[SW_EPILOG]]> |
| 78 ; MIPS32: jr ra |
| 79 |
43 ; Check for a valid addressing mode when the switch operand is an | 80 ; Check for a valid addressing mode when the switch operand is an |
44 ; immediate. It's important that there is exactly one case, because | 81 ; immediate. It's important that there is exactly one case, because |
45 ; for two or more cases the source operand is legalized into a | 82 ; for two or more cases the source operand is legalized into a |
46 ; register. | 83 ; register. |
47 define internal i32 @testSwitchImm() { | 84 define internal i32 @testSwitchImm() { |
48 entry: | 85 entry: |
49 switch i32 10, label %sw.default [ | 86 switch i32 10, label %sw.default [ |
50 i32 1, label %sw.default | 87 i32 1, label %sw.default |
51 ] | 88 ] |
52 | 89 |
53 sw.default: | 90 sw.default: |
54 ret i32 20 | 91 ret i32 20 |
55 } | 92 } |
56 ; ARM32-LABEL: testSwitchImm | 93 ; ARM32-LABEL: testSwitchImm |
57 ; ARM32: cmp {{r[0-9]+}}, #1 | 94 ; ARM32: cmp {{r[0-9]+}}, #1 |
58 ; ARM32-NEXT: beq | 95 ; ARM32-NEXT: beq |
59 ; ARM32-NEXT: b | 96 ; ARM32-NEXT: b |
60 | 97 |
| 98 ; MIPS32-LABEL: testSwitchImm |
| 99 ; MIPS32: li {{.*}},10 |
| 100 ; MIPS32: li {{.*}},1 |
| 101 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <.LtestSwitchImm$sw.default> |
| 102 ; MIPS32: .LtestSwitchImm$sw.default |
| 103 ; MIPS32: li v0,20 |
| 104 ; MIPS32: jr ra |
| 105 |
61 ; Test for correct 64-bit lowering. | 106 ; Test for correct 64-bit lowering. |
62 define internal i32 @testSwitch64(i64 %a) { | 107 define internal i32 @testSwitch64(i64 %a) { |
63 entry: | 108 entry: |
64 switch i64 %a, label %sw.default [ | 109 switch i64 %a, label %sw.default [ |
65 i64 123, label %return | 110 i64 123, label %return |
66 i64 234, label %sw.bb1 | 111 i64 234, label %sw.bb1 |
67 i64 345, label %sw.bb2 | 112 i64 345, label %sw.bb2 |
68 i64 78187493520, label %sw.bb3 | 113 i64 78187493520, label %sw.bb3 |
69 ] | 114 ] |
70 | 115 |
(...skipping 24 matching lines...) Expand all Loading... |
95 ; ARM32-NEXT: cmp {{r[0-9]+}}, [[REG]] | 140 ; ARM32-NEXT: cmp {{r[0-9]+}}, [[REG]] |
96 ; ARM32-NEXT: cmpeq {{r[0-9]+}}, #0 | 141 ; ARM32-NEXT: cmpeq {{r[0-9]+}}, #0 |
97 ; ARM32-NEXT: beq | 142 ; ARM32-NEXT: beq |
98 ; ARM32: movw [[REG:r[0-9]+]], #30864 | 143 ; ARM32: movw [[REG:r[0-9]+]], #30864 |
99 ; ARM32-NEXT: movt [[REG]], #13398 | 144 ; ARM32-NEXT: movt [[REG]], #13398 |
100 ; ARM32-NEXT: cmp {{r[0-9]+}}, [[REG]] | 145 ; ARM32-NEXT: cmp {{r[0-9]+}}, [[REG]] |
101 ; ARM32-NEXT: cmpeq {{r[0-9]+}}, #18 | 146 ; ARM32-NEXT: cmpeq {{r[0-9]+}}, #18 |
102 ; ARM32-NEXT: beq | 147 ; ARM32-NEXT: beq |
103 ; ARM32-NEXT: b | 148 ; ARM32-NEXT: b |
104 | 149 |
| 150 ; MIPS32-LABEL: testSwitch64 |
| 151 ; MIPS32: bne {{.*}},{{.*}},{{.*}} <.LtestSwitch64$local$__0> |
| 152 ; MIPS32: li {{.*}},123 |
| 153 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <.LtestSwitch64$return> |
| 154 ; MIPS32: .LtestSwitch64$local$__0 |
| 155 ; MIPS32: li {{.*}},0 |
| 156 ; MIPS32: bne {{.*}},{{.*}},{{.*}} <.LtestSwitch64$local$__1> |
| 157 ; MIPS32: li {{.*}},234 |
| 158 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <.LtestSwitch64$sw.bb1> |
| 159 ; MIPS32: .LtestSwitch64$local$__1 |
| 160 ; MIPS32: li {{.*}},0 |
| 161 ; MIPS32: bne {{.*}},{{.*}},{{.*}} <.LtestSwitch64$local$__2> |
| 162 ; MIPS32: li {{.*}},345 |
| 163 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <.LtestSwitch64$sw.bb2> |
| 164 ; MIPS32: .LtestSwitch64$local$__2 |
| 165 ; MIPS32: li {{.*}},18 |
| 166 ; MIPS32: bne {{.*}},{{.*}},{{.*}} <.LtestSwitch64$local$__3> |
| 167 ; MIPS32: lui {{.*}},0x3456 |
| 168 ; MIPS32: ori {{.*}},{{.*}},0x7890 |
| 169 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <.LtestSwitch64$sw.bb3> |
| 170 ; MIPS32: .LtestSwitch64$local$__3 |
| 171 ; MIPS32: b {{.*}} <.LtestSwitch64$sw.default> |
| 172 ; MIPS32: .LtestSwitch64$sw.bb1 |
| 173 ; MIPS32: li {{.*}},2 |
| 174 ; MIPS32: b {{.*}} <.LtestSwitch64$return> |
| 175 ; MIPS32: .LtestSwitch64$sw.bb2 |
| 176 ; MIPS32: li {{.*}},3 |
| 177 ; MIPS32: b {{.*}} <.LtestSwitch64$return> |
| 178 ; MIPS32: .LtestSwitch64$sw.bb3 |
| 179 ; MIPS32: li {{.*}},4 |
| 180 ; MIPS32: b {{.*}} <.LtestSwitch64$return> |
| 181 ; MIPS32: .LtestSwitch64$sw.default |
| 182 ; MIPS32: li {{.*}},5 |
| 183 ; MIPS32: b {{.*}} <.LtestSwitch64$return> |
| 184 ; MIPS32: .LtestSwitch64$return |
| 185 ; MIPS32: jr ra |
| 186 |
105 ; Similar to testSwitchImm, make sure proper addressing modes are | 187 ; Similar to testSwitchImm, make sure proper addressing modes are |
106 ; used. In reality, this is tested by running the output through the | 188 ; used. In reality, this is tested by running the output through the |
107 ; assembler. | 189 ; assembler. |
108 define internal i32 @testSwitchImm64() { | 190 define internal i32 @testSwitchImm64() { |
109 entry: | 191 entry: |
110 switch i64 10, label %sw.default [ | 192 switch i64 10, label %sw.default [ |
111 i64 1, label %sw.default | 193 i64 1, label %sw.default |
112 ] | 194 ] |
113 | 195 |
114 sw.default: | 196 sw.default: |
115 ret i32 20 | 197 ret i32 20 |
116 } | 198 } |
117 ; ARM32-LABEL: testSwitchImm64 | 199 ; ARM32-LABEL: testSwitchImm64 |
118 ; ARM32: cmp {{r[0-9]+}}, #1 | 200 ; ARM32: cmp {{r[0-9]+}}, #1 |
119 ; ARM32-NEXT: cmpeq {{r[0-9]+}}, #0 | 201 ; ARM32-NEXT: cmpeq {{r[0-9]+}}, #0 |
120 ; ARM32-NEXT: beq [[ADDR:[0-9a-f]+]] | 202 ; ARM32-NEXT: beq [[ADDR:[0-9a-f]+]] |
121 ; ARM32-NEXT: b [[ADDR]] | 203 ; ARM32-NEXT: b [[ADDR]] |
122 | 204 |
| 205 ; MIPS32-LABEL: testSwitchImm64 |
| 206 ; MIPS32: li {{.*}},10 |
| 207 ; MIPS32: li {{.*}},0 |
| 208 ; MIPS32: li {{.*}},0 |
| 209 ; MIPS32: bne {{.*}},{{.*}},{{.*}} <.LtestSwitchImm64$local$__0> |
| 210 ; MIPS32: li {{.*}},1 |
| 211 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <.LtestSwitchImm64$sw.default> |
| 212 ; MIPS32: .LtestSwitchImm64$local$__0 |
| 213 ; MIPS32: b {{.*}} <.LtestSwitchImm64$sw.default> |
| 214 ; MIPS32: .LtestSwitchImm64$sw.default |
| 215 ; MIPS32: li {{.*}},20 |
| 216 ; MIPS32: jr ra |
| 217 |
123 define internal i32 @testSwitchUndef64() { | 218 define internal i32 @testSwitchUndef64() { |
124 entry: | 219 entry: |
125 switch i64 undef, label %sw.default [ | 220 switch i64 undef, label %sw.default [ |
126 i64 1, label %sw.default | 221 i64 1, label %sw.default |
127 ] | 222 ] |
128 | 223 |
129 sw.default: | 224 sw.default: |
130 ret i32 20 | 225 ret i32 20 |
131 } | 226 } |
132 ; ARM32-LABEL: testSwitchUndef64 | 227 ; ARM32-LABEL: testSwitchUndef64 |
133 ; ARM32: mov {{.*}}, #0 | 228 ; ARM32: mov {{.*}}, #0 |
134 ; ARM32: mov {{.*}}, #0 | 229 ; ARM32: mov {{.*}}, #0 |
| 230 |
| 231 ; MIPS32-LABEL: testSwitchUndef64 |
| 232 ; MIPS32: li {{.*}},0 |
| 233 ; MIPS32: li {{.*}},0 |
| 234 ; MIPS32: li {{.*}},0 |
| 235 ; MIPS32: bne {{.*}},{{.*}},{{.*}} <.LtestSwitchUndef64$local$__0> |
| 236 ; MIPS32: li {{.*}},1 |
| 237 ; MIPS32: beq {{.*}},{{.*}},{{.*}} <.LtestSwitchUndef64$sw.default> |
| 238 ; MIPS32: .LtestSwitchUndef64$local$__0 |
| 239 ; MIPS32: b {{.*}} <.LtestSwitchUndef64$sw.default> |
| 240 ; MIPS32: .LtestSwitchUndef64$sw.default |
| 241 ; MIPS32: li {{.*}},20 |
| 242 ; MIPS32: jr ra |
OLD | NEW |