Debian Codegraph @

gcc/testsuite/gcc.dg/attr-noipa.c

raw
1 /* Test the noipa attribute. */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -fdump-tree-optimized" } */
4
5 static inline int __attribute__((noipa))
6 fn1 (void) /* { dg-warning "inline function \[^\n\]* given attribute 'noinline'" "" } */
7 {
8 return 1;
9 }
10
11 /* Verify the function is not inlined into its caller. */
12
13 static __attribute__((noipa)) int
14 fn2 (int x, int y)
15 {
16 return x + y;
17 }
18
19 int
20 fn3 (int x)
21 {
22 return fn2 (x, 0);
23 }
24
25 /* { dg-final { scan-tree-dump "= fn2 \\(" "optimized" } } */
26
27 void fn4 (char *);
28
29 /* Verify the function is not cloned. */
30
31 __attribute__((__noipa__)) static int
32 fn5 (int x, int y)
33 {
34 char *p = __builtin_alloca (x + y);
35 fn4 (p);
36 return x + y;
37 }
38
39 int
40 fn6 (int x)
41 {
42 return fn5 (x, 2);
43 }
44
45 /* { dg-final { scan-tree-dump "= fn5 \\(" "optimized" } } */
46 /* { dg-final { scan-tree-dump-not "fn5\\.constprop" "optimized" } } */
47
48 /* Verify we still remove unused function calls, even if they have
49 noipa attribute. */
50
51 static void fn7 (void) __attribute__((noipa));
52 static void
53 fn7 (void)
54 {
55 }
56
57 /* { dg-final { scan-tree-dump-not "fn7 \\(" "optimized" } } */
58
59 /* Verify noipa functions are not ICF optimized. */
60
61 static __attribute__((noipa)) int
62 fn8 (int x)
63 {
64 return x + 12;
65 }
66
67 static __attribute__((noipa)) int
68 fn9 (int x)
69 {
70 return x + 12;
71 }
72
73 int
74 fn10 (int x)
75 {
76 return fn8 (x) + fn9 (x);
77 }
78
79 /* { dg-final { scan-tree-dump "fn8 \\(int" "optimized" } } */
80 /* { dg-final { scan-tree-dump "fn9 \\(int" "optimized" } } */
81
82 /* Verify IPA-VRP is not performed. */
83
84 void fn11 (void);
85
86 static int __attribute__((noipa))
87 fn12 (int x)
88 {
89 if (x < 6 || x >= 29)
90 fn11 ();
91 }
92
93 void
94 fn13 (int x)
95 {
96 fn12 (6 + (x & 15));
97 }
98
99 /* { dg-final { scan-tree-dump "fn11 \\(\\)" "optimized" } } */
100
101 void fn14 (void);
102
103 __attribute__((noipa)) static int
104 fn15 (int x)
105 {
106 return x & 7;
107 }
108
109 int
110 fn16 (int x)
111 {
112 x = fn15 (x);
113 if (x < 0 || x >= 7)
114 fn14 ();
115 }
116
117 /* { dg-final { scan-tree-dump "fn14 \\(\\)" "optimized" } } */
118
119 /* Verify IPA BIT CP is not performed. */
120
121 void fn17 (void);
122
123 __attribute__((noipa)) static int
124 fn18 (int x)
125 {
126 if (x & 8)
127 fn17 ();
128 }
129
130 void
131 fn19 (void)
132 {
133 fn18 (1);
134 fn18 (2);
135 fn18 (4);
136 fn18 (16);
137 fn18 (32);
138 fn18 (64);
139 }
140
141 /* { dg-final { scan-tree-dump "fn17 \\(\\)" "optimized" } } */
142
143 /* Ensure pure/const discovery is not performed. */
144
145 int var1;
146 void fn20 (void);
147
148 __attribute__((noipa)) static int
149 fn21 (int x, int y)
150 {
151 return x * y;
152 }
153
154 int
155 fn22 (void)
156 {
157 var1 = 7;
158 asm volatile ("" : "+g" (var1) : : "memory");
159 int a = var1;
160 int b = fn21 (a, a);
161 if (a != var1)
162 fn20 ();
163 return b;
164 }
165
166 /* { dg-final { scan-tree-dump "fn20 \\(\\)" "optimized" } } */
167
168 /* Verify IPA alignment propagation is not performed. */
169
170 static __attribute__ ((aligned(16))) char var2[32];
171 void fn23 (void);
172
173 __attribute__((noipa)) static void
174 fn24 (char *p)
175 {
176 if ((((__UINTPTR_TYPE__) p) & 15) != 0)
177 fn23 ();
178 asm ("");
179 }
180
181 void
182 fn25 (void)
183 {
184 fn24 (var2);
185 fn24 (var2 + 16);
186 }
187
188 /* { dg-final { scan-tree-dump "fn20 \\(\\)" "optimized" } } */