aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/optim
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-06-26 13:14:44 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-23 13:11:20 +0200
commitde13e2c39b95fe234f86b932e1784512b0ee694c (patch)
treeff0fbfb95d8bed3ccabad8bc5450508939044a35 /validation/optim
parent90cc2706010c1d2eb8cedf0765c95cbb2d5bd38b (diff)
downloadsparse-dev-de13e2c39b95fe234f86b932e1784512b0ee694c.tar.gz
add testcases for casts & bitfield insertion/extraction
There is several difficulties some related to unclear semantic of our IR instructions and/or type evaluation. Add testcases trying to cover this area. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/optim')
-rw-r--r--validation/optim/and-extend.c28
-rw-r--r--validation/optim/and-extendx.c25
-rw-r--r--validation/optim/and-lsr.c16
-rw-r--r--validation/optim/and-trunc.c21
-rw-r--r--validation/optim/ext-trunc-greater.c18
-rw-r--r--validation/optim/ext-trunc-same.c20
-rw-r--r--validation/optim/ext-trunc-smaller.c19
-rw-r--r--validation/optim/mask-lsr.c15
-rw-r--r--validation/optim/mask-out.c13
-rw-r--r--validation/optim/sext-sext.c13
-rw-r--r--validation/optim/sext.c15
-rw-r--r--validation/optim/shift-zext.c13
-rw-r--r--validation/optim/store-load-bitfield.c50
-rw-r--r--validation/optim/trunc-mask-zext.c14
-rw-r--r--validation/optim/zext-and.c13
-rw-r--r--validation/optim/zext-and1.c13
-rw-r--r--validation/optim/zext-sext.c14
-rw-r--r--validation/optim/zext-zext.c14
18 files changed, 334 insertions, 0 deletions
diff --git a/validation/optim/and-extend.c b/validation/optim/and-extend.c
new file mode 100644
index 00000000..fdcf470f
--- /dev/null
+++ b/validation/optim/and-extend.c
@@ -0,0 +1,28 @@
+typedef unsigned short u16;
+typedef short s16;
+typedef unsigned int u32;
+typedef int s32;
+
+u32 ufoo(u32 x)
+{
+ u16 i = ((u16)x) & 0x7fffU;
+ return i;
+}
+
+u32 sfoo(u32 x)
+{
+ s16 i = ((s16)x) & 0x7fff;
+ return i;
+}
+
+/*
+ * check-name: and-extend
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ * check-output-excludes: zext\\.
+ * check-output-excludes: sext\\.
+ * check-output-contains: and\\.32.*0x7fff
+ */
diff --git a/validation/optim/and-extendx.c b/validation/optim/and-extendx.c
new file mode 100644
index 00000000..a580bd0d
--- /dev/null
+++ b/validation/optim/and-extendx.c
@@ -0,0 +1,25 @@
+typedef unsigned short u16;
+typedef short s16;
+typedef unsigned int u32;
+typedef int s32;
+typedef unsigned long long u64;
+typedef long long s64;
+
+u64 ufoo(int x)
+{
+ return x & 0x7fff;
+}
+
+u64 sfoo(int x)
+{
+ return x & 0x7fff;
+}
+
+/*
+ * check-name: and-extend
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\.64.*0x7fff
+ */
diff --git a/validation/optim/and-lsr.c b/validation/optim/and-lsr.c
new file mode 100644
index 00000000..df6b72f3
--- /dev/null
+++ b/validation/optim/and-lsr.c
@@ -0,0 +1,16 @@
+// (x & M) >> S to (x >> S) & (M >> S)
+
+unsigned int foo(unsigned int x)
+{
+ return (x & 0xffff) >> 12;
+}
+
+/*
+ * check-name: and-lsr
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*\\$15
+ * check-output-excludes: and\\..*\\$0xffff
+ */
diff --git a/validation/optim/and-trunc.c b/validation/optim/and-trunc.c
new file mode 100644
index 00000000..bcb80bbe
--- /dev/null
+++ b/validation/optim/and-trunc.c
@@ -0,0 +1,21 @@
+short smask(short x)
+{
+ return x & (short) 0x7fff;
+}
+
+short umask(unsigned short x)
+{
+ return x & (unsigned short) 0x7fff;
+}
+
+/*
+ * check-name: and-trunc
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-excludes: zext\\.
+ * check-output-excludes: trunc\\.
+ * check-output-contains: and\\.16
+ */
diff --git a/validation/optim/ext-trunc-greater.c b/validation/optim/ext-trunc-greater.c
new file mode 100644
index 00000000..bb19e17b
--- /dev/null
+++ b/validation/optim/ext-trunc-greater.c
@@ -0,0 +1,18 @@
+short sgt(char x)
+{
+ return (int) x;
+}
+
+short ugt(unsigned char x)
+{
+ return (int) x;
+}
+
+/*
+ * check-name: ext-trunc-greater
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ */
diff --git a/validation/optim/ext-trunc-same.c b/validation/optim/ext-trunc-same.c
new file mode 100644
index 00000000..634fdb87
--- /dev/null
+++ b/validation/optim/ext-trunc-same.c
@@ -0,0 +1,20 @@
+short seq(short x)
+{
+ return (int) x;
+}
+
+short ueq(unsigned short x)
+{
+ return (int) x;
+}
+
+/*
+ * check-name: ext-trunc-same
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ * check-output-excludes: sext\\.
+ * check-output-excludes: zext\\.
+ */
diff --git a/validation/optim/ext-trunc-smaller.c b/validation/optim/ext-trunc-smaller.c
new file mode 100644
index 00000000..a757a3ad
--- /dev/null
+++ b/validation/optim/ext-trunc-smaller.c
@@ -0,0 +1,19 @@
+char slt(short x)
+{
+ return (int) x;
+}
+
+char ult(unsigned short x)
+{
+ return (int) x;
+}
+
+/*
+ * check-name: ext-trunc-smaller
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-excludes: zext\\.
+ */
diff --git a/validation/optim/mask-lsr.c b/validation/optim/mask-lsr.c
new file mode 100644
index 00000000..1d37c91e
--- /dev/null
+++ b/validation/optim/mask-lsr.c
@@ -0,0 +1,15 @@
+// ((x & M) | y) >> S to (y >> S) when (M >> S) == 0
+
+unsigned int foo(unsigned int x, unsigned int y)
+{
+ return ((x & 0xff) | y) >> 8;
+}
+
+/*
+ * check-name: mask-lsr
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: %arg1
+ */
diff --git a/validation/optim/mask-out.c b/validation/optim/mask-out.c
new file mode 100644
index 00000000..bf116873
--- /dev/null
+++ b/validation/optim/mask-out.c
@@ -0,0 +1,13 @@
+unsigned mask(unsigned a, unsigned b)
+{
+ return ((a & 0xffff0000) | b) & 0x0000ffff;
+}
+
+/*
+ * check-name: mask-out
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: %arg1
+ */
diff --git a/validation/optim/sext-sext.c b/validation/optim/sext-sext.c
new file mode 100644
index 00000000..3f7a0efc
--- /dev/null
+++ b/validation/optim/sext-sext.c
@@ -0,0 +1,13 @@
+int foo(signed char offset)
+{
+ return (int)(short) offset;
+}
+
+/*
+ * check-name: sext-sext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): sext\\.
+ */
diff --git a/validation/optim/sext.c b/validation/optim/sext.c
new file mode 100644
index 00000000..719730d5
--- /dev/null
+++ b/validation/optim/sext.c
@@ -0,0 +1,15 @@
+int sext(int x)
+{
+ return (x << 5) >> 5;
+}
+
+/*
+ * check-name: sext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: sext\\.$27
+ * check-output-excludes: asr\\.
+ * check-output-excludes: shl\\.
+ */
diff --git a/validation/optim/shift-zext.c b/validation/optim/shift-zext.c
new file mode 100644
index 00000000..070416f3
--- /dev/null
+++ b/validation/optim/shift-zext.c
@@ -0,0 +1,13 @@
+unsigned int foo(unsigned int x)
+{
+ return (x << 20) >> 20;
+}
+
+/*
+ * check-name: shift-zext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*%arg1, \\$0xfff
+ */
diff --git a/validation/optim/store-load-bitfield.c b/validation/optim/store-load-bitfield.c
new file mode 100644
index 00000000..1d8ff240
--- /dev/null
+++ b/validation/optim/store-load-bitfield.c
@@ -0,0 +1,50 @@
+int ufoo(unsigned int a)
+{
+ struct u {
+ unsigned int :2;
+ unsigned int a:3;
+ } bf;
+
+ bf.a = a;
+ return bf.a;
+}
+
+int sfoo(int a)
+{
+ struct s {
+ signed int :2;
+ signed int a:3;
+ } bf;
+
+ bf.a = a;
+ return bf.a;
+}
+
+/*
+ * check-name: optim store/load bitfields
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+ufoo:
+.L0:
+ <entry-point>
+ and.32 %r4 <- %arg1, $7
+ shl.32 %r5 <- %r4, $2
+ lsr.32 %r9 <- %r5, $2
+ and.32 %r11 <- %r9, $7
+ ret.32 %r11
+
+
+sfoo:
+.L2:
+ <entry-point>
+ and.32 %r16 <- %arg1, $7
+ shl.32 %r17 <- %r16, $2
+ lsr.32 %r21 <- %r17, $2
+ trunc.3 %r22 <- (32) %r21
+ sext.32 %r23 <- (3) %r22
+ ret.32 %r23
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/trunc-mask-zext.c b/validation/optim/trunc-mask-zext.c
new file mode 100644
index 00000000..30ae5aee
--- /dev/null
+++ b/validation/optim/trunc-mask-zext.c
@@ -0,0 +1,14 @@
+unsigned long long foo(unsigned long long x)
+{
+ return (((unsigned int) x) & 0x7ffU);
+}
+
+/*
+ * check-name: trunc-mask-zext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ * check-output-excludes: zext\\.
+ */
diff --git a/validation/optim/zext-and.c b/validation/optim/zext-and.c
new file mode 100644
index 00000000..2f4f3c80
--- /dev/null
+++ b/validation/optim/zext-and.c
@@ -0,0 +1,13 @@
+unsigned int foo(unsigned char x)
+{
+ return (unsigned int)x & 0xffffU;
+}
+
+/*
+ * check-name: zext-and
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: and\\.
+ */
diff --git a/validation/optim/zext-and1.c b/validation/optim/zext-and1.c
new file mode 100644
index 00000000..2ad01103
--- /dev/null
+++ b/validation/optim/zext-and1.c
@@ -0,0 +1,13 @@
+unsigned int bar(unsigned char x)
+{
+ return (unsigned int)x & 0xff01U;
+}
+
+/*
+ * check-name: zext-and1
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*\\$1
+ */
diff --git a/validation/optim/zext-sext.c b/validation/optim/zext-sext.c
new file mode 100644
index 00000000..b0964b54
--- /dev/null
+++ b/validation/optim/zext-sext.c
@@ -0,0 +1,14 @@
+int foo(unsigned char offset)
+{
+ return (int)(short) offset;
+}
+
+/*
+ * check-name: zext-sext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-pattern(1): zext\\.
+ */
diff --git a/validation/optim/zext-zext.c b/validation/optim/zext-zext.c
new file mode 100644
index 00000000..b88a6cca
--- /dev/null
+++ b/validation/optim/zext-zext.c
@@ -0,0 +1,14 @@
+int foo(unsigned char offset)
+{
+ return (int)(unsigned short) offset;
+}
+
+/*
+ * check-name: zext-zext
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-pattern(1): zext\\.
+ */