Debian Codegraph @

gcc/testsuite/gcc.target/mips/insn-casesi.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-mips16 -mcode-readable=yes" } */
3
4 int __attribute__ ((noinline))
5 frob (int i)
6 {
7 switch (i)
8 {
9 case -5:
10 return -2;
11 case -3:
12 return -1;
13 case 0:
14 return 0;
15 case 3:
16 return 1;
17 case 5:
18 break;
19 default:
20 __builtin_unreachable ();
21 }
22 return i;
23 }
24
25 int
26 main (int argc, char **argv)
27 {
28 asm ("" : "+r" (argc));
29 argc = frob ((argc & 10) - 5);
30 asm ("" : "+r" (argc));
31 return !argc;
32 }
33
34 /* This will result in assembly like:
35
36 .text
37 .align 2
38 .globl frob
39 .set mips16
40 .set nomicromips
41 .ent frob
42 .type frob, @function
43 frob:
44 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
45 .mask 0x00000000,0
46 .fmask 0x00000000,0
47 addiu $2,$4,5
48 sltu $2,11
49 bteqz $L2
50 sll $3,$2,1
51 la $2,$L4
52 addu $3,$2,$3
53 lh $3,0($3)
54 addu $2,$2,$3
55 j $2
56 .align 1
57 .align 2
58 $L4:
59 .half $L3-$L4
60 .half $L2-$L4
61 .half $L9-$L4
62 .half $L2-$L4
63 .half $L2-$L4
64 .half $L8-$L4
65 .half $L2-$L4
66 .half $L2-$L4
67 .half $L7-$L4
68 .half $L2-$L4
69 .half $L8-$L4
70 $L8:
71 .set noreorder
72 .set nomacro
73 jr $31
74 move $2,$4
75 .set macro
76 .set reorder
77
78 $L9:
79 li $2,1
80 .set noreorder
81 .set nomacro
82 jr $31
83 neg $2,$2
84 .set macro
85 .set reorder
86
87 $L3:
88 li $2,2
89 .set noreorder
90 .set nomacro
91 jr $31
92 neg $2,$2
93 .set macro
94 .set reorder
95
96 $L7:
97 .set noreorder
98 .set nomacro
99 jr $31
100 li $2,1
101 .set macro
102 .set reorder
103
104 $L2:
105 .insn
106 .end frob
107 .size frob, .-frob
108
109 for `frob' and we want to make sure it links correctly owing to the
110 `.insn' pseudo-op which needs to be there at `$L2' as there's no
111 code following and the label is a MIPS16 branch target (even though
112 the branch is never taken. See also insn-tablejump.c. */