1 /* Verify that indirect inlining can also remove references of the functions it
2    discovers calls for.  */
3 /* { dg-do compile } */
4 /* { dg-options "-O3 -fno-early-inlining -fno-ipa-cp -fdump-ipa-inline -fdump-tree-optimized -fno-ipa-icf"  } */
5 
6 int global;
7 
8 void __attribute__ ((noinline, noclone, used))
stuff(int i)9 stuff (int i)
10 {
11   global = i;
12 }
13 
get_input(void)14 int __attribute__ ((noinline,noclone)) get_input(void)
15 {
16   return 1;
17 }
18 
19 static void
hooray_1()20 hooray_1 ()
21 {
22   stuff (1);
23 }
24 
25 static inline void
hip2_1(void (* g)())26 hip2_1 (void (*g)())
27 {
28   int i;
29   g ();
30   /* Some stuff to make the function bigger so that hip1_1 gets inlined
31      fiorst. */
32   for (i = 0; i < get_input (); i++)
33     {
34       stuff (2);
35       stuff (2+2);
36     }
37 }
38 
39 static inline void
hip1_1(void (* g)())40 hip1_1 (void (*g)())
41 {
42   hip2_1 (g);
43 }
44 
45 static void
hooray_2()46 hooray_2 ()
47 {
48   stuff (1);
49 }
50 
51 static inline void
hip2_2(void (* g)())52 hip2_2 (void (*g)())
53 {
54   g ();
55 }
56 
57 static inline void
hip1_2(void (* g)())58 hip1_2 (void (*g)())
59 {
60   int i;
61 
62   hip2_2 (g);
63 
64   /* Some stuff to make the function bigger so that hip2_2 gets inlined
65      fiorst. */
66   for (i = 0; i < get_input (); i++)
67     {
68       stuff (2);
69       stuff (2+2);
70     }
71 }
72 
73 
74 int
main(int argc,int * argv[])75 main (int argc, int *argv[])
76 {
77   int i;
78 
79   for (i = 0; i < get_input (); i++)
80     {
81       hip1_1 (hooray_1);
82       hip1_2 (hooray_2);
83     }
84   return 0;
85 }
86 
87 /* { dg-final { scan-ipa-dump-times "ipa-prop: Removed a reference" 2 "inline"  } } */
88 /* { dg-final { scan-tree-dump-not "hooray"  "optimized"  } } */
89