| 1 |
/* { dg-do compile { target { nonpic || pie_enabled } } } */ |
| 2 |
/* { dg-options "-O3 -fno-ipa-vrp -fdump-tree-local-pure-const1 -fdump-ipa-pure-const -fdump-tree-optimized -fno-early-inlining -fgnu89-inline" } */ |
| 3 |
void abort (void); |
| 4 |
int error_code; |
| 5 |
static int val; |
| 6 |
__attribute__ ((noinline, noclone)) |
| 7 |
static int |
| 8 |
i_am_pure1 (int a) |
| 9 |
{ |
| 10 |
if (a > 50) |
| 11 |
abort (); |
| 12 |
return a; |
| 13 |
} |
| 14 |
|
| 15 |
__attribute__ ((noinline, noclone)) |
| 16 |
static int |
| 17 |
i_am_const2 (int a) |
| 18 |
{ |
| 19 |
return a+val; |
| 20 |
} |
| 21 |
|
| 22 |
__attribute__ ((noinline, noclone)) |
| 23 |
int |
| 24 |
call_me(int a) |
| 25 |
{ |
| 26 |
return a; |
| 27 |
} |
| 28 |
|
| 29 |
inline int |
| 30 |
call_callback(int (*fn)(int), int a) |
| 31 |
{ |
| 32 |
return fn(a); |
| 33 |
} |
| 34 |
|
| 35 |
__attribute__ ((noinline, noclone)) int |
| 36 |
i_am_const3(int a) |
| 37 |
{ |
| 38 |
return call_callback (call_me, a); |
| 39 |
} |
| 40 |
|
| 41 |
__attribute__ ((noinline)) int |
| 42 |
explode_badly() |
| 43 |
{ |
| 44 |
error_code = 0xbad; |
| 45 |
abort (); |
| 46 |
} |
| 47 |
|
| 48 |
__attribute__ ((noinline, noclone)) int |
| 49 |
i_am_pure4(int a) |
| 50 |
{ |
| 51 |
if (a > 50) |
| 52 |
explode_badly (); |
| 53 |
return a; |
| 54 |
} |
| 55 |
|
| 56 |
int |
| 57 |
test() |
| 58 |
{ |
| 59 |
int s; |
| 60 |
s = i_am_pure1(5); |
| 61 |
s += i_am_pure1(5); |
| 62 |
s += i_am_const2(5); |
| 63 |
s += i_am_const2(5); |
| 64 |
s += i_am_const3(5); |
| 65 |
s += i_am_const3(5); |
| 66 |
s += i_am_pure4(5); |
| 67 |
s += i_am_pure4(5); |
| 68 |
return s; |
| 69 |
} |
| 70 |
/* { dg-final { scan-tree-dump-times "i_am_pure1 .5" 1 "optimized"} } */ |
| 71 |
/* { dg-final { scan-tree-dump-times "i_am_const2 .5" 1 "optimized"} } */ |
| 72 |
/* { dg-final { scan-tree-dump-times "i_am_const3 .5" 1 "optimized"} } */ |
| 73 |
/* { dg-final { scan-tree-dump-times "i_am_pure4 .5" 1 "optimized"} } */ |
| 74 |
/* { dg-final { scan-tree-dump "found to be looping pure: i_am_pure1" "local-pure-const1"} } */ |
| 75 |
/* { dg-final { scan-tree-dump "found to be looping pure: i_am_pure4" "local-pure-const1"} } */ |
| 76 |
/* { dg-final { scan-ipa-dump "found to be const: i_am_const2" "pure-const"} } */ |
| 77 |
/* { dg-final { scan-ipa-dump "found to be const: i_am_const3" "pure-const"} } */ |
| 78 |
|