aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/attr-noipa.c
blob: 1d2b86894ed2395ab3dd8871335475649e2a05e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Test the noipa attribute.  */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */

static inline int __attribute__((noipa))
fn1 (void) /* { dg-warning "inline function \[^\n\]* given attribute noinline" "" } */
{
  return 1;
}

/* Verify the function is not inlined into its caller.  */

static __attribute__((noipa)) int
fn2 (int x, int y)
{
  return x + y;
}

int
fn3 (int x)
{
  return fn2 (x, 0);
}

/* { dg-final { scan-tree-dump "= fn2 \\(" "optimized" } } */

void fn4 (char *);

/* Verify the function is not cloned.  */

__attribute__((__noipa__)) static int
fn5 (int x, int y)
{
  char *p = __builtin_alloca (x + y);
  fn4 (p);
  return x + y;
}

int
fn6 (int x)
{
  return fn5 (x, 2);
}

/* { dg-final { scan-tree-dump "= fn5 \\(" "optimized" } } */
/* { dg-final { scan-tree-dump-not "fn5\\.constprop" "optimized" } } */

/* Verify we still remove unused function calls, even if they have
   noipa attribute.  */

static void fn7 (void) __attribute__((noipa));
static void
fn7 (void)
{
}

/* { dg-final { scan-tree-dump-not "fn7 \\(" "optimized" } } */

/* Verify noipa functions are not ICF optimized.  */

static __attribute__((noipa)) int
fn8 (int x)
{
  return x + 12;
}

static __attribute__((noipa)) int
fn9 (int x)
{
  return x + 12;
}

int
fn10 (int x)
{
  return fn8 (x) + fn9 (x);
}

/* { dg-final { scan-tree-dump "fn8 \\(int" "optimized" } } */
/* { dg-final { scan-tree-dump "fn9 \\(int" "optimized" } } */

/* Verify IPA-VRP is not performed.  */

void fn11 (void);

static int __attribute__((noipa))
fn12 (int x)
{
  if (x < 6 || x >= 29)
    fn11 ();
}

void
fn13 (int x)
{
  fn12 (6 + (x & 15));
}

/* { dg-final { scan-tree-dump "fn11 \\(\\)" "optimized" } } */

void fn14 (void);

__attribute__((noipa)) static int
fn15 (int x)
{
  return x & 7;
}

int
fn16 (int x)
{
  x = fn15 (x);
  if (x < 0 || x >= 7)
    fn14 ();
}

/* { dg-final { scan-tree-dump "fn14 \\(\\)" "optimized" } } */

/* Verify IPA BIT CP is not performed.  */

void fn17 (void);

__attribute__((noipa)) static int
fn18 (int x)
{
  if (x & 8)
    fn17 ();
}

void
fn19 (void)
{
  fn18 (1);
  fn18 (2);
  fn18 (4);
  fn18 (16);
  fn18 (32);
  fn18 (64);
}

/* { dg-final { scan-tree-dump "fn17 \\(\\)" "optimized" } } */

/* Ensure pure/const discovery is not performed.  */

int var1;
void fn20 (void);

__attribute__((noipa)) static int
fn21 (int x, int y)
{
  return x * y;
}

int
fn22 (void)
{
  var1 = 7;
  asm volatile ("" : "+g" (var1) : : "memory");
  int a = var1;
  int b = fn21 (a, a);
  if (a != var1)
    fn20 ();
  return b;
}

/* { dg-final { scan-tree-dump "fn20 \\(\\)" "optimized" } } */

/* Verify IPA alignment propagation is not performed.  */

static __attribute__ ((aligned(16))) char var2[32];
void fn23 (void);

__attribute__((noipa)) static void
fn24 (char *p)
{
  if ((((__UINTPTR_TYPE__) p) & 15) != 0)
    fn23 ();
  asm ("");
}

void
fn25 (void)
{
  fn24 (var2);
  fn24 (var2 + 16);
}

/* { dg-final { scan-tree-dump "fn20 \\(\\)" "optimized" } } */