* g++.dg/ipa/ipa-icf-1.C: New test.
* g++.dg/ipa/ipa-icf-2.C: New test.
* g++.dg/ipa/ipa-icf-3.C: New test.
* g++.dg/ipa/ipa-icf-4.C: New test.
* g++.dg/ipa/ipa-icf-5.C: New test.
* gcc.dg/ipa/ipa-icf-1.c: New test.
* gcc.dg/ipa/ipa-icf-10.c: New test.
* gcc.dg/ipa/ipa-icf-11.c: New test.
* gcc.dg/ipa/ipa-icf-12.c: New test.
* gcc.dg/ipa/ipa-icf-13.c: New test.
* gcc.dg/ipa/ipa-icf-14.c: New test.
* gcc.dg/ipa/ipa-icf-15.c: New test.
* gcc.dg/ipa/ipa-icf-16.c: New test.
* gcc.dg/ipa/ipa-icf-17.c: New test.
* gcc.dg/ipa/ipa-icf-18.c: New test.
* gcc.dg/ipa/ipa-icf-19.c: New test.
* gcc.dg/ipa/ipa-icf-2.c: New test.
* gcc.dg/ipa/ipa-icf-20.c: New test.
* gcc.dg/ipa/ipa-icf-21.c: New test.
* gcc.dg/ipa/ipa-icf-22.c: New test.
* gcc.dg/ipa/ipa-icf-23.c: New test.
* gcc.dg/ipa/ipa-icf-24.c: New test.
* gcc.dg/ipa/ipa-icf-25.c: New test.
* gcc.dg/ipa/ipa-icf-26.c: New test.
* gcc.dg/ipa/ipa-icf-27.c: New test.
* gcc.dg/ipa/ipa-icf-28.c: New test.
* gcc.dg/ipa/ipa-icf-29.c: New test.
* gcc.dg/ipa/ipa-icf-3.c: New test.
* gcc.dg/ipa/ipa-icf-30.c: New test.
* gcc.dg/ipa/ipa-icf-4.c: New test.
* gcc.dg/ipa/ipa-icf-5.c: New test.
* gcc.dg/ipa/ipa-icf-6.c: New test.
* gcc.dg/ipa/ipa-icf-7.c: New test.
* gcc.dg/ipa/ipa-icf-8.c: New test.
* gcc.dg/ipa/ipa-icf-9.c: New test.
Co-Authored-By: Jan Hubicka <hubicka@ucw.cz>
From-SVN: r216308
+2014-10-16 Martin Liska <mliska@suse.cz>
+ Jan Hubicka <hubicka@ucw.cz>
+
+ * g++.dg/ipa/ipa-icf-1.C: New test.
+ * g++.dg/ipa/ipa-icf-2.C: New test.
+ * g++.dg/ipa/ipa-icf-3.C: New test.
+ * g++.dg/ipa/ipa-icf-4.C: New test.
+ * g++.dg/ipa/ipa-icf-5.C: New test.
+ * gcc.dg/ipa/ipa-icf-1.c: New test.
+ * gcc.dg/ipa/ipa-icf-10.c: New test.
+ * gcc.dg/ipa/ipa-icf-11.c: New test.
+ * gcc.dg/ipa/ipa-icf-12.c: New test.
+ * gcc.dg/ipa/ipa-icf-13.c: New test.
+ * gcc.dg/ipa/ipa-icf-14.c: New test.
+ * gcc.dg/ipa/ipa-icf-15.c: New test.
+ * gcc.dg/ipa/ipa-icf-16.c: New test.
+ * gcc.dg/ipa/ipa-icf-17.c: New test.
+ * gcc.dg/ipa/ipa-icf-18.c: New test.
+ * gcc.dg/ipa/ipa-icf-19.c: New test.
+ * gcc.dg/ipa/ipa-icf-2.c: New test.
+ * gcc.dg/ipa/ipa-icf-20.c: New test.
+ * gcc.dg/ipa/ipa-icf-21.c: New test.
+ * gcc.dg/ipa/ipa-icf-22.c: New test.
+ * gcc.dg/ipa/ipa-icf-23.c: New test.
+ * gcc.dg/ipa/ipa-icf-24.c: New test.
+ * gcc.dg/ipa/ipa-icf-25.c: New test.
+ * gcc.dg/ipa/ipa-icf-26.c: New test.
+ * gcc.dg/ipa/ipa-icf-27.c: New test.
+ * gcc.dg/ipa/ipa-icf-28.c: New test.
+ * gcc.dg/ipa/ipa-icf-29.c: New test.
+ * gcc.dg/ipa/ipa-icf-3.c: New test.
+ * gcc.dg/ipa/ipa-icf-30.c: New test.
+ * gcc.dg/ipa/ipa-icf-4.c: New test.
+ * gcc.dg/ipa/ipa-icf-5.c: New test.
+ * gcc.dg/ipa/ipa-icf-6.c: New test.
+ * gcc.dg/ipa/ipa-icf-7.c: New test.
+ * gcc.dg/ipa/ipa-icf-8.c: New test.
+ * gcc.dg/ipa/ipa-icf-9.c: New test.
+
2014-10-16 Oleg Endo <olegendo@gcc.gnu.org>
PR target/53513
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+class A
+{
+public:
+ __attribute__ ((noinline))
+ virtual int Foo2()
+ {
+ return v;
+ }
+
+ float f;
+ int v;
+};
+
+class B
+{
+public:
+ __attribute__ ((noinline))
+ int Bar2()
+ {
+ return v;
+ }
+
+ float f, aaa;
+ int v;
+};
+
+int main()
+{
+ A a;
+ B b;
+
+ a.Foo2();
+ b.Bar2();
+
+ return 12345;
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+class A
+{
+public:
+ __attribute__ ((noinline))
+ int Foo2()
+ {
+ return 1;
+ }
+
+ int v;
+ float f;
+};
+
+class B
+{
+public:
+ __attribute__ ((noinline))
+ int Bar2()
+ {
+ return 1;
+ }
+
+ int v;
+ float f, aaa;
+};
+
+int main()
+{
+ A a;
+ B b;
+
+ return a.Foo2() + b.Bar2();
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+__attribute__ ((noinline))
+int zero()
+{
+ return 0;
+}
+
+__attribute__ ((noinline))
+int nula()
+{
+ return 0;
+}
+
+__attribute__ ((noinline))
+int foo()
+{
+ return zero();
+}
+
+__attribute__ ((noinline))
+int bar()
+{
+ return nula();
+}
+
+int main()
+{
+ return foo() + bar();
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:.*bar.*->.*foo.*" "icf" } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:.*nula.*->.*zero.*" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 2" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf -fno-inline" } */
+
+namespace {
+struct A
+{
+ virtual void foo(void) {}
+};
+struct B: virtual A
+{
+ virtual void foo(void) {}
+};
+struct C: virtual A
+{
+ virtual void bar(void) {}
+};
+struct D: virtual A
+{
+ virtual void sparta(void) {}
+};
+struct E: B,C,D
+{
+ virtual void foo(void) {}
+ virtual void barbar(void) {}
+};
+} // anonymous namespace
+
+int main()
+{
+ struct A a;
+ struct B b;
+ struct C c;
+ struct D d;
+ struct E e;
+
+ a.foo();
+ b.foo();
+ c.bar();
+ d.foo();
+ d.sparta();
+ e.barbar();
+
+ return 123;
+}
+
+/* { dg-final { scan-ipa-dump "Varpool alias has been created" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 2" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+struct test
+{
+ int a;
+ float b;
+};
+
+extern const struct test myarray __attribute__ ((visibility("hidden")));
+extern const struct test myarray_alias __attribute__ ((visibility("hidden")));
+
+const struct test myarray = {1, 1.5f};
+
+extern const struct test myarray_alias __attribute__ ((alias ("myarray")));
+
+int main()
+{
+ return myarray.a - myarray_alias.a;
+}
+
+/* { dg-final { scan-ipa-dump "Varpool alias cannot be created \\(alias cycle\\)." "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdio.h>
+
+struct container
+{
+ int x;
+ int y;
+};
+
+static struct container max;
+static int array[3][3];
+static int array2[123];
+
+__attribute__ ((noinline))
+void foo(void)
+{
+ printf("Foo()");
+}
+
+__attribute__ ((noinline))
+int order(int x, int y)
+{
+ return x < y ? 2 : 4;
+}
+
+__attribute__ ((noinline))
+int order2(int y, int x)
+{
+ return x < y ? 2 : 4;
+}
+
+__attribute__ ((noinline))
+void x1(int x)
+{
+ int i;
+ for(i = 0; i < 20; ++i)
+ array2[i] = i;
+
+ array2[2] = 13;
+}
+
+__attribute__ ((noinline))
+void x2(int a)
+{
+ int i;
+ for(i = 0; i < 20; ++i)
+ array2[i] = i;
+
+ array2[2] = 13;
+}
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:x2->x1" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+int ferda(int x, int y) __attribute__ ((pure));
+int funkce(int a, int b) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int ferda(int x, int y)
+{
+ if (x < y)
+ {
+ return x;
+ }
+ else
+ return y;
+}
+
+__attribute__ ((noinline))
+int funkce(int a, int b)
+{
+ if(a < b)
+ return a;
+ else
+ return b;
+}
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:funkce->ferda" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+__attribute__ ((noinline))
+int fce(int a, int b)
+{
+ return a + b;
+}
+
+__attribute__ ((noinline))
+int f0(int a)
+{
+ return fce(a, 5) + fce(a, 7);
+}
+
+__attribute__ ((noinline))
+int f1(int a)
+{
+ return fce(a, 5) + fce(a, 7);
+}
+
+int main(int argc, char **argv)
+{
+ return f0(argc) * f1(argc);
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:f1->f0" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int gcd(int x, int y) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int gcd(int x, int y)
+{
+ int swap;
+
+ if(x <= 0 || y <= 0)
+ return 0;
+
+ if(x < y)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+
+ while(x != y)
+ {
+ x = x - y;
+
+ if(y > x)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+ }
+
+ return x;
+}
+
+int nsd(int x, int y) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int nsd(int x, int y)
+{
+ int swap;
+
+ if(x <= 0 || y <= 0)
+ return 0;
+
+ if(x < y)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+
+ while(x != y)
+ {
+ x = x - y;
+
+ if(y > x)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+ }
+
+ return x;
+}
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:nsd->gcd" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int gcd(int x, int y) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int gcd(int x, int y)
+{
+ int swap;
+
+ if(x <= 0 || y <= 0)
+ return 0;
+
+ if(x < y)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+
+ while(x != y)
+ {
+ x = x - y;
+
+ if(y > x)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+ }
+
+ return x;
+}
+
+int nsd(int x, int y) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int nsd(int x, int y)
+{
+ int swap;
+
+ if(x <= 0 || y <= 0)
+ return 0;
+
+ if(x < y)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+
+ while(x != y)
+ {
+ x = x - y;
+
+ if(y > x)
+ {
+ swap = x;
+ x = y;
+ y = swap;
+ }
+ }
+
+ return x;
+}
+
+int nsd_different_result(int x, int y) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int nsd_different_result(int x, int y)
+{
+ int pes;
+
+ if(x <= 0 || y <= 0)
+ return 1;
+
+ if(x < 10)
+ y = 12;
+ else if(x == 44)
+ y = 124;
+ else
+ y = 1111;
+
+ if(x < y)
+ {
+ pes = x;
+ x = y;
+ y = pes;
+ }
+
+ while(x != y)
+ {
+ x = x - y;
+
+ if(y > x)
+ {
+ pes = x;
+ x = y;
+ y = pes;
+ }
+ }
+
+ return x;
+}
+
+int nsd_different_result2(int x, int y) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int nsd_different_result2(int x, int y)
+{
+ int pes;
+
+ if(x <= 0 || y <= 0)
+ return 1;
+
+ if(x < 10)
+ y = 12;
+ else if(x == 44)
+ y = 124;
+ else
+ y = 1111;
+
+ if(x < y)
+ {
+ pes = x;
+ x = y;
+ y = pes;
+ }
+
+ while(x != y)
+ {
+ x = x - y;
+
+ if(y > x)
+ {
+ pes = x;
+ x = y;
+ y = pes;
+ }
+ }
+
+ return x;
+}
+
+__attribute__ ((noinline))
+int s1(int x)
+{
+ switch (x)
+ {
+ case 10:
+ case 11:
+ return 2;
+ case 12:
+ return 123;
+ default:
+ return x + 2;
+ }
+}
+
+__attribute__ ((noinline))
+int s2(int x)
+{
+ switch (x)
+ {
+ case 10:
+ case 11:
+ return 2;
+ case 12:
+ return 123;
+ default:
+ return x + 2;
+ }
+}
+int main(int argc, char **argv)
+{
+ if(argc < 3)
+ return 1;
+
+ int a = atoi(argv[1]);
+ int b = atoi(argv[2]);
+
+ printf("Test1: %d, %d, gdc: %d\n", a, b, gcd(a, b));
+ printf("Test2: %d, %d, gdc: %d\n", a, b, nsd(a, b));
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:s2->s1" "icf" } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:nsd_different_result2->nsd_different_result" "icf" } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:nsd->gcd" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 3" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdio.h>
+
+__attribute__ ((noinline))
+int foo(int a)
+{
+ void *l = &&error;
+
+ if(a == 4)
+ goto *l;
+
+ return 150;
+
+error:
+ return a;
+failure:
+ return a + 2;
+}
+
+__attribute__ ((noinline))
+int foo_wrong(int a)
+{
+ void *l = &&failure;
+
+ if(a == 4)
+ goto *l;
+
+ return 150;
+
+error:
+ return a;
+failure:
+ return a + 2;
+}
+
+int main(int argc, char **argv)
+{
+ printf("value: %d\n", foo(argc));
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdio.h>
+
+__attribute__ ((noinline))
+int bar(int a)
+{
+ void *l = &&error;
+
+ if(a == 4)
+ goto *l;
+
+ return 150;
+
+error:
+ return a;
+failure:
+ return a + 2;
+}
+
+__attribute__ ((noinline))
+int foo(int a)
+{
+ void *l = &&error;
+
+ if(a == 4)
+ goto *l;
+
+ return 150;
+
+error:
+ return a;
+failure:
+ return a + 2;
+}
+
+int main(int argc, char **argv)
+{
+ printf("value: %d\n", foo(argc));
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdio.h>
+
+__attribute__ ((noinline))
+int foo()
+{
+ printf ("Hello world.\n");
+ return 0;
+}
+
+__attribute__ ((noinline))
+int bar()
+{
+ printf ("Hello world.\n");
+ return 0;
+}
+
+int main()
+{
+ return foo() + bar();
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+__attribute__ ((noinline))
+int foo(int x)
+{
+ int c = x;
+
+ if (x > 10)
+ c += 2;
+ else
+ c -= 3;
+
+ return x;
+}
+
+__attribute__ ((noinline))
+int bar(int y)
+{
+ int d = y;
+
+ if (y > 10)
+ d += 2;
+ else
+ d -= 3;
+
+ return d;
+}
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+__attribute__ ((noinline))
+int foo(int x)
+{
+ int c = x;
+
+ if (x > 10)
+ c += 2;
+ else
+ c -= 3;
+
+ return c;
+}
+
+__attribute__ ((noinline))
+int bar(int y)
+{
+ int d = y;
+
+ if (y > 10)
+ d += 2;
+ else
+ d -= 3;
+
+ return d;
+}
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+__attribute__ ((noinline))
+int foo(int x)
+{
+ int c = x;
+
+ if (x > 10)
+ c += 2;
+ else
+ c -= 3;
+
+ return c;
+}
+
+__attribute__ ((noinline))
+int bar(int y)
+{
+ int d = y;
+
+ if (y > 11)
+ d += 2;
+ else
+ d -= 3;
+
+ return d;
+}
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdio.h>
+
+struct container
+{
+ int x;
+ int y;
+};
+
+static struct container max;
+static int pole[3][3];
+static int pole2[123];
+
+static struct container superpole[10][10];
+
+void f1(struct container *c)
+{
+ struct container pes;
+ pes.x = 123;
+ pes.y = 123;
+
+ struct container *pesp = c;
+ pesp->x = 5;
+
+ pole[1][2] = 3;
+
+ superpole[4][3].x = 4;
+ max.x = 3;
+ void *x = &pole;
+
+ int **a = (int**)pole;
+ a[1][2] = 543;
+
+ if(x != 0)
+ pole[1][2] = 123;
+}
+
+void f2(struct container *c)
+{
+ struct container pes;
+ pes.x = 123;
+ pes.y = 123;
+
+ struct container *pesp = c;
+ pesp->x = 5;
+
+ pole[1][2] = 3;
+
+ superpole[4][3].x = 4;
+ max.x = 3;
+ void *x = &pole;
+
+ int **a = (int**)pole;
+ a[1][2] = 543;
+
+ if(x != 0)
+ pole[1][2] = 123;
+}
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:f2->f1" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <math.h>
+
+__attribute__ ((noinline))
+float foo()
+{
+ return sin(12.4f);
+}
+
+__attribute__ ((noinline))
+float bar()
+{
+ return sin(12.4f);
+}
+
+int main()
+{
+ foo();
+ bar();
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <xmmintrin.h>
+
+__attribute__ ((noinline))
+void foo()
+{
+ float x = 1.2345f;
+ __m128 v =_mm_load1_ps(&x);
+}
+
+__attribute__ ((noinline))
+void bar()
+{
+ float x = 1.2345f;
+ __m128 v =_mm_load1_ps(&x);
+}
+
+int main()
+{
+ return 2;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+struct A
+{
+ int a, b, c;
+};
+
+struct B
+{
+ int x, y;
+};
+
+__attribute__ ((noinline))
+int foo(struct A *a)
+{
+ a->c = 1;
+
+ return 123;
+}
+
+__attribute__ ((noinline))
+int bar(struct B *b)
+{
+ b->y = 1;
+
+ return 123;
+}
+
+int main()
+{
+ return foo(0) + bar(0);
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+struct A
+{
+ int a;
+ int b;
+};
+
+__attribute__ ((noinline))
+int foo(struct A *a)
+{
+ return 123;
+}
+
+__attribute__ ((noinline))
+int bar(struct A *b)
+{
+ return 123;
+}
+
+int main()
+{
+ return foo(0) + bar(0);
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+struct A
+{
+ int a, b, c, d;
+};
+
+struct B
+{
+ int x, y, z;
+};
+
+__attribute__ ((noinline))
+int foo(struct A *a)
+{
+ a->c = 1;
+
+ return 123;
+}
+
+__attribute__ ((noinline))
+int bar(struct B *b)
+{
+ b->z = 1;
+
+ return 123;
+}
+
+int main()
+{
+ return foo(0) + bar(0);
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+static int zip();
+static int zap();
+static int two();
+
+__attribute__ ((noinline))
+int foo()
+{
+ return zip();
+}
+
+__attribute__ ((noinline))
+int bar()
+{
+ return zap();
+}
+
+__attribute__ ((noinline))
+int baz()
+{
+ return two();
+}
+
+__attribute__ ((noinline))
+int zip()
+{
+ return 0;
+}
+
+__attribute__ ((noinline))
+int zap()
+{
+ return 0;
+}
+
+__attribute__ ((noinline))
+int two()
+{
+ return 2;
+}
+
+int main()
+{
+ return foo() + bar();
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:zap->zip" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 2" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+void destroy (void)
+{
+}
+
+void remove (void)
+{
+}
+
+
+struct callbacks
+{
+ void (*success) (void);
+ void (*error) (void);
+};
+
+struct callbacks my_callbacks;
+
+__attribute__ ((noinline))
+void foo()
+{
+ my_callbacks.success = destroy;
+}
+
+__attribute__ ((noinline))
+void bar()
+{
+ my_callbacks.success = remove;
+}
+
+int main()
+{
+ foo();
+ bar();
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:remove->destroy" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 2" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf -fno-inline" } */
+
+void destroy (void)
+{
+ __asm__ __volatile__ ("" : : : "memory");
+}
+
+void remove (void)
+{
+ __asm__ __volatile__ ("" : : : "memory");
+}
+
+void remove2 (void)
+{
+ __asm__ __volatile__ ("" : : : );
+}
+
+int main()
+{
+ destroy ();
+ remove ();
+ remove2 ();
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:remove->destroy" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf-details -fno-inline" } */
+
+__attribute__ ((noinline, constructor(200)))
+int foo()
+{
+ return 123;
+}
+
+__attribute__ ((noinline, constructor(400)))
+int bar()
+{
+ return 123;
+}
+
+int main()
+{
+ foo() + bar();
+
+ return 0;
+}
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { scan-ipa-dump "attribute values are different" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf -fno-inline" } */
+
+struct str
+{
+ unsigned a:1, b:1;
+};
+
+static struct str test;
+
+unsigned foo(struct str *s)
+{
+ return s->a;
+}
+
+unsigned bar(struct str *s)
+{
+ return s->b;
+}
+
+int main()
+{
+ test.a = 0;
+ test.b = 1;
+
+ return foo (&test) != bar (&test);
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+typedef int v4si __attribute__ ((vector_size (16)));
+
+__attribute__ ((noinline))
+int foo(void)
+{
+ v4si a = {1,2,3,4};
+ v4si b = {3,2,1,4};
+ v4si c;
+
+ return 54;
+}
+
+__attribute__ ((noinline))
+int bar(void)
+{
+ v4si a = {1,2,3,4};
+ v4si b = {3,2,1,4};
+ v4si c;
+
+ return 54;
+}
+
+int main()
+{
+ foo();
+ bar();
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:bar->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf -fno-inline" } */
+
+struct str
+{
+ unsigned a:1, b:1;
+};
+
+static struct str test;
+
+unsigned foo(struct str *s)
+{
+ return s->a;
+}
+
+unsigned bar(struct str *s)
+{
+ return s->a;
+}
+
+int main()
+{
+ test.a = 0;
+ test.b = 1;
+
+ return foo (&test) == bar (&test);
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+__attribute__ ((noinline))
+int foo(int a)
+{
+ return a * a;
+}
+
+__attribute__ ((noinline))
+int bar(int b)
+{
+ return b;
+}
+
+__attribute__ ((noinline))
+void caller(int x)
+{
+ return;
+}
+
+int main(int argc, char **argv)
+{
+ caller(foo(argc));
+ caller(bar(argc));
+
+ return 123;
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <complex.h>
+
+static double test;
+
+__attribute__ ((noinline))
+double f1(void)
+{
+ double complex z1 = 1.0 + 3.0 * I;
+ double complex z2 = 1.0 - 4.0 * I;
+
+ unsigned a = 123;
+ unsigned b = 321;
+
+ if (a & b)
+ return 1.2f;
+
+ if(cimag(z1) > 1)
+ return 1.0f;
+
+ test = cimag(z1) + 2;
+
+ return cimag(z1 + z2);
+}
+
+__attribute__ ((noinline))
+double f2(void)
+{
+ double complex z1 = 1.0 + 3.0 * I;
+ double complex z2 = 1.0 - 4.0 * I;
+
+ unsigned a = 123;
+ unsigned b = 321;
+
+ if (a & b)
+ return 1.2f;
+
+ if(cimag(z1) > 1)
+ return 1.0f;
+
+ test = cimag(z1) + 2;
+
+ return cimag(z1 + z2);
+}
+
+int main()
+{
+ return 1;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:f2->f1" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O0 -fipa-icf -fdump-ipa-icf" } */
+
+typedef int v4si __attribute__ ((vector_size (16)));
+
+__attribute__ ((noinline))
+int foo(void)
+{
+ v4si a = {1,2,3,4};
+ v4si b = {3,2,1,4};
+ v4si c;
+
+ return 54;
+}
+
+__attribute__ ((noinline))
+int bar(void)
+{
+ v4si a = {1,2,3,4};
+ v4si b = {3,2,5,4};
+ v4si c;
+
+ return 54;
+}
+
+int main()
+{
+ foo();
+ bar();
+
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <complex.h>
+
+#if (__SIZEOF_INT__ == __SIZEOF_FLOAT__)
+typedef int intflt;
+#elif (__SIZEOF_LONG__ == __SIZEOF_FLOAT__)
+typedef long intflt;
+#else
+#error Add target support here for type that will union float size
+#endif
+
+
+static double test;
+
+struct struktura
+{
+ union
+ {
+ long i;
+ float f;
+ } u;
+};
+
+struct struktura sss;
+
+struct X
+{
+ int i;
+ union
+ {
+ intflt j;
+ intflt k;
+ float f;
+ } u;
+};
+
+__attribute__ ((noinline))
+intflt foo(intflt j)
+{
+ struct X a;
+
+ a.u.j = j;
+ a.u.f = a.u.f;
+ a.u.f = a.u.f;
+ a.u.j = a.u.j;
+ a.u.f = a.u.f;
+ return a.u.k;
+}
+
+__attribute__ ((noinline))
+intflt foo2(intflt j)
+{
+ struct X a;
+
+ a.u.j = j;
+ a.u.f = a.u.f;
+ a.u.f = a.u.f;
+ a.u.j = a.u.j;
+ a.u.f = a.u.f;
+ return a.u.k;
+}
+
+int main()
+{
+ return 1;
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:foo2->foo" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+#include <stdio.h>
+
+__attribute__ ((noinline))
+int fce1(int a, int b)
+{
+ int swap;
+
+ if(a < b)
+ {
+ swap = a;
+ a = b;
+ b = swap;
+ }
+
+ return a / b;
+}
+
+__attribute__ ((noinline))
+int fce2(int x, int y)
+{
+ int tmp;
+
+ if(x < y)
+ {
+ tmp = x;
+ x = y;
+ y = tmp;
+ }
+
+ return x / y;
+}
+
+
+int main(int argc, char **argv)
+{
+ printf("fce1: %d\n", fce1(argc, argc + 2));
+ printf("fce2: %d\n", fce2(argc, 2 * argc));
+}
+
+/* { dg-final { scan-ipa-dump "Semantic equality hit:fce2->fce1" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf" } */
+
+int funkce(int a, int b) __attribute__ ((pure));
+
+__attribute__ ((noinline))
+int ferda(int x, int y)
+{
+ if (x < y)
+ {
+ return x;
+ }
+ else
+ return y;
+}
+
+__attribute__ ((noinline))
+int funkce(int a, int b)
+{
+ if(a < b)
+ return a;
+ else
+ return b;
+}
+
+int main(int argc, char **argv)
+{
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-not "Semantic equality hit:" "icf" } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */