Debian Codegraph @

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

raw
1 /* { dg-do compile } */
2 /* { dg-options "-mthumb --param case-values-threshold=1 -fno-reorder-blocks -fno-tree-dce -O2" } */
3 /* { dg-require-effective-target arm_thumb2_ok } */
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 ** tbb \[pc, r[0-9]+\]
57 ** ...
58 */
59 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* QImode_test(enum z x)
60 {
61 switch (x)
62 {
63 case d:
64 QIFunction("QItest");
65 return "InlineASM";
66 case f:
67 return "TEST";
68 default:
69 return "Default";
70 }
71 }
72
73 /* { dg-final { scan-assembler ".byte" } } */
74
75 /*
76 **HImode_test:
77 ** ...
78 ** tbh \[pc, r[0-9]+, lsl #1\]
79 ** ...
80 */
81 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* HImode_test(enum z x)
82 {
83 switch (x)
84 {
85 case d:
86 HIFunction("HItest");
87 return "InlineASM";
88 case f:
89 return "TEST";
90 default:
91 return "Default";
92 }
93 }
94
95 /* { dg-final { scan-assembler ".2byte" } } */
96
97 /*
98 **SImode_test:
99 ** ...
100 ** adr (r[0-9]+), .L[0-9]+
101 ** ldr pc, \[\1, r[0-9]+, lsl #2\]
102 ** ...
103 */
104 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* SImode_test(enum z x)
105 {
106 switch (x)
107 {
108 case d:
109 SIFunction("SItest");
110 return "InlineASM";
111 case f:
112 return "TEST";
113 default:
114 return "Default";
115 }
116 }
117
118 /* { dg-final { scan-assembler ".word" } } */
119
120 /*
121 **backwards_branch_test:
122 ** ...
123 ** adr (r[0-9]+), .L[0-9]+
124 ** ldr pc, \[\1, r[0-9]+, lsl #2\]
125 ** ...
126 */
127 __attribute__ ((noinline)) __attribute__ ((noclone)) const char* backwards_branch_test(enum z x, int flag)
128 {
129 if (flag == 5)
130 {
131 backwards:
132 asm volatile (NOP512);
133 return "ASM";
134 }
135 switch (x)
136 {
137 case d:
138 goto backwards;
139 case f:
140 return "TEST";
141 default:
142 return "Default";
143 }
144 }