[3/3] Add tests for the vartrace pass

Message ID 20180212025317.28068-3-andi@firstfloor.org
State New
Headers show
Series
  • [1/3] Add PTWRITE builtins for x86
Related show

Commit Message

Andi Kleen Feb. 12, 2018, 2:53 a.m.
From: Andi Kleen <ak@linux.intel.com>

gcc/testsuite/:

2018-02-10  Andi Kleen  <ak@linux.intel.com>

	* g++.dg/vartrace-3.C: New test.
	* g++.dg/vartrace-ret.C: New test.
	* g++.dg/vartrace-ret2.C: New test.
	* gcc.target/i386/vartrace-1.c: New test.
	* gcc.target/i386/vartrace-10.c: New test.
	* gcc.target/i386/vartrace-11.c: New test.
	* gcc.target/i386/vartrace-12.c: New test.
	* gcc.target/i386/vartrace-13.c: New test.
	* gcc.target/i386/vartrace-14.c: New test.
	* gcc.target/i386/vartrace-15.c: New test.
	* gcc.target/i386/vartrace-16.c: New test.
	* gcc.target/i386/vartrace-2.c: New test.
	* gcc.target/i386/vartrace-3.c: New test.
	* gcc.target/i386/vartrace-4.c: New test.
	* gcc.target/i386/vartrace-5.c: New test.
	* gcc.target/i386/vartrace-6.c: New test.
	* gcc.target/i386/vartrace-7.c: New test.
	* gcc.target/i386/vartrace-8.c: New test.
	* gcc.target/i386/vartrace-9.c: New test.
---
 gcc/testsuite/g++.dg/vartrace-3.C           | 14 ++++++++++
 gcc/testsuite/g++.dg/vartrace-ret.C         | 17 ++++++++++++
 gcc/testsuite/g++.dg/vartrace-ret2.C        | 24 +++++++++++++++++
 gcc/testsuite/gcc.target/i386/vartrace-1.c  | 41 +++++++++++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/vartrace-10.c | 13 +++++++++
 gcc/testsuite/gcc.target/i386/vartrace-11.c | 16 +++++++++++
 gcc/testsuite/gcc.target/i386/vartrace-12.c | 16 +++++++++++
 gcc/testsuite/gcc.target/i386/vartrace-13.c | 18 +++++++++++++
 gcc/testsuite/gcc.target/i386/vartrace-14.c | 17 ++++++++++++
 gcc/testsuite/gcc.target/i386/vartrace-15.c | 12 +++++++++
 gcc/testsuite/gcc.target/i386/vartrace-16.c | 12 +++++++++
 gcc/testsuite/gcc.target/i386/vartrace-17.c | 23 ++++++++++++++++
 gcc/testsuite/gcc.target/i386/vartrace-2.c  |  9 +++++++
 gcc/testsuite/gcc.target/i386/vartrace-3.c  |  9 +++++++
 gcc/testsuite/gcc.target/i386/vartrace-4.c  | 13 +++++++++
 gcc/testsuite/gcc.target/i386/vartrace-5.c  | 11 ++++++++
 gcc/testsuite/gcc.target/i386/vartrace-6.c  | 13 +++++++++
 gcc/testsuite/gcc.target/i386/vartrace-7.c  | 11 ++++++++
 gcc/testsuite/gcc.target/i386/vartrace-8.c  | 11 ++++++++
 gcc/testsuite/gcc.target/i386/vartrace-9.c  | 11 ++++++++
 gcc/tree-vartrace.c                         |  7 ++---
 21 files changed, 315 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/vartrace-3.C
 create mode 100644 gcc/testsuite/g++.dg/vartrace-ret.C
 create mode 100644 gcc/testsuite/g++.dg/vartrace-ret2.C
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-10.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-11.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-12.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-13.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-14.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-15.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-16.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-17.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-3.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-4.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-5.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-6.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-7.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-8.c
 create mode 100644 gcc/testsuite/gcc.target/i386/vartrace-9.c

Patch

diff --git a/gcc/testsuite/g++.dg/vartrace-3.C b/gcc/testsuite/g++.dg/vartrace-3.C
new file mode 100644
index 00000000000..13f71cca6d8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vartrace-3.C
@@ -0,0 +1,14 @@ 
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-O2 -mptwrite -fvartrace-args " } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int a;
+int b(int c) 
+{
+  if (a)
+    c += 1;
+  else
+    c += b(a);
+  b(c);
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/vartrace-ret.C b/gcc/testsuite/g++.dg/vartrace-ret.C
new file mode 100644
index 00000000000..2a8a6753bd3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vartrace-ret.C
@@ -0,0 +1,17 @@ 
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-O2 -mptwrite -fvartrace-returns " } */
+/* { dg-final { scan-assembler-not "ptwrite" } } */
+
+class foo { 
+public:
+    short a;
+    short b;
+};
+
+foo f1()
+{
+    foo x = { 1, 2 };
+    return x;
+}
+
+
diff --git a/gcc/testsuite/g++.dg/vartrace-ret2.C b/gcc/testsuite/g++.dg/vartrace-ret2.C
new file mode 100644
index 00000000000..56842d75fb6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vartrace-ret2.C
@@ -0,0 +1,24 @@ 
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-O2 -mptwrite -fvartrace " } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+typedef int a;
+enum b
+{ };
+struct ac
+{
+  a operator () (a, a, a, a, a, a);
+};
+struct c
+{
+  ac ag;
+} extern ai[];
+a d;
+void
+l (a e)
+{
+  b f;
+  a g, h, i, j, k;
+  e = d;
+  ai[f].ag (e, g, h, i, j, k);
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-1.c b/gcc/testsuite/gcc.target/i386/vartrace-1.c
new file mode 100644
index 00000000000..ff7a22398b1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-1.c
@@ -0,0 +1,41 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace -fvartrace-locals" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int foo;
+
+extern void f2 (void);
+
+void
+f0 (void)
+{
+  foo += 1;
+}
+
+int
+f3 (int a)
+{
+  return a * 2;
+}
+
+extern void extfunc (int);
+
+int
+f4 (int a, int b)
+{
+  extfunc (a);
+  extfunc (b);
+  return a + b;
+}
+
+void
+f5 (int a)
+{
+}
+
+int
+f (int a, int b)
+{
+  f2 ();
+  return a + b + foo;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-10.c b/gcc/testsuite/gcc.target/i386/vartrace-10.c
new file mode 100644
index 00000000000..37f2ede23ee
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-10.c
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace" } */
+/* { dg-final { scan-assembler-not "ptwrite" } } */
+
+int a __attribute__ ((no_vartrace));
+
+extern void f2 (int);
+
+void
+f (void)
+{
+  f2 (a);
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-11.c b/gcc/testsuite/gcc.target/i386/vartrace-11.c
new file mode 100644
index 00000000000..3ad792fee34
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-11.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+struct foo
+{
+  __attribute__ ((vartrace)) int field;
+};
+
+struct foo a;
+
+int
+f (void)
+{
+  return a.field;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-12.c b/gcc/testsuite/gcc.target/i386/vartrace-12.c
new file mode 100644
index 00000000000..7f721e3beb7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-12.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+struct foo
+{
+  int field;
+} __attribute__ ((vartrace));
+
+struct foo a;
+
+int
+f (void)
+{
+  return a.field;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-13.c b/gcc/testsuite/gcc.target/i386/vartrace-13.c
new file mode 100644
index 00000000000..94802596d72
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-13.c
@@ -0,0 +1,18 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace" } */
+/* { dg-final { scan-assembler-not "ptwrite" } } */
+
+struct foo
+{
+  int field;
+} __attribute__ ((no_vartrace));
+
+struct foo a;
+
+extern void f2 (int);
+
+int
+f (void)
+{
+  f2 (a.field);
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-14.c b/gcc/testsuite/gcc.target/i386/vartrace-14.c
new file mode 100644
index 00000000000..04f3a873bd7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-14.c
@@ -0,0 +1,17 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace" } */
+/* { dg-final { scan-assembler-not "ptwrite" } } */
+
+struct foo 
+{
+  int __attribute__((no_vartrace)) field;
+};
+
+struct foo a;
+
+extern void f2(int);
+
+int f(void)
+{
+	f2(a.field);
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-15.c b/gcc/testsuite/gcc.target/i386/vartrace-15.c
new file mode 100644
index 00000000000..aeadb68c41a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-15.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "-mptwrite -fvartrace" } */
+/* { dg-final { scan-assembler-not "ptwrite" } } */
+
+struct {
+	int __attribute__((vartrace)) x;
+} v;
+
+__attribute__((target("no-ptwrite"))) int f(void)
+{
+	return v.x;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-16.c b/gcc/testsuite/gcc.target/i386/vartrace-16.c
new file mode 100644
index 00000000000..516e9d39950
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-16.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+struct {
+	int __attribute__((vartrace)) x;
+} v;
+
+__attribute__((target("ptwrite"))) int f(void)
+{
+	return v.x;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-17.c b/gcc/testsuite/gcc.target/i386/vartrace-17.c
new file mode 100644
index 00000000000..f051c5bdf00
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-17.c
@@ -0,0 +1,23 @@ 
+/* Test optimization for redundant PTWRITEs */
+/* So far XFAIL because we generate redundant PTWRITEs */
+/* { dg-do compile } */
+/* { dg-options "-fvartrace -mptwrite" } */
+/* { dg-final { scan-assembler-times "ptwrite" 8 { xfail *-*-* } } } */
+
+int read_locals(int a, int b)
+{
+	return a+b;
+}
+
+int x;
+
+int global(int a)
+{
+	x += a;
+	return x + a;
+}
+
+int pointer_ref(int *f)
+{
+	return *f++;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-2.c b/gcc/testsuite/gcc.target/i386/vartrace-2.c
new file mode 100644
index 00000000000..1386d58a450
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-2.c
@@ -0,0 +1,9 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace-args" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int
+f (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-3.c b/gcc/testsuite/gcc.target/i386/vartrace-3.c
new file mode 100644
index 00000000000..0029660f284
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-3.c
@@ -0,0 +1,9 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace-returns" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int
+f (int a)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-4.c b/gcc/testsuite/gcc.target/i386/vartrace-4.c
new file mode 100644
index 00000000000..aa09d14d49e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-4.c
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace-reads" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int a;
+
+extern void f2 (int);
+
+int
+f (void)
+{
+  f2 (a);
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-5.c b/gcc/testsuite/gcc.target/i386/vartrace-5.c
new file mode 100644
index 00000000000..7d7e90d3ead
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-5.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace-writes" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int a;
+
+void
+f (void)
+{
+  a++;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-6.c b/gcc/testsuite/gcc.target/i386/vartrace-6.c
new file mode 100644
index 00000000000..86b8a06ab64
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-6.c
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace-reads -fvartrace-locals" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+extern void f2 (void);
+
+void
+f (void)
+{
+  int i;
+  for (i = 0; i < 10; i++)
+    f2 ();
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-7.c b/gcc/testsuite/gcc.target/i386/vartrace-7.c
new file mode 100644
index 00000000000..99269d70a75
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-7.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int a __attribute__ ((vartrace));
+
+int
+f (void)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-8.c b/gcc/testsuite/gcc.target/i386/vartrace-8.c
new file mode 100644
index 00000000000..ceef61944ea
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-8.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite" } */
+/* { dg-final { scan-assembler "ptwrite" } } */
+
+int a;
+
+__attribute__ ((vartrace))
+     int f (void)
+{
+  return a;
+}
diff --git a/gcc/testsuite/gcc.target/i386/vartrace-9.c b/gcc/testsuite/gcc.target/i386/vartrace-9.c
new file mode 100644
index 00000000000..f2eb2c373d6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vartrace-9.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mptwrite -fvartrace" } */
+/* { dg-final { scan-assembler-not "ptwrite" } } */
+
+int a;
+
+__attribute__ ((no_vartrace))
+     int f (void)
+{
+  return a;
+}
diff --git a/gcc/tree-vartrace.c b/gcc/tree-vartrace.c
index 53b2740cc02..e368492f994 100644
--- a/gcc/tree-vartrace.c
+++ b/gcc/tree-vartrace.c
@@ -239,9 +239,10 @@  bool instrument_args (function *fun, bool force)
 	  if (!func)
 	    continue;
 
-	  tree sarg = ssa_default_def (fun, arg);
-	  /* This can happen with tail recursion. Don't log in this
-	     case for now.  */
+	  tree sarg = NULL;
+	  // ??? or force like sanopt?
+	  if (is_gimple_reg (arg))
+	    sarg = get_or_create_ssa_default_def (fun, arg);
 	  if (!sarg)
 	    continue;