Debian Codegraph @

gcc/testsuite/gcc.target/arm/arm-switchstatement.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O2 --param case-values-threshold=1 -fno-reorder-blocks -fno-tree-dce" } */
3 /* { dg-require-effective-target arm_nothumb } */
4 /* { dg-final { check-function-bodies "**" "" "" } } */
5
6 #define NOP "nop;"
7 #define NOP2 NOP NOP
8 #define NOP4 NOP2 NOP2
9 #define NOP8 NOP4 NOP4
10 #define NOP16 NOP8 NOP8
11 #define NOP32 NOP16 NOP16
12 #define NOP64 NOP32 NOP32
13 #define NOP128 NOP64 NOP64
14 #define NOP256 NOP128 NOP128
15 #define NOP512 NOP256 NOP256
16 #define NOP1024 NOP512 NOP512
17 #define NOP2048 NOP1024 NOP1024
18 #define NOP4096 NOP2048 NOP2048
19 #define NOP8192 NOP4096 NOP4096
20 #define NOP16384 NOP8192 NOP8192
21 #define NOP32768 NOP16384 NOP16384
22 #define NOP65536 NOP32768 NOP32768
23 #define NOP131072 NOP65536 NOP65536
24
25 enum z
26 {
27 a = 1,
28 b,
29 c,
30 d,
31 e,
32 f = 7,
33 };
34
35 inline void QIFunction (const char* flag)
36 {
37 asm volatile (NOP32);
38 return;
39 }
40
41 inline void HIFunction (const char* flag)
42 {
43 asm volatile (NOP512);
44 return;
45 }
46
47 inline void SIFunction (const char* flag)
48 {
49 asm volatile (NOP131072);
50 return;
51 }
52
53 /*
54 **QImode_test:
55 ** ...
56 ** ldr (r[0-9]+), .L[0-9]+
57 ** ...
58 ** ldrb (r[0-9]+), \[\1, r[0-9]+\]
59 ** add pc, pc, \2, lsl #2
60 ** ...
61 */
62 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* QImode_test(enum z x)
63 {
64 switch (x)
65 {
66 case d:
67 QIFunction("QItest");
68 return "InlineASM";
69 case f:
70 return "TEST";
71 default:
72 return "Default";
73 }
74 }
75
76 /* { dg-final { scan-assembler ".byte" } } */
77
78 /*
79 **HImode_test:
80 ** ...
81 ** ldr (r[0-9]+), .L[0-9]+
82 ** ...
83 ** add r[0-9]+, r[0-9]+, r[0-9]+
84 ** ldrh (r[0-9]+), \[r[0-9]+, r[0-9]+]
85 ** add pc, pc, \2, lsl #2
86 ** ...
87 */
88 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* HImode_test(enum z x)
89 {
90 switch (x)
91 {
92 case d:
93 HIFunction("HItest");
94 return "InlineASM";
95 case f:
96 return "TEST";
97 default:
98 return "Default";
99 }
100 }
101
102 /* { dg-final { scan-assembler ".2byte" } } */
103
104 /*
105 **SImode_test:
106 ** ...
107 ** ldr (r[0-9]+), .L[0-9]+
108 ** ...
109 ** ldr pc, \[\1, r[0-9]+, lsl #2\]
110 ** ...
111 */
112 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* SImode_test(enum z x)
113 {
114 switch (x)
115 {
116 case d:
117 SIFunction("SItest");
118 return "InlineASM";
119 case f:
120 return "TEST";
121 default:
122 return "Default";
123 }
124 }
125
126 /* { dg-final { scan-assembler ".word" } } */
127
128 /*
129 **backwards_branch_test:
130 ** ...
131 ** ldr (r[0-9]+), .L[0-9]+
132 ** ...
133 ** add r[0-9]+, r[0-9]+, r[0-9]+
134 ** ldrsh (r[0-9]+), \[r[0-9]+, r[0-9]+]
135 ** add pc, pc, \2, lsl #2
136 ** ...
137 */
138 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* backwards_branch_test(enum z x, int flag)
139 {
140 if (flag == 5)
141 {
142 backwards:
143 asm volatile (NOP512);
144 return "ASM";
145 }
146 switch (x)
147 {
148 case d:
149 goto backwards;
150 case f:
151 return "TEST";
152 default:
153 return "Default";
154 }
155 }