[PATCH] Add testcase for already fixed bug

Jakub Jelinek jakub@redhat.com
Thu Jul 12 11:23:00 GMT 2018


Hi!

I've created a self-contained testcase for a powerpc64{,le}
wrong-code introduced (at least for powerpc64le) with r256656
and just later found it was already fixed with r260329.
The SLP vectorized:
+  w.l = x.l;
+  w.u = x.u;
was actually swapping it, so acting as:
  w.u = x.l;
  w.l = x.u;
instead.  As the testcase is sufficiently different from PR85698
testcase, I've committed this one too to trunk.

2018-07-12  Jakub Jelinek  <jakub@redhat.com>

	* gcc.dg/torture/20180712-1.c: New test.

--- gcc/testsuite/gcc.dg/torture/20180712-1.c.jj	2018-07-12 13:14:46.513068757 +0200
+++ gcc/testsuite/gcc.dg/torture/20180712-1.c	2018-07-12 13:14:07.851035363 +0200
@@ -0,0 +1,76 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fstack-protector" { target fstack_protector } } */
+/* { dg-additional-options "-fPIC" { target fpic } } */
+
+struct S { int *l, *u; };
+int a[3];
+
+__attribute__((noipa)) struct S
+foo (void)
+{
+  int *p = a, *q = a + 1;
+  struct S s;
+  asm volatile ("" : "+g" (p), "+g" (q) : : "memory");
+  s.l = p;
+  s.u = q;
+  a[0]++;
+  return s;
+}
+
+__attribute__((noipa)) void
+bar (struct S *x)
+{
+  asm volatile ("" : : "g" (x) : "memory");
+  if (x->l != a || x->u != a + 1)
+    __builtin_abort ();
+  a[1]++;
+}
+
+__attribute__((noipa)) int
+baz (int *x, int *y)
+{
+  int r = -1;
+  asm volatile ("" : "+g" (r) : "g" (x), "g" (y) : "memory");
+  a[2]++;
+  return r;
+}
+
+__attribute__((noipa)) void
+quux (void)
+{
+  asm volatile ("" : : : "memory");
+}
+
+__attribute__((noipa)) void
+qux (void)
+{
+  struct S v = foo ();
+  struct S w;
+  struct S x = foo ();
+  int y = 0;
+
+  w.l = x.l;
+  w.u = x.u;
+  if (baz (x.l, v.l) > 0)
+    {
+      w.l = v.l;
+      y = 1;
+      quux ();
+    }
+  if (baz (x.u, v.u) < 0)
+    {
+      w.u = v.u;
+      y = 1;
+    }
+  if (y)
+    bar (&w);
+}
+
+int
+main ()
+{
+  qux ();
+  if (a[0] != 2 || a[1] != 1 || a[2] != 2)
+    __builtin_abort ();
+  return 0;
+}


	Jakub



More information about the Gcc-patches mailing list