aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/mem2reg
diff options
Diffstat (limited to 'validation/mem2reg')
-rw-r--r--validation/mem2reg/address-used00.c19
-rw-r--r--validation/mem2reg/broken-phi02.c28
-rw-r--r--validation/mem2reg/broken-phi03.c29
-rw-r--r--validation/mem2reg/cond-expr.c13
-rw-r--r--validation/mem2reg/cond-expr5.c18
-rw-r--r--validation/mem2reg/global-direct-undef.c23
-rw-r--r--validation/mem2reg/global-direct.c23
-rw-r--r--validation/mem2reg/global-loop.c20
-rw-r--r--validation/mem2reg/global-noalias.c21
-rw-r--r--validation/mem2reg/global-pointer.c26
-rw-r--r--validation/mem2reg/if-direct.c19
-rw-r--r--validation/mem2reg/if-pointer.c21
-rw-r--r--validation/mem2reg/init-global-array.c17
-rw-r--r--validation/mem2reg/init-local-array.c25
-rw-r--r--validation/mem2reg/init-local-union0.c18
-rw-r--r--validation/mem2reg/init-local-union1.c32
-rw-r--r--validation/mem2reg/init-local.c27
-rw-r--r--validation/mem2reg/loop00.c16
-rw-r--r--validation/mem2reg/loop01-global.c18
-rw-r--r--validation/mem2reg/loop02-array.c23
-rw-r--r--validation/mem2reg/loop02-global.c22
-rw-r--r--validation/mem2reg/loop02-local.c23
-rw-r--r--validation/mem2reg/loop02-pointer.c23
-rw-r--r--validation/mem2reg/quadra00.c28
-rw-r--r--validation/mem2reg/short-load.c29
-rw-r--r--validation/mem2reg/undef00.c14
-rw-r--r--validation/mem2reg/volatile-store00.c27
27 files changed, 602 insertions, 0 deletions
diff --git a/validation/mem2reg/address-used00.c b/validation/mem2reg/address-used00.c
new file mode 100644
index 00000000..f2d6c87b
--- /dev/null
+++ b/validation/mem2reg/address-used00.c
@@ -0,0 +1,19 @@
+int foo(int **g, int j)
+{
+ int i = 1;
+ int *a;
+ int **p;
+
+ a = &i;
+ p = &a;
+ *p[0] = 0;
+ return i;
+}
+
+/*
+ * check-name: address-used00
+ * check-command: test-linearize -Wno-decl -fdump-ir=final $file
+ * check-known-to-fail
+ * check-output-ignore
+ * check-output-excludes: ret\\..* \\$1
+ */
diff --git a/validation/mem2reg/broken-phi02.c b/validation/mem2reg/broken-phi02.c
new file mode 100644
index 00000000..69776e0f
--- /dev/null
+++ b/validation/mem2reg/broken-phi02.c
@@ -0,0 +1,28 @@
+int foo(int a, int b)
+{
+ int x;
+ int i;
+
+ if (a)
+ i = 0;
+ else
+ i = 1;
+
+ x = 0;
+ if (b)
+ x = i;
+ return x;
+}
+
+/*
+ * check-name: broken-phi02
+ * check-description:
+ * This is an indirect test to check correctness of phi-node placement.
+ * The misplaced phi-node for 'i' (not at the meet point but where 'i'
+ * is used) causes a missed select-conversion at later stage.
+ *
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ * check-output-ignore
+ * check-output-contains: select\\.
+ */
diff --git a/validation/mem2reg/broken-phi03.c b/validation/mem2reg/broken-phi03.c
new file mode 100644
index 00000000..58b47979
--- /dev/null
+++ b/validation/mem2reg/broken-phi03.c
@@ -0,0 +1,29 @@
+int foo(int a, int b)
+{
+ int x;
+ int i;
+
+ switch (a) {
+ case 0: i = 0; break;
+ case 1: i = 1; break;
+ default: i = -1; break;
+ }
+
+ x = 0;
+ if (b)
+ x = i;
+ return x;
+}
+
+/*
+ * check-name: broken-phi03
+ * check-description:
+ * This is an indirect test to check correctness of phi-node placement.
+ * The misplaced phi-node for 'i' (not at the meet point but where 'i'
+ * is used) causes a missed select-conversion at later stage.
+ *
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ * check-output-ignore
+ * check-output-contains: select\\.
+ */
diff --git a/validation/mem2reg/cond-expr.c b/validation/mem2reg/cond-expr.c
new file mode 100644
index 00000000..f38564ef
--- /dev/null
+++ b/validation/mem2reg/cond-expr.c
@@ -0,0 +1,13 @@
+int fun(int);
+
+int foo(int a, int b, int c)
+{
+ return a ? fun(b) : fun(c);
+}
+
+/*
+ * check-name: cond-expr
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(2): phi\\.
+ */
diff --git a/validation/mem2reg/cond-expr5.c b/validation/mem2reg/cond-expr5.c
new file mode 100644
index 00000000..6c1e1c34
--- /dev/null
+++ b/validation/mem2reg/cond-expr5.c
@@ -0,0 +1,18 @@
+int foo(int p, int q, int a)
+{
+ if (p)
+ a = 0;
+ if (q)
+ a = 1;
+
+ return a;
+}
+
+/*
+ * check-name: cond-expr5
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ * check-output-excludes: store\\.
+ * check-output-pattern(2): phi\\.
+ */
diff --git a/validation/mem2reg/global-direct-undef.c b/validation/mem2reg/global-direct-undef.c
new file mode 100644
index 00000000..34960e74
--- /dev/null
+++ b/validation/mem2reg/global-direct-undef.c
@@ -0,0 +1,23 @@
+int a, c, d;
+
+int foo(void)
+{
+ int b, e;
+ if (a)
+ b = c;
+ else
+ b = d;
+ if (c)
+ a = b;
+ if (b)
+ e = a;
+ return e;
+}
+
+/*
+ * check-name: global direct undef
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(4,5): load\\.
+ * check-output-pattern(1): store\\.
+ */
diff --git a/validation/mem2reg/global-direct.c b/validation/mem2reg/global-direct.c
new file mode 100644
index 00000000..ea5d42dc
--- /dev/null
+++ b/validation/mem2reg/global-direct.c
@@ -0,0 +1,23 @@
+int a, c, d;
+
+int foo(void)
+{
+ int b, e = 0;
+ if (a)
+ b = c;
+ else
+ b = d;
+ if (c)
+ a = b;
+ if (b)
+ e = a;
+ return e;
+}
+
+/*
+ * check-name: global direct
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(4,5): load\\.
+ * check-output-pattern(1): store\\.
+ */
diff --git a/validation/mem2reg/global-loop.c b/validation/mem2reg/global-loop.c
new file mode 100644
index 00000000..a232f7ed
--- /dev/null
+++ b/validation/mem2reg/global-loop.c
@@ -0,0 +1,20 @@
+struct s {
+ int c;
+ int a[];
+} s;
+int f;
+
+void fun(void);
+void foo(void)
+{
+ for (f = 1;;)
+ if (s.a[f])
+ fun();
+}
+
+/*
+ * check-name: global var as loop index
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-contains: load\\..*\\[f\\]
+ */
diff --git a/validation/mem2reg/global-noalias.c b/validation/mem2reg/global-noalias.c
new file mode 100644
index 00000000..b78b5117
--- /dev/null
+++ b/validation/mem2reg/global-noalias.c
@@ -0,0 +1,21 @@
+int a, b, c, d, e;
+
+void foo(void)
+{
+ if (a)
+ b = c;
+ else
+ b = d;
+ if (c)
+ a = b;
+ if (b)
+ e = a;
+}
+
+/*
+ * check-name: global no-alias
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(4,7): load\\.
+ * check-output-pattern(4): store\\.
+ */
diff --git a/validation/mem2reg/global-pointer.c b/validation/mem2reg/global-pointer.c
new file mode 100644
index 00000000..d312577a
--- /dev/null
+++ b/validation/mem2reg/global-pointer.c
@@ -0,0 +1,26 @@
+int a, c, d;
+
+int foo_ptr(void)
+{
+ int b, *bp = &b;
+ int e, *ep = &e;
+
+ if (a)
+ *bp = c;
+ else
+ *bp = d;
+ if (c)
+ a = *bp;
+ if (b)
+ e = a;
+ return e;
+}
+
+/*
+ * check-name: global pointer
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-known-to-fail
+ * check-output-ignore
+ * check-output-pattern(4,5): load\\.
+ * check-output-pattern(3): store\\.
+ */
diff --git a/validation/mem2reg/if-direct.c b/validation/mem2reg/if-direct.c
new file mode 100644
index 00000000..1b5a07cc
--- /dev/null
+++ b/validation/mem2reg/if-direct.c
@@ -0,0 +1,19 @@
+int foo(int c, int a, int b)
+{
+ int l;
+
+ if (c)
+ l = a;
+ else
+ l = b;
+
+ return l;
+}
+
+/*
+ * check-name: if-then-else direct
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ * check-output-contains: phi\\.
+ */
diff --git a/validation/mem2reg/if-pointer.c b/validation/mem2reg/if-pointer.c
new file mode 100644
index 00000000..acfceb71
--- /dev/null
+++ b/validation/mem2reg/if-pointer.c
@@ -0,0 +1,21 @@
+int foo(int c, int a, int b)
+{
+ int l, *p = &l;
+
+ if (c)
+ *p = a;
+ else
+ *p = b;
+
+ return l + *p;
+}
+
+/*
+ * check-name: if-then-else pointer
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-known-to-fail
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ * check-output-excludes: store\\.
+ * check-output-contains: phi\\.
+ */
diff --git a/validation/mem2reg/init-global-array.c b/validation/mem2reg/init-global-array.c
new file mode 100644
index 00000000..aea4135a
--- /dev/null
+++ b/validation/mem2reg/init-global-array.c
@@ -0,0 +1,17 @@
+struct {
+ int a[2];
+} s;
+
+int sarray(void)
+{
+ s.a[1] = 1;
+ return s.a[1];
+}
+
+/*
+ * check-name: init global array
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ * check-output-pattern(1): store\\.
+ */
diff --git a/validation/mem2reg/init-local-array.c b/validation/mem2reg/init-local-array.c
new file mode 100644
index 00000000..2ac53bc7
--- /dev/null
+++ b/validation/mem2reg/init-local-array.c
@@ -0,0 +1,25 @@
+int array(void)
+{
+ int a[2];
+
+ a[1] = 1;
+ return a[1];
+}
+
+int sarray(void)
+{
+ struct {
+ int a[2];
+ } s;
+
+ s.a[1] = 1;
+ return s.a[1];
+}
+
+/*
+ * check-name: init local array
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ * check-output-excludes: store\\.
+ */
diff --git a/validation/mem2reg/init-local-union0.c b/validation/mem2reg/init-local-union0.c
new file mode 100644
index 00000000..3a57e781
--- /dev/null
+++ b/validation/mem2reg/init-local-union0.c
@@ -0,0 +1,18 @@
+double uintfloat(void)
+{
+ union {
+ int a;
+ double f;
+ } s;
+
+ s.a = 1;
+ return s.f;
+}
+
+/*
+ * check-name: init-local union 0
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(1): store\\.32
+ * check-output-pattern(1): load\\.64
+ */
diff --git a/validation/mem2reg/init-local-union1.c b/validation/mem2reg/init-local-union1.c
new file mode 100644
index 00000000..925b0a73
--- /dev/null
+++ b/validation/mem2reg/init-local-union1.c
@@ -0,0 +1,32 @@
+double uintfloat(void)
+{
+ union {
+ int a;
+ double f;
+ } s;
+
+ s.a = 1;
+ return s.f;
+}
+
+
+int uarray(void)
+{
+ union {
+ double d;
+ int a[2];
+ } s;
+
+ s.d = 1;
+ return s.a[0];
+}
+
+/*
+ * check-name: init-local union 1
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(1): store\\.32
+ * check-output-pattern(1): load\\.64
+ * check-output-pattern(1): store\\.64
+ * check-output-pattern(1): load\\.32
+ */
diff --git a/validation/mem2reg/init-local.c b/validation/mem2reg/init-local.c
new file mode 100644
index 00000000..d51c9247
--- /dev/null
+++ b/validation/mem2reg/init-local.c
@@ -0,0 +1,27 @@
+int ssimple(void)
+{
+ struct {
+ int a;
+ } s;
+
+ s.a = 1;
+ return s.a;
+}
+
+double sdouble(void)
+{
+ struct {
+ double a;
+ } s;
+
+ s.a = 1.23;
+ return s.a;
+}
+
+/*
+ * check-name: init-local
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ * check-output-excludes: store\\.
+ */
diff --git a/validation/mem2reg/loop00.c b/validation/mem2reg/loop00.c
new file mode 100644
index 00000000..de33d9f6
--- /dev/null
+++ b/validation/mem2reg/loop00.c
@@ -0,0 +1,16 @@
+int loop00(int n)
+{
+ int i, r = 0;
+
+ for (i = 1; i <= n; ++i)
+ r += i;
+ return r;
+}
+
+/*
+ * check-name: loop00
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: store\\.
+ * check-output-excludes: load\\.
+ */
diff --git a/validation/mem2reg/loop01-global.c b/validation/mem2reg/loop01-global.c
new file mode 100644
index 00000000..b6798137
--- /dev/null
+++ b/validation/mem2reg/loop01-global.c
@@ -0,0 +1,18 @@
+extern int g;
+
+void fun(void);
+void loop01(void)
+{
+ int i;
+ for (i = 0; i <= 2;)
+ if (g)
+ fun();
+}
+
+/*
+ * check-name: loop01 global
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: load\\..*\\[i\\]
+ * check-output-contains: load\\..*\\[g\\]
+ */
diff --git a/validation/mem2reg/loop02-array.c b/validation/mem2reg/loop02-array.c
new file mode 100644
index 00000000..13b0aeaf
--- /dev/null
+++ b/validation/mem2reg/loop02-array.c
@@ -0,0 +1,23 @@
+
+
+int foo(int i[])
+{
+ int j = 1;
+ i[0] = 6;
+
+ do {
+ if (i[0] != 6)
+ i[0]++;
+ i[0]++;
+ } while (i[0] != j);
+
+ return j;
+}
+
+/*
+ * check-name: loop02 array
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(0,4): load\\.
+ * check-output-pattern(1,3): store\\.
+ */
diff --git a/validation/mem2reg/loop02-global.c b/validation/mem2reg/loop02-global.c
new file mode 100644
index 00000000..a0a8b42b
--- /dev/null
+++ b/validation/mem2reg/loop02-global.c
@@ -0,0 +1,22 @@
+int i;
+
+int foo(void)
+{
+ int j = 1;
+ i = 6;
+
+ do {
+ if (i != 6)
+ i++;
+ i++;
+ } while (i != j);
+
+ return j;
+}
+
+/*
+ * check-name: loop02 global
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ */
diff --git a/validation/mem2reg/loop02-local.c b/validation/mem2reg/loop02-local.c
new file mode 100644
index 00000000..a1bd602b
--- /dev/null
+++ b/validation/mem2reg/loop02-local.c
@@ -0,0 +1,23 @@
+
+
+int foo(void)
+{
+ int j = 1;
+ int i = 6;
+
+ do {
+ if (i != 6)
+ i++;
+ i++;
+ } while (i != j);
+
+ return j;
+}
+
+/*
+ * check-name: loop02 pointer
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ *
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ */
diff --git a/validation/mem2reg/loop02-pointer.c b/validation/mem2reg/loop02-pointer.c
new file mode 100644
index 00000000..fdb0a8fb
--- /dev/null
+++ b/validation/mem2reg/loop02-pointer.c
@@ -0,0 +1,23 @@
+
+
+int foo(int *i)
+{
+ int j = 1;
+ *i = 6;
+
+ do {
+ if (*i != 6)
+ (*i)++;
+ (*i)++;
+ } while (*i != j);
+
+ return j;
+}
+
+/*
+ * check-name: loop02 pointer
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(0,4): load\\.
+ * check-output-pattern(1,3): store\\.
+ */
diff --git a/validation/mem2reg/quadra00.c b/validation/mem2reg/quadra00.c
new file mode 100644
index 00000000..63b489c9
--- /dev/null
+++ b/validation/mem2reg/quadra00.c
@@ -0,0 +1,28 @@
+#define TEST(N) \
+ do { \
+ d = b + a[N]; \
+ if (d < b) \
+ c++; \
+ b = d; \
+ } while (0)
+
+int foo(int *a, int b, int c)
+{
+ int d;
+
+ TEST(0);
+ TEST(1);
+ TEST(2);
+
+ return d + c;
+}
+
+/*
+ * check-name: quadratic phisrc
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ * check-output-ignore
+ * check-output-excludes: phi\\..*, .*, .*
+ * check-output-excludes: phi\\..*, .*, .*, .*
+ * check-output-pattern(6): phisrc\\.
+ */
diff --git a/validation/mem2reg/short-load.c b/validation/mem2reg/short-load.c
new file mode 100644
index 00000000..c4b4dc4b
--- /dev/null
+++ b/validation/mem2reg/short-load.c
@@ -0,0 +1,29 @@
+#ifdef __SIZEOF_INT__ == 4
+typedef unsigned int u32;
+#endif
+#ifdef __SIZEOF_SHORT__ == 2
+typedef unsigned short u16;
+#endif
+
+
+union u {
+ u32 a;
+ u16 b;
+};
+
+void bar(u16, union u);
+
+void foo(u16 val)
+{
+ union u u;
+
+ u.b = val;
+ bar(u.b, u);
+}
+
+/*
+ * check-name: short-load
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-contains: load\\.32
+ */
diff --git a/validation/mem2reg/undef00.c b/validation/mem2reg/undef00.c
new file mode 100644
index 00000000..ba9ba915
--- /dev/null
+++ b/validation/mem2reg/undef00.c
@@ -0,0 +1,14 @@
+void bad0(void)
+{
+ int *a;
+ *a++;
+}
+
+/*
+ * check-name: undef00
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-known-to-fail
+ * check-output-ignore
+ * check-output-pattern(1): load\\.
+ * check-output-pattern(1): load\\..*\\[UNDEF\\]
+ */
diff --git a/validation/mem2reg/volatile-store00.c b/validation/mem2reg/volatile-store00.c
new file mode 100644
index 00000000..d565037a
--- /dev/null
+++ b/validation/mem2reg/volatile-store00.c
@@ -0,0 +1,27 @@
+void foo(volatile int *p)
+{
+ *p = 0;
+ *p = 0;
+}
+
+void bar(void)
+{
+ extern volatile int i;
+ i = 0;
+ i = 0;
+}
+
+
+void baz(void)
+{
+ volatile int i;
+ i = 0;
+ i = 0;
+}
+
+/*
+ * check-name: keep volatile stores
+ * check-command: test-linearize -Wno-decl -fdump-ir=mem2reg $file
+ * check-output-ignore
+ * check-output-pattern(1,6): store\\.
+ */