aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-25 18:48:32 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-25 20:58:09 +0200
commitd0d63eb6c186fe6c37fb8a1061392512047ebaca (patch)
tree044a12a5b3cff17175b795f4d279bd8c10298c52 /validation
parent7bd897d350147a040d2f1e88b9042884697676b5 (diff)
parentbb97ff365b6f0cbcd8ee4057ee45925094d8101d (diff)
downloadsparse-dev-d0d63eb6c186fe6c37fb8a1061392512047ebaca.tar.gz
Merge branch 'optim-cast' into tip
* several simplifications involving casts and/or bitfields Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/linear/bitfield-inc.c17
-rw-r--r--validation/linear/bitfield-preinc.c18
-rw-r--r--validation/linear/bitfield-store.c22
-rw-r--r--validation/optim/and-extend.c27
-rw-r--r--validation/optim/and-extendx.c24
-rw-r--r--validation/optim/and-lsr.c16
-rw-r--r--validation/optim/and-trunc.c20
-rw-r--r--validation/optim/ext-trunc-greater.c17
-rw-r--r--validation/optim/ext-trunc-same.c19
-rw-r--r--validation/optim/ext-trunc-smaller.c18
-rw-r--r--validation/optim/mask-lsr.c15
-rw-r--r--validation/optim/mask-out.c13
-rw-r--r--validation/optim/sext-sext.c12
-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.c13
-rw-r--r--validation/optim/zext-and.c12
-rw-r--r--validation/optim/zext-and1.c12
-rw-r--r--validation/optim/zext-sext.c13
-rw-r--r--validation/optim/zext-zext.c13
21 files changed, 379 insertions, 0 deletions
diff --git a/validation/linear/bitfield-inc.c b/validation/linear/bitfield-inc.c
new file mode 100644
index 00000000..ed8efe7d
--- /dev/null
+++ b/validation/linear/bitfield-inc.c
@@ -0,0 +1,17 @@
+struct s {
+ int f:5;
+};
+
+void inc(struct s *p)
+{
+ p->f++;
+}
+
+/*
+ * check-name: bitfield-inc
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: add\\.5
+ */
diff --git a/validation/linear/bitfield-preinc.c b/validation/linear/bitfield-preinc.c
new file mode 100644
index 00000000..783327ae
--- /dev/null
+++ b/validation/linear/bitfield-preinc.c
@@ -0,0 +1,18 @@
+struct s {
+ int f:3;
+};
+
+int preinc(void)
+{
+ struct s s = { 7 };
+ return ++s.f;
+}
+
+/*
+ * check-name: bitfield-preinc
+ * check-description: ++X is equivalent to X+=1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret.32 *\\$0
+ */
diff --git a/validation/linear/bitfield-store.c b/validation/linear/bitfield-store.c
new file mode 100644
index 00000000..3d952c8d
--- /dev/null
+++ b/validation/linear/bitfield-store.c
@@ -0,0 +1,22 @@
+int foo(void)
+{
+ struct {
+ int a:8;
+ int b:16;
+ int c:8;
+ } s = { 0xff, 0x0000, 0xff };
+
+ return s.b = 0x56781234;
+}
+
+/*
+ * check-name: bitfield-store
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0x1234
+ *
+ * check-error-start
+linear/bitfield-store.c:9:22: warning: cast truncates bits from constant value (56781234 becomes 1234)
+ * check-error-end
+ */
diff --git a/validation/optim/and-extend.c b/validation/optim/and-extend.c
new file mode 100644
index 00000000..eb589236
--- /dev/null
+++ b/validation/optim/and-extend.c
@@ -0,0 +1,27 @@
+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-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..5c181c93
--- /dev/null
+++ b/validation/optim/and-extendx.c
@@ -0,0 +1,24 @@
+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-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..df1e4d03
--- /dev/null
+++ b/validation/optim/and-trunc.c
@@ -0,0 +1,20 @@
+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-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..b682fc5d
--- /dev/null
+++ b/validation/optim/ext-trunc-greater.c
@@ -0,0 +1,17 @@
+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-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..2bfcf030
--- /dev/null
+++ b/validation/optim/ext-trunc-same.c
@@ -0,0 +1,19 @@
+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-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..194c98d7
--- /dev/null
+++ b/validation/optim/ext-trunc-smaller.c
@@ -0,0 +1,18 @@
+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-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..604a7dd4
--- /dev/null
+++ b/validation/optim/sext-sext.c
@@ -0,0 +1,12 @@
+int foo(signed char offset)
+{
+ return (int)(short) offset;
+}
+
+/*
+ * check-name: sext-sext
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * 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..9b604174
--- /dev/null
+++ b/validation/optim/trunc-mask-zext.c
@@ -0,0 +1,13 @@
+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-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..a3153bf7
--- /dev/null
+++ b/validation/optim/zext-and.c
@@ -0,0 +1,12 @@
+unsigned int foo(unsigned char x)
+{
+ return (unsigned int)x & 0xffffU;
+}
+
+/*
+ * check-name: zext-and
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * 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..c99a0e62
--- /dev/null
+++ b/validation/optim/zext-and1.c
@@ -0,0 +1,12 @@
+unsigned int bar(unsigned char x)
+{
+ return (unsigned int)x & 0xff01U;
+}
+
+/*
+ * check-name: zext-and1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * 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..1fe3900d
--- /dev/null
+++ b/validation/optim/zext-sext.c
@@ -0,0 +1,13 @@
+int foo(unsigned char offset)
+{
+ return (int)(short) offset;
+}
+
+/*
+ * check-name: zext-sext
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * 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..986d2242
--- /dev/null
+++ b/validation/optim/zext-zext.c
@@ -0,0 +1,13 @@
+int foo(unsigned char offset)
+{
+ return (int)(unsigned short) offset;
+}
+
+/*
+ * check-name: zext-zext
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ * check-output-pattern(1): zext\\.
+ */