aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/optim
diff options
Diffstat (limited to 'validation/optim')
-rw-r--r--validation/optim/and-extend.c27
-rw-r--r--validation/optim/and-extendx.c24
-rw-r--r--validation/optim/and-lsr.c15
-rw-r--r--validation/optim/and-or-bf0.c24
-rw-r--r--validation/optim/and-or-bf1.c18
-rw-r--r--validation/optim/and-or-bf2.c27
-rw-r--r--validation/optim/and-or-bfs.c23
-rw-r--r--validation/optim/and-or-bfu.c21
-rw-r--r--validation/optim/and-or-bfx.c18
-rw-r--r--validation/optim/and-or-constant0.c12
-rw-r--r--validation/optim/and-or-constant1.c14
-rw-r--r--validation/optim/and-or-constant2.c13
-rw-r--r--validation/optim/and-or-crash.c5
-rw-r--r--validation/optim/and-or-lsr0.c13
-rw-r--r--validation/optim/and-or-lsr1.c13
-rw-r--r--validation/optim/and-or-lsr2.c13
-rw-r--r--validation/optim/and-or-lsrx.c13
-rw-r--r--validation/optim/and-or-mask.c18
-rw-r--r--validation/optim/and-or-mask0.c12
-rw-r--r--validation/optim/and-or-mask1.c13
-rw-r--r--validation/optim/and-or-mask2.c13
-rw-r--r--validation/optim/and-or-mask3s.c25
-rw-r--r--validation/optim/and-or-mask3u.c25
-rw-r--r--validation/optim/and-or-mask4.c25
-rw-r--r--validation/optim/and-or-maskx.c13
-rw-r--r--validation/optim/and-or-shl0.c12
-rw-r--r--validation/optim/and-or-shl1.c13
-rw-r--r--validation/optim/and-or-shl2.c13
-rw-r--r--validation/optim/and-or-shlx.c13
-rw-r--r--validation/optim/and-or-trunc0.c13
-rw-r--r--validation/optim/and-or-trunc1.c12
-rw-r--r--validation/optim/and-or-trunc2.c13
-rw-r--r--validation/optim/and-or-truncx.c13
-rw-r--r--validation/optim/and-trunc.c20
-rw-r--r--validation/optim/bitfield-store-load0.c44
-rw-r--r--validation/optim/bitfield-store-loads.c23
-rw-r--r--validation/optim/bitfield-store-loadu.c21
-rw-r--r--validation/optim/bool-context-fp.c22
-rw-r--r--validation/optim/bool-sext-test.c12
-rw-r--r--validation/optim/bool-simplify.c15
-rw-r--r--validation/optim/bool-simplify2.c50
-rw-r--r--validation/optim/bool-zext-test.c12
-rw-r--r--validation/optim/call-inlined.c4
-rw-r--r--validation/optim/cast-kinds.c397
-rw-r--r--validation/optim/cast-nop.c18
-rw-r--r--validation/optim/cse-cmp-next.c15
-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/lsr-and0.c13
-rw-r--r--validation/optim/lsr-and1.c18
-rw-r--r--validation/optim/lsr-asr.c42
-rw-r--r--validation/optim/lsr-shl0.c14
-rw-r--r--validation/optim/mask-lsr.c14
-rw-r--r--validation/optim/mask-out.c12
-rw-r--r--validation/optim/mask1-setne0.c28
-rw-r--r--validation/optim/or-and-constant1.c29
-rw-r--r--validation/optim/setcc-mask.c18
-rw-r--r--validation/optim/setne0-sext.c9
-rw-r--r--validation/optim/setne0-trunc.c9
-rw-r--r--validation/optim/setne0-zext.c9
-rw-r--r--validation/optim/sext-sext.c12
-rw-r--r--validation/optim/sext.c15
-rw-r--r--validation/optim/sh-or-and0.c20
-rw-r--r--validation/optim/sh-or-and1.c20
-rw-r--r--validation/optim/sh-or-and2.c21
-rw-r--r--validation/optim/shift-big.c82
-rw-r--r--validation/optim/shift-shift.c149
-rw-r--r--validation/optim/shift-zext.c12
-rw-r--r--validation/optim/shl-and0.c13
-rw-r--r--validation/optim/shl-and1.c18
-rw-r--r--validation/optim/shl-lsr0.c14
-rw-r--r--validation/optim/trunc-mask-zext.c13
-rw-r--r--validation/optim/trunc-or-shl.c13
-rw-r--r--validation/optim/trunc-seteq0.c18
-rw-r--r--validation/optim/trunc-setne0.c20
-rw-r--r--validation/optim/trunc-trunc.c12
-rw-r--r--validation/optim/zext-and.c12
-rw-r--r--validation/optim/zext-and1.c12
-rw-r--r--validation/optim/zext-asr.c13
-rw-r--r--validation/optim/zext-sext.c13
-rw-r--r--validation/optim/zext-zext.c13
82 files changed, 1920 insertions, 56 deletions
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..439eb822
--- /dev/null
+++ b/validation/optim/and-lsr.c
@@ -0,0 +1,15 @@
+// (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-output-ignore
+ * check-output-contains: and\\..*\\$15
+ * check-output-excludes: and\\..*\\$0xffff
+ */
diff --git a/validation/optim/and-or-bf0.c b/validation/optim/and-or-bf0.c
new file mode 100644
index 00000000..cfaff4f2
--- /dev/null
+++ b/validation/optim/and-or-bf0.c
@@ -0,0 +1,24 @@
+struct s {
+ int f:3;
+};
+
+void foo(struct s *p, int a)
+{
+ p->f = 1;
+ p->f = a;
+}
+
+void bar(struct s *p, int a)
+{
+ p->f = a;
+ p->f = 1;
+}
+
+/*
+ * check-name: and-or-bf0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(3): and\\.
+ * check-output-pattern(2): or\\.
+ */
diff --git a/validation/optim/and-or-bf1.c b/validation/optim/and-or-bf1.c
new file mode 100644
index 00000000..23477ff3
--- /dev/null
+++ b/validation/optim/and-or-bf1.c
@@ -0,0 +1,18 @@
+struct s {
+ int :2;
+ int f:3;
+};
+
+void foo(struct s *d, const struct s *s, int a)
+{
+ d->f = s->f | a;
+}
+
+/*
+ * check-name: and-or-bf1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(2): and\\.
+ * check-output-pattern(2): or\\.
+ */
diff --git a/validation/optim/and-or-bf2.c b/validation/optim/and-or-bf2.c
new file mode 100644
index 00000000..2296da12
--- /dev/null
+++ b/validation/optim/and-or-bf2.c
@@ -0,0 +1,27 @@
+struct s {
+ char a:3;
+ char b:3;
+ char c:2;
+};
+
+void foo(struct s *p)
+{
+ p->a = 1;
+ p->b = 2;
+ p->c = 3;
+}
+
+/*
+ * check-name: and-or-bf2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ store.8 $209 -> 0[%arg1]
+ ret
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/and-or-bfs.c b/validation/optim/and-or-bfs.c
new file mode 100644
index 00000000..f3f33204
--- /dev/null
+++ b/validation/optim/and-or-bfs.c
@@ -0,0 +1,23 @@
+struct s {
+ signed int :2;
+ signed int f:3;
+};
+
+int bfs(struct s s, int a)
+{
+ s.f = a;
+ return s.f;
+}
+
+/*
+ * check-name: and-or-bfs
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): trunc\\.
+ * check-output-pattern(1): sext\\.
+ * check-output-excludes: and\\.
+ * check-output-excludes: or\\.
+ * check-output-excludes: shl\\.
+ * check-output-excludes: lsr\\.
+ */
diff --git a/validation/optim/and-or-bfu.c b/validation/optim/and-or-bfu.c
new file mode 100644
index 00000000..b6a080bd
--- /dev/null
+++ b/validation/optim/and-or-bfu.c
@@ -0,0 +1,21 @@
+struct u {
+ unsigned int :2;
+ unsigned int f:3;
+};
+
+int bfu(struct u s, int a)
+{
+ s.f = a;
+ return s.f;
+}
+
+/*
+ * check-name: and-or-bfu
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): and\\.
+ * check-output-excludes: or\\.
+ * check-output-excludes: shl\\.
+ * check-output-excludes: lsr\\.
+ */
diff --git a/validation/optim/and-or-bfx.c b/validation/optim/and-or-bfx.c
new file mode 100644
index 00000000..57a54cf5
--- /dev/null
+++ b/validation/optim/and-or-bfx.c
@@ -0,0 +1,18 @@
+struct s {
+ int f:3;
+};
+
+void foo(struct s *p, int a, int b)
+{
+ p->f = a;
+ p->f = b;
+}
+
+/*
+ * check-name: and-or-bfx
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(2): and\\.
+ * check-output-pattern(1): or\\.
+ */
diff --git a/validation/optim/and-or-constant0.c b/validation/optim/and-or-constant0.c
new file mode 100644
index 00000000..dcf440f3
--- /dev/null
+++ b/validation/optim/and-or-constant0.c
@@ -0,0 +1,12 @@
+int foo(int x)
+{
+ return (x | 0xfffff000) & 0xfff;
+}
+
+/*
+ * check-name: and-or-constant0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-constant1.c b/validation/optim/and-or-constant1.c
new file mode 100644
index 00000000..49823d5c
--- /dev/null
+++ b/validation/optim/and-or-constant1.c
@@ -0,0 +1,14 @@
+int foo(int x)
+{
+ return (x | 0x000fffff) & 0xfff;
+}
+
+/*
+ * check-name: or-and-constant1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0xfff
+ * check-output-excludes: and\\.
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-constant2.c b/validation/optim/and-or-constant2.c
new file mode 100644
index 00000000..d7e66f9c
--- /dev/null
+++ b/validation/optim/and-or-constant2.c
@@ -0,0 +1,13 @@
+int foo(int x)
+{
+ return (x | 0xfffffff0) & 0xfff;
+}
+
+/*
+ * check-name: and-or-constant2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: or\\..*\\$0xff0
+ * check-output-excludes: or\\..*\\$0xfffffff0
+ */
diff --git a/validation/optim/and-or-crash.c b/validation/optim/and-or-crash.c
new file mode 100644
index 00000000..98a8a9b8
--- /dev/null
+++ b/validation/optim/and-or-crash.c
@@ -0,0 +1,5 @@
+static unsigned a(unsigned b, unsigned c) { (c << 1 | b & 1 << 1) >> 1; }
+
+/*
+ * check-name: catch crashes during AND-OR simplifications
+ */
diff --git a/validation/optim/and-or-lsr0.c b/validation/optim/and-or-lsr0.c
new file mode 100644
index 00000000..227c5aed
--- /dev/null
+++ b/validation/optim/and-or-lsr0.c
@@ -0,0 +1,13 @@
+int foo(int a, int b)
+{
+ return ((a & 0x00000fff) | b) >> 12;
+}
+
+/*
+ * check-name: and-or-lsr0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-lsr1.c b/validation/optim/and-or-lsr1.c
new file mode 100644
index 00000000..bd1dbc8a
--- /dev/null
+++ b/validation/optim/and-or-lsr1.c
@@ -0,0 +1,13 @@
+int foo(int a, int b)
+{
+ return ((a & 0xfffff000) | b) >> 12;
+}
+
+/*
+ * check-name: and-or-lsr1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(0): and\\.
+ * check-output-pattern(1): or\\.
+ */
diff --git a/validation/optim/and-or-lsr2.c b/validation/optim/and-or-lsr2.c
new file mode 100644
index 00000000..d1af0135
--- /dev/null
+++ b/validation/optim/and-or-lsr2.c
@@ -0,0 +1,13 @@
+int foo(int x, int y)
+{
+ return ((x & 0xf0ffffff) | y) >> 12;
+}
+
+/*
+ * check-name: and-or-lsr2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*\\$0xf0fff
+ * check-output-excludes: and\\..*\\$0xf0ffffff
+ */
diff --git a/validation/optim/and-or-lsrx.c b/validation/optim/and-or-lsrx.c
new file mode 100644
index 00000000..31adca92
--- /dev/null
+++ b/validation/optim/and-or-lsrx.c
@@ -0,0 +1,13 @@
+unsigned int foo(unsigned int x, unsigned int y, unsigned int a)
+{
+ return ((x & y) | (a & 0x0fff)) >> 12;
+}
+
+/*
+ * check-name: and-or-lsrx
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): and\\.
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-mask.c b/validation/optim/and-or-mask.c
new file mode 100644
index 00000000..46803789
--- /dev/null
+++ b/validation/optim/and-or-mask.c
@@ -0,0 +1,18 @@
+int foo(int a, int b)
+{
+ return ((a & 7) | (b & 3)) & 8;
+}
+
+/*
+ * check-name: and-or-mask
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ ret.32 $0
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/and-or-mask0.c b/validation/optim/and-or-mask0.c
new file mode 100644
index 00000000..2d2245ea
--- /dev/null
+++ b/validation/optim/and-or-mask0.c
@@ -0,0 +1,12 @@
+int foo(int a, int b)
+{
+ return ((a & 0xfffff000) | b) & 0xfff;
+}
+
+/*
+ * check-name: and-or-mask0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-mask1.c b/validation/optim/and-or-mask1.c
new file mode 100644
index 00000000..bff3a89f
--- /dev/null
+++ b/validation/optim/and-or-mask1.c
@@ -0,0 +1,13 @@
+int foo(int a, int b)
+{
+ return ((a & 0x0fffffff) | b) & 0xfff;
+}
+
+/*
+ * check-name: and-or-mask1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): and\\.
+ * check-output-pattern(1): or\\.
+ */
diff --git a/validation/optim/and-or-mask2.c b/validation/optim/and-or-mask2.c
new file mode 100644
index 00000000..cab802a6
--- /dev/null
+++ b/validation/optim/and-or-mask2.c
@@ -0,0 +1,13 @@
+int foo(int x, int y)
+{
+ return ((x & 0xffffff0f) | y) & 0xfff;
+}
+
+/*
+ * check-name: and-or-mask2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*\\$0xf0f
+ * check-output-excludes: and\\..*\\$0xffffff0f
+ */
diff --git a/validation/optim/and-or-mask3s.c b/validation/optim/and-or-mask3s.c
new file mode 100644
index 00000000..cf264723
--- /dev/null
+++ b/validation/optim/and-or-mask3s.c
@@ -0,0 +1,25 @@
+#define W 3
+#define S 8
+#define M (W << S)
+
+static inline int fun(unsigned int x, unsigned int y)
+{
+ return ((x & M) | (y << S)) >> S;
+}
+
+short foo(unsigned int x, unsigned int y)
+{
+ return fun(x, y) & W;
+}
+
+/*
+ * check-name: and-or-mask3s
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): lsr\\.
+ * check-output-pattern(1): or\\.
+ * check-output-pattern(1): and\\.
+ * check-output-excludes: shl\\.
+ */
diff --git a/validation/optim/and-or-mask3u.c b/validation/optim/and-or-mask3u.c
new file mode 100644
index 00000000..c5b6c5fa
--- /dev/null
+++ b/validation/optim/and-or-mask3u.c
@@ -0,0 +1,25 @@
+#define W 3
+#define S 8
+#define M (W << S)
+
+static inline int fun(unsigned int x, unsigned int y)
+{
+ return ((x & M) | (y << S)) >> S;
+}
+
+int foo(unsigned int x, unsigned int y)
+{
+ return fun(x, y) & W;
+}
+
+/*
+ * check-name: and-or-mask3u
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): lsr\\.
+ * check-output-pattern(1): or\\.
+ * check-output-pattern(1): and\\.
+ * check-output-excludes: shl\\.
+ */
diff --git a/validation/optim/and-or-mask4.c b/validation/optim/and-or-mask4.c
new file mode 100644
index 00000000..1c4bc01a
--- /dev/null
+++ b/validation/optim/and-or-mask4.c
@@ -0,0 +1,25 @@
+#define W 3
+#define S 8
+#define M (W << S)
+
+static inline int fun(unsigned int x, unsigned int y)
+{
+ return ((x & W) | (y >> S)) << S;
+}
+
+int foo(unsigned int x, unsigned int y)
+{
+ return fun(x, y) & M;
+}
+
+/*
+ * check-name: and-or-mask4
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): shl\\.
+ * check-output-pattern(1): or\\.
+ * check-output-pattern(1): and\\.
+ * check-output-excludes: lsr\\.
+ */
diff --git a/validation/optim/and-or-maskx.c b/validation/optim/and-or-maskx.c
new file mode 100644
index 00000000..21d44e8d
--- /dev/null
+++ b/validation/optim/and-or-maskx.c
@@ -0,0 +1,13 @@
+int foo(int x, int y, int a)
+{
+ return ((x & y) | (a & 0xf000)) & 0x0fff;
+}
+
+/*
+ * check-name: and-or-maskx
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(2): and\\.
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-shl0.c b/validation/optim/and-or-shl0.c
new file mode 100644
index 00000000..4850b326
--- /dev/null
+++ b/validation/optim/and-or-shl0.c
@@ -0,0 +1,12 @@
+int foo(int a, int b)
+{
+ return ((a & 0xfff00000) | b) << 12;
+}
+
+/*
+ * check-name: and-or-shl0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-shl1.c b/validation/optim/and-or-shl1.c
new file mode 100644
index 00000000..bea22245
--- /dev/null
+++ b/validation/optim/and-or-shl1.c
@@ -0,0 +1,13 @@
+int foo(int a, int b)
+{
+ return ((a & 0x000fffff) | b) << 12;
+}
+
+/*
+ * check-name: and-or-shl1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(0): and\\.
+ * check-output-pattern(1): or\\.
+ */
diff --git a/validation/optim/and-or-shl2.c b/validation/optim/and-or-shl2.c
new file mode 100644
index 00000000..f5f62758
--- /dev/null
+++ b/validation/optim/and-or-shl2.c
@@ -0,0 +1,13 @@
+int foo(int x, int y)
+{
+ return ((x & 0xffffff0f) | y) << 12;
+}
+
+/*
+ * check-name: and-or-shl2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*\\$0xfff0f
+ * check-output-excludes: and\\..*\\$0xffffff0f
+ */
diff --git a/validation/optim/and-or-shlx.c b/validation/optim/and-or-shlx.c
new file mode 100644
index 00000000..ec2a2ced
--- /dev/null
+++ b/validation/optim/and-or-shlx.c
@@ -0,0 +1,13 @@
+unsigned int foo(unsigned int x, unsigned int y, unsigned int a)
+{
+ return ((x & y) | (a & 0xfff00000)) << 12;
+}
+
+/*
+ * check-name: and-or-shlx
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): and\\.
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-trunc0.c b/validation/optim/and-or-trunc0.c
new file mode 100644
index 00000000..3d326b6a
--- /dev/null
+++ b/validation/optim/and-or-trunc0.c
@@ -0,0 +1,13 @@
+char foo(int x, int y)
+{
+ return (x & 0xff00) | y;
+}
+
+/*
+ * check-name: and-or-trunc0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: and\\.
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/and-or-trunc1.c b/validation/optim/and-or-trunc1.c
new file mode 100644
index 00000000..6bbe8a8c
--- /dev/null
+++ b/validation/optim/and-or-trunc1.c
@@ -0,0 +1,12 @@
+char foo(int x, int y)
+{
+ return (x & 0xffff) | y;
+}
+
+/*
+ * check-name: and-or-trunc1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: and\\.
+ */
diff --git a/validation/optim/and-or-trunc2.c b/validation/optim/and-or-trunc2.c
new file mode 100644
index 00000000..e66c1f14
--- /dev/null
+++ b/validation/optim/and-or-trunc2.c
@@ -0,0 +1,13 @@
+char foo(int x, int y)
+{
+ return (x & 0xff07) | y;
+}
+
+/*
+ * check-name: and-or-trunc2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): and\\.
+ * check-output-pattern(1): and\\..*\\$7
+ */
diff --git a/validation/optim/and-or-truncx.c b/validation/optim/and-or-truncx.c
new file mode 100644
index 00000000..ef8249a1
--- /dev/null
+++ b/validation/optim/and-or-truncx.c
@@ -0,0 +1,13 @@
+char foo(int x, int y, int b)
+{
+ return (x & y) | (b & 0xff00);
+}
+
+/*
+ * check-name: and-or-truncx
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): and\\.
+ * check-output-excludes: or\\.
+ */
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/bitfield-store-load0.c b/validation/optim/bitfield-store-load0.c
new file mode 100644
index 00000000..f68cb600
--- /dev/null
+++ b/validation/optim/bitfield-store-load0.c
@@ -0,0 +1,44 @@
+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 %r11 <- %arg1, $7
+ ret.32 %r11
+
+
+sfoo:
+.L2:
+ <entry-point>
+ trunc.3 %r16 <- (32) %arg1
+ sext.32 %r23 <- (3) %r16
+ ret.32 %r23
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/bitfield-store-loads.c b/validation/optim/bitfield-store-loads.c
new file mode 100644
index 00000000..dc625131
--- /dev/null
+++ b/validation/optim/bitfield-store-loads.c
@@ -0,0 +1,23 @@
+struct s {
+ char :2;
+ char f:3;
+};
+
+int foo(struct s s, int a)
+{
+ s.f = a;
+ return s.f;
+}
+
+/*
+ * check-name: bitfield-store-load signed
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: shl\\.
+ * check-output-excludes: lsr\\.
+ * check-output-excludes: or\\.
+ * check-output-excludes: [sz]ext\\.
+ * check-output-excludes: trunc\\.
+ * check-output-pattern(1): and\\.
+ */
diff --git a/validation/optim/bitfield-store-loadu.c b/validation/optim/bitfield-store-loadu.c
new file mode 100644
index 00000000..7fa1593d
--- /dev/null
+++ b/validation/optim/bitfield-store-loadu.c
@@ -0,0 +1,21 @@
+struct s {
+ unsigned int :2;
+ unsigned int f:3;
+};
+
+int foo(struct s s, int a)
+{
+ s.f = a;
+ return s.f;
+}
+
+/*
+ * check-name: bitfield-store-load unsigned
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: shl\\.
+ * check-output-excludes: lsr\\.
+ * check-output-excludes: or\\.
+ * check-output-pattern(1): and\\.
+ */
diff --git a/validation/optim/bool-context-fp.c b/validation/optim/bool-context-fp.c
index 50e96825..c41370ba 100644
--- a/validation/optim/bool-context-fp.c
+++ b/validation/optim/bool-context-fp.c
@@ -18,7 +18,7 @@ int ifand(float a, float b) { return a && b; }
bfimp:
.L0:
<entry-point>
- setfval.32 %r2 <- 0.000000
+ setfval.32 %r2 <- 0.000000e+00
fcmpune.1 %r3 <- %arg1, %r2
ret.1 %r3
@@ -26,7 +26,7 @@ bfimp:
bfexp:
.L2:
<entry-point>
- setfval.32 %r6 <- 0.000000
+ setfval.32 %r6 <- 0.000000e+00
fcmpune.1 %r7 <- %arg1, %r6
ret.1 %r7
@@ -34,7 +34,7 @@ bfexp:
bfnot:
.L4:
<entry-point>
- setfval.32 %r10 <- 0.000000
+ setfval.32 %r10 <- 0.000000e+00
fcmpoeq.1 %r12 <- %arg1, %r10
ret.1 %r12
@@ -42,7 +42,7 @@ bfnot:
ifnot:
.L6:
<entry-point>
- setfval.32 %r15 <- 0.000000
+ setfval.32 %r15 <- 0.000000e+00
fcmpoeq.32 %r16 <- %arg1, %r15
ret.32 %r16
@@ -50,18 +50,17 @@ ifnot:
bfior:
.L8:
<entry-point>
- setfval.32 %r19 <- 0.000000
+ setfval.32 %r19 <- 0.000000e+00
fcmpune.1 %r20 <- %arg1, %r19
fcmpune.1 %r23 <- %arg2, %r19
or.1 %r24 <- %r20, %r23
- setne.1 %r26 <- %r24, $0
- ret.1 %r26
+ ret.1 %r24
ifior:
.L10:
<entry-point>
- setfval.32 %r29 <- 0.000000
+ setfval.32 %r29 <- 0.000000e+00
fcmpune.1 %r30 <- %arg1, %r29
fcmpune.1 %r33 <- %arg2, %r29
or.1 %r34 <- %r30, %r33
@@ -72,18 +71,17 @@ ifior:
bfand:
.L12:
<entry-point>
- setfval.32 %r38 <- 0.000000
+ setfval.32 %r38 <- 0.000000e+00
fcmpune.1 %r39 <- %arg1, %r38
fcmpune.1 %r42 <- %arg2, %r38
and.1 %r43 <- %r39, %r42
- setne.1 %r45 <- %r43, $0
- ret.1 %r45
+ ret.1 %r43
ifand:
.L14:
<entry-point>
- setfval.32 %r48 <- 0.000000
+ setfval.32 %r48 <- 0.000000e+00
fcmpune.1 %r49 <- %arg1, %r48
fcmpune.1 %r52 <- %arg2, %r48
and.1 %r53 <- %r49, %r52
diff --git a/validation/optim/bool-sext-test.c b/validation/optim/bool-sext-test.c
new file mode 100644
index 00000000..bd85e06e
--- /dev/null
+++ b/validation/optim/bool-sext-test.c
@@ -0,0 +1,12 @@
+_Bool eqs0( signed char a) { return a == 0; }
+_Bool eqs1( signed char a) { return a == 1; }
+_Bool nes0( signed char a) { return a != 0; }
+_Bool nes1( signed char a) { return a != 1; }
+
+/*
+ * check-name: bool-sext-test
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ */
diff --git a/validation/optim/bool-simplify.c b/validation/optim/bool-simplify.c
index 68aabb78..fe8ce88b 100644
--- a/validation/optim/bool-simplify.c
+++ b/validation/optim/bool-simplify.c
@@ -43,17 +43,15 @@ and_0:
and_1:
.L2:
<entry-point>
- setne.1 %r8 <- %arg1, $0
- zext.32 %r11 <- (1) %r8
- ret.32 %r11
+ setne.32 %r9 <- %arg1, $0
+ ret.32 %r9
or_0:
.L4:
<entry-point>
- setne.1 %r14 <- %arg1, $0
- zext.32 %r17 <- (1) %r14
- ret.32 %r17
+ setne.32 %r14 <- %arg1, $0
+ ret.32 %r14
or_1:
@@ -65,9 +63,8 @@ or_1:
and_2:
.L8:
<entry-point>
- setne.1 %r26 <- %arg1, $0
- zext.32 %r29 <- (1) %r26
- ret.32 %r29
+ setne.32 %r25 <- %arg1, $0
+ ret.32 %r25
or_2:
diff --git a/validation/optim/bool-simplify2.c b/validation/optim/bool-simplify2.c
index c94b4412..a089fe62 100644
--- a/validation/optim/bool-simplify2.c
+++ b/validation/optim/bool-simplify2.c
@@ -27,7 +27,7 @@ static bool babbb(bool a, bool b, bool c) { return a && b && c; }
* check-name: bool-simplify2
* check-command: test-linearize $file
*
- * check-output-pattern(36): setne\\.
+ * check-output-pattern(20): setne\\.
* check-output-pattern(4): seteq\\.
* check-output-pattern(8): zext\\.
* check-output-pattern(12): and
@@ -75,8 +75,7 @@ boii:
setne.1 %r23 <- %arg1, $0
setne.1 %r25 <- %arg2, $0
or.1 %r26 <- %r23, %r25
- setne.1 %r28 <- %r26, $0
- ret.1 %r28
+ ret.1 %r26
baii:
@@ -85,8 +84,7 @@ baii:
setne.1 %r31 <- %arg1, $0
setne.1 %r33 <- %arg2, $0
and.1 %r34 <- %r31, %r33
- setne.1 %r36 <- %r34, $0
- ret.1 %r36
+ ret.1 %r34
ioiii:
@@ -95,9 +93,8 @@ ioiii:
setne.1 %r39 <- %arg1, $0
setne.1 %r41 <- %arg2, $0
or.1 %r42 <- %r39, %r41
- setne.1 %r44 <- %r42, $0
setne.1 %r46 <- %arg3, $0
- or.1 %r47 <- %r44, %r46
+ or.1 %r47 <- %r42, %r46
zext.32 %r48 <- (1) %r47
ret.32 %r48
@@ -108,9 +105,8 @@ iaiii:
setne.1 %r51 <- %arg1, $0
setne.1 %r53 <- %arg2, $0
and.1 %r54 <- %r51, %r53
- setne.1 %r56 <- %r54, $0
setne.1 %r58 <- %arg3, $0
- and.1 %r59 <- %r56, %r58
+ and.1 %r59 <- %r54, %r58
zext.32 %r60 <- (1) %r59
ret.32 %r60
@@ -121,11 +117,9 @@ boiii:
setne.1 %r63 <- %arg1, $0
setne.1 %r65 <- %arg2, $0
or.1 %r66 <- %r63, %r65
- setne.1 %r68 <- %r66, $0
setne.1 %r70 <- %arg3, $0
- or.1 %r71 <- %r68, %r70
- setne.1 %r73 <- %r71, $0
- ret.1 %r73
+ or.1 %r71 <- %r66, %r70
+ ret.1 %r71
baiii:
@@ -134,11 +128,9 @@ baiii:
setne.1 %r76 <- %arg1, $0
setne.1 %r78 <- %arg2, $0
and.1 %r79 <- %r76, %r78
- setne.1 %r81 <- %r79, $0
setne.1 %r83 <- %arg3, $0
- and.1 %r84 <- %r81, %r83
- setne.1 %r86 <- %r84, $0
- ret.1 %r86
+ and.1 %r84 <- %r79, %r83
+ ret.1 %r84
inb:
@@ -175,24 +167,21 @@ bobb:
.L28:
<entry-point>
or.1 %r107 <- %arg1, %arg2
- setne.1 %r109 <- %r107, $0
- ret.1 %r109
+ ret.1 %r107
babb:
.L30:
<entry-point>
and.1 %r113 <- %arg1, %arg2
- setne.1 %r115 <- %r113, $0
- ret.1 %r115
+ ret.1 %r113
iobbb:
.L32:
<entry-point>
or.1 %r119 <- %arg1, %arg2
- setne.1 %r121 <- %r119, $0
- or.1 %r123 <- %r121, %arg3
+ or.1 %r123 <- %r119, %arg3
zext.32 %r124 <- (1) %r123
ret.32 %r124
@@ -201,8 +190,7 @@ iabbb:
.L34:
<entry-point>
and.1 %r128 <- %arg1, %arg2
- setne.1 %r130 <- %r128, $0
- and.1 %r132 <- %r130, %arg3
+ and.1 %r132 <- %r128, %arg3
zext.32 %r133 <- (1) %r132
ret.32 %r133
@@ -211,20 +199,16 @@ bobbb:
.L36:
<entry-point>
or.1 %r137 <- %arg1, %arg2
- setne.1 %r139 <- %r137, $0
- or.1 %r141 <- %r139, %arg3
- setne.1 %r143 <- %r141, $0
- ret.1 %r143
+ or.1 %r141 <- %r137, %arg3
+ ret.1 %r141
babbb:
.L38:
<entry-point>
and.1 %r147 <- %arg1, %arg2
- setne.1 %r149 <- %r147, $0
- and.1 %r151 <- %r149, %arg3
- setne.1 %r153 <- %r151, $0
- ret.1 %r153
+ and.1 %r151 <- %r147, %arg3
+ ret.1 %r151
* check-output-end
diff --git a/validation/optim/bool-zext-test.c b/validation/optim/bool-zext-test.c
new file mode 100644
index 00000000..138938b0
--- /dev/null
+++ b/validation/optim/bool-zext-test.c
@@ -0,0 +1,12 @@
+_Bool equ0(unsigned char a) { return a == 0; }
+_Bool equ1(unsigned char a) { return a == 1; }
+_Bool neu0(unsigned char a) { return a != 0; }
+_Bool neu1(unsigned char a) { return a != 1; }
+
+/*
+ * check-name: bool-zext-test
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: zext\\.
+ */
diff --git a/validation/optim/call-inlined.c b/validation/optim/call-inlined.c
index 00698a4b..f21b3294 100644
--- a/validation/optim/call-inlined.c
+++ b/validation/optim/call-inlined.c
@@ -22,8 +22,8 @@ int foo(int a, int b, int p)
foo:
.L0:
<entry-point>
- select.32 %r9 <- %arg3, %arg3, $0
- ret.32 %r9
+ select.32 %r10 <- %arg3, %arg3, $0
+ ret.32 %r10
* check-output-end
diff --git a/validation/optim/cast-kinds.c b/validation/optim/cast-kinds.c
new file mode 100644
index 00000000..b144dc7e
--- /dev/null
+++ b/validation/optim/cast-kinds.c
@@ -0,0 +1,397 @@
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+static int uint_2_int(uint a) { return (int)a; }
+static int long_2_int(long a) { return (int)a; }
+static int ulong_2_int(ulong a) { return (int)a; }
+static int vptr_2_int(void *a) { return (int)a; }
+static int iptr_2_int(int *a) { return (int)a; }
+static int float_2_int(float a) { return (int)a; }
+static int double_2_int(double a) { return (int)a; }
+static uint int_2_uint(int a) { return (uint)a; }
+static uint long_2_uint(long a) { return (uint)a; }
+static uint ulong_2_uint(ulong a) { return (uint)a; }
+static uint vptr_2_uint(void *a) { return (uint)a; }
+static uint iptr_2_uint(int *a) { return (uint)a; }
+static uint float_2_uint(float a) { return (uint)a; }
+static uint double_2_uint(double a) { return (uint)a; }
+static long int_2_long(int a) { return (long)a; }
+static long uint_2_long(uint a) { return (long)a; }
+static long ulong_2_long(ulong a) { return (long)a; }
+static long vptr_2_long(void *a) { return (long)a; }
+static long iptr_2_long(int *a) { return (long)a; }
+static long float_2_long(float a) { return (long)a; }
+static long double_2_long(double a) { return (long)a; }
+static ulong int_2_ulong(int a) { return (ulong)a; }
+static ulong uint_2_ulong(uint a) { return (ulong)a; }
+static ulong long_2_ulong(long a) { return (ulong)a; }
+static ulong vptr_2_ulong(void *a) { return (ulong)a; }
+static ulong iptr_2_ulong(int *a) { return (ulong)a; }
+static ulong float_2_ulong(float a) { return (ulong)a; }
+static ulong double_2_ulong(double a) { return (ulong)a; }
+static void * int_2_vptr(int a) { return (void *)a; }
+static void * uint_2_vptr(uint a) { return (void *)a; }
+static void * long_2_vptr(long a) { return (void *)a; }
+static void * ulong_2_vptr(ulong a) { return (void *)a; }
+static void * iptr_2_vptr(int *a) { return (void *)a; }
+static int * int_2_iptr(int a) { return (int *)a; }
+static int * uint_2_iptr(uint a) { return (int *)a; }
+static int * long_2_iptr(long a) { return (int *)a; }
+static int * ulong_2_iptr(ulong a) { return (int *)a; }
+static int * vptr_2_iptr(void *a) { return (int *)a; }
+static float int_2_float(int a) { return (float)a; }
+static float uint_2_float(uint a) { return (float)a; }
+static float long_2_float(long a) { return (float)a; }
+static float ulong_2_float(ulong a) { return (float)a; }
+static float double_2_float(double a) { return (float)a; }
+static double int_2_double(int a) { return (double)a; }
+static double uint_2_double(uint a) { return (double)a; }
+static double long_2_double(long a) { return (double)a; }
+static double ulong_2_double(ulong a) { return (double)a; }
+static double float_2_double(float a) { return (double)a; }
+
+static float float_2_float(float a) { return a; }
+static double double_2_double(double a) { return a; }
+
+/*
+ * check-name: cast-kinds
+ * check-command: test-linearize -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -m64 $file
+ *
+ * check-output-start
+uint_2_int:
+.L0:
+ <entry-point>
+ ret.32 %arg1
+
+
+long_2_int:
+.L2:
+ <entry-point>
+ trunc.32 %r4 <- (64) %arg1
+ ret.32 %r4
+
+
+ulong_2_int:
+.L4:
+ <entry-point>
+ trunc.32 %r7 <- (64) %arg1
+ ret.32 %r7
+
+
+vptr_2_int:
+.L6:
+ <entry-point>
+ trunc.32 %r10 <- (64) %arg1
+ ret.32 %r10
+
+
+iptr_2_int:
+.L8:
+ <entry-point>
+ trunc.32 %r14 <- (64) %arg1
+ ret.32 %r14
+
+
+float_2_int:
+.L10:
+ <entry-point>
+ fcvts.32 %r17 <- (32) %arg1
+ ret.32 %r17
+
+
+double_2_int:
+.L12:
+ <entry-point>
+ fcvts.32 %r20 <- (64) %arg1
+ ret.32 %r20
+
+
+int_2_uint:
+.L14:
+ <entry-point>
+ ret.32 %arg1
+
+
+long_2_uint:
+.L16:
+ <entry-point>
+ trunc.32 %r25 <- (64) %arg1
+ ret.32 %r25
+
+
+ulong_2_uint:
+.L18:
+ <entry-point>
+ trunc.32 %r28 <- (64) %arg1
+ ret.32 %r28
+
+
+vptr_2_uint:
+.L20:
+ <entry-point>
+ trunc.32 %r31 <- (64) %arg1
+ ret.32 %r31
+
+
+iptr_2_uint:
+.L22:
+ <entry-point>
+ trunc.32 %r35 <- (64) %arg1
+ ret.32 %r35
+
+
+float_2_uint:
+.L24:
+ <entry-point>
+ fcvtu.32 %r38 <- (32) %arg1
+ ret.32 %r38
+
+
+double_2_uint:
+.L26:
+ <entry-point>
+ fcvtu.32 %r41 <- (64) %arg1
+ ret.32 %r41
+
+
+int_2_long:
+.L28:
+ <entry-point>
+ sext.64 %r44 <- (32) %arg1
+ ret.64 %r44
+
+
+uint_2_long:
+.L30:
+ <entry-point>
+ zext.64 %r47 <- (32) %arg1
+ ret.64 %r47
+
+
+ulong_2_long:
+.L32:
+ <entry-point>
+ ret.64 %arg1
+
+
+vptr_2_long:
+.L34:
+ <entry-point>
+ ret.64 %arg1
+
+
+iptr_2_long:
+.L36:
+ <entry-point>
+ ret.64 %arg1
+
+
+float_2_long:
+.L38:
+ <entry-point>
+ fcvts.64 %r57 <- (32) %arg1
+ ret.64 %r57
+
+
+double_2_long:
+.L40:
+ <entry-point>
+ fcvts.64 %r60 <- (64) %arg1
+ ret.64 %r60
+
+
+int_2_ulong:
+.L42:
+ <entry-point>
+ sext.64 %r63 <- (32) %arg1
+ ret.64 %r63
+
+
+uint_2_ulong:
+.L44:
+ <entry-point>
+ zext.64 %r66 <- (32) %arg1
+ ret.64 %r66
+
+
+long_2_ulong:
+.L46:
+ <entry-point>
+ ret.64 %arg1
+
+
+vptr_2_ulong:
+.L48:
+ <entry-point>
+ ret.64 %arg1
+
+
+iptr_2_ulong:
+.L50:
+ <entry-point>
+ ret.64 %arg1
+
+
+float_2_ulong:
+.L52:
+ <entry-point>
+ fcvtu.64 %r76 <- (32) %arg1
+ ret.64 %r76
+
+
+double_2_ulong:
+.L54:
+ <entry-point>
+ fcvtu.64 %r79 <- (64) %arg1
+ ret.64 %r79
+
+
+int_2_vptr:
+.L56:
+ <entry-point>
+ sext.64 %r82 <- (32) %arg1
+ ret.64 %r82
+
+
+uint_2_vptr:
+.L58:
+ <entry-point>
+ zext.64 %r85 <- (32) %arg1
+ ret.64 %r85
+
+
+long_2_vptr:
+.L60:
+ <entry-point>
+ ret.64 %arg1
+
+
+ulong_2_vptr:
+.L62:
+ <entry-point>
+ ret.64 %arg1
+
+
+iptr_2_vptr:
+.L64:
+ <entry-point>
+ ret.64 %arg1
+
+
+int_2_iptr:
+.L66:
+ <entry-point>
+ sext.64 %r94 <- (32) %arg1
+ ret.64 %r94
+
+
+uint_2_iptr:
+.L68:
+ <entry-point>
+ zext.64 %r98 <- (32) %arg1
+ ret.64 %r98
+
+
+long_2_iptr:
+.L70:
+ <entry-point>
+ ret.64 %arg1
+
+
+ulong_2_iptr:
+.L72:
+ <entry-point>
+ ret.64 %arg1
+
+
+vptr_2_iptr:
+.L74:
+ <entry-point>
+ ptrcast.64 %r108 <- (64) %arg1
+ ret.64 %r108
+
+
+int_2_float:
+.L76:
+ <entry-point>
+ scvtf.32 %r111 <- (32) %arg1
+ ret.32 %r111
+
+
+uint_2_float:
+.L78:
+ <entry-point>
+ ucvtf.32 %r114 <- (32) %arg1
+ ret.32 %r114
+
+
+long_2_float:
+.L80:
+ <entry-point>
+ scvtf.32 %r117 <- (64) %arg1
+ ret.32 %r117
+
+
+ulong_2_float:
+.L82:
+ <entry-point>
+ ucvtf.32 %r120 <- (64) %arg1
+ ret.32 %r120
+
+
+double_2_float:
+.L84:
+ <entry-point>
+ fcvtf.32 %r123 <- (64) %arg1
+ ret.32 %r123
+
+
+int_2_double:
+.L86:
+ <entry-point>
+ scvtf.64 %r126 <- (32) %arg1
+ ret.64 %r126
+
+
+uint_2_double:
+.L88:
+ <entry-point>
+ ucvtf.64 %r129 <- (32) %arg1
+ ret.64 %r129
+
+
+long_2_double:
+.L90:
+ <entry-point>
+ scvtf.64 %r132 <- (64) %arg1
+ ret.64 %r132
+
+
+ulong_2_double:
+.L92:
+ <entry-point>
+ ucvtf.64 %r135 <- (64) %arg1
+ ret.64 %r135
+
+
+float_2_double:
+.L94:
+ <entry-point>
+ fcvtf.64 %r138 <- (32) %arg1
+ ret.64 %r138
+
+
+float_2_float:
+.L96:
+ <entry-point>
+ ret.32 %arg1
+
+
+double_2_double:
+.L98:
+ <entry-point>
+ ret.64 %arg1
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/cast-nop.c b/validation/optim/cast-nop.c
new file mode 100644
index 00000000..7741b7a7
--- /dev/null
+++ b/validation/optim/cast-nop.c
@@ -0,0 +1,18 @@
+static long p2l(long *p)
+{
+ return (long) p;
+}
+
+static long *l2p(long l)
+{
+ return (long*)l;
+}
+
+/*
+ * check-name: cast-nop
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: utptr\\.
+ * check-output-excludes: ptrtu\\.
+ */
diff --git a/validation/optim/cse-cmp-next.c b/validation/optim/cse-cmp-next.c
new file mode 100644
index 00000000..50fdbac0
--- /dev/null
+++ b/validation/optim/cse-cmp-next.c
@@ -0,0 +1,15 @@
+void foo(int p, int i, int f, int *ref, int *dst, int *src)
+{
+ if (p)
+ f = ref[i];
+ if (f)
+ dst[i] = src[i];
+}
+
+/*
+ * check-name: cse-cmp-next
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1,2): mul\\.
+ */
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/lsr-and0.c b/validation/optim/lsr-and0.c
new file mode 100644
index 00000000..94310ba8
--- /dev/null
+++ b/validation/optim/lsr-and0.c
@@ -0,0 +1,13 @@
+unsigned lsr_and0(unsigned x)
+{
+ unsigned t = (x & 0x00000fff);
+ return (t >> 12) & t;
+}
+
+/*
+ * check-name: lsr-and0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0$
+ */
diff --git a/validation/optim/lsr-and1.c b/validation/optim/lsr-and1.c
new file mode 100644
index 00000000..393679e3
--- /dev/null
+++ b/validation/optim/lsr-and1.c
@@ -0,0 +1,18 @@
+// If (t >> S) is simplified into (x >> S)
+// then the whole expression will be 0.
+// The test is only interesting if the sub-expression
+// (x & M) is referenced more than once
+// (because otherwise other simplifications apply).
+unsigned lsr_and1(unsigned x)
+{
+ unsigned t = (x & 0xfffff000);
+ return ((t >> 12) ^ (x >> 12)) & t;
+}
+
+/*
+ * check-name: lsr-and1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0$
+ */
diff --git a/validation/optim/lsr-asr.c b/validation/optim/lsr-asr.c
new file mode 100644
index 00000000..aee46940
--- /dev/null
+++ b/validation/optim/lsr-asr.c
@@ -0,0 +1,42 @@
+int lsrasr0(unsigned int x)
+{
+ return ((int) (x >> 15)) >> 15;
+}
+
+int lsrasr1(unsigned int x)
+{
+ return ((int) (x >> 16)) >> 15;
+}
+
+int lsrasr2(unsigned int x)
+{
+ return ((int) (x >> 16)) >> 16;
+}
+
+/*
+ * check-name: lsr-asr
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+lsrasr0:
+.L0:
+ <entry-point>
+ lsr.32 %r3 <- %arg1, $30
+ ret.32 %r3
+
+
+lsrasr1:
+.L2:
+ <entry-point>
+ lsr.32 %r7 <- %arg1, $31
+ ret.32 %r7
+
+
+lsrasr2:
+.L4:
+ <entry-point>
+ ret.32 $0
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/lsr-shl0.c b/validation/optim/lsr-shl0.c
new file mode 100644
index 00000000..952baa6b
--- /dev/null
+++ b/validation/optim/lsr-shl0.c
@@ -0,0 +1,14 @@
+unsigned mask(unsigned x)
+{
+ return (x << 15) >> 15;
+}
+
+/*
+ * check-name: lsr-shl0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*0x1ffff
+ * check-output-excludes: lsr\\.
+ * check-output-excludes: shl\\.
+ */
diff --git a/validation/optim/mask-lsr.c b/validation/optim/mask-lsr.c
new file mode 100644
index 00000000..ec636444
--- /dev/null
+++ b/validation/optim/mask-lsr.c
@@ -0,0 +1,14 @@
+// ((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-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..ac85aec8
--- /dev/null
+++ b/validation/optim/mask-out.c
@@ -0,0 +1,12 @@
+unsigned mask(unsigned a, unsigned b)
+{
+ return ((a & 0xffff0000) | b) & 0x0000ffff;
+}
+
+/*
+ * check-name: mask-out
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: %arg1
+ */
diff --git a/validation/optim/mask1-setne0.c b/validation/optim/mask1-setne0.c
new file mode 100644
index 00000000..1e599dc8
--- /dev/null
+++ b/validation/optim/mask1-setne0.c
@@ -0,0 +1,28 @@
+struct s {
+ unsigned i:1;
+};
+
+int foo(struct s x)
+{
+ unsigned int i = x.i;
+
+ if (i == 0)
+ return 1;
+ else if (i == 1)
+ return 1;
+ return 0;
+}
+
+/*
+ * check-name: mask1-setne0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ ret.32 $1
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/or-and-constant1.c b/validation/optim/or-and-constant1.c
new file mode 100644
index 00000000..aa673b90
--- /dev/null
+++ b/validation/optim/or-and-constant1.c
@@ -0,0 +1,29 @@
+unsigned int and_or_equ(unsigned int a)
+{
+ return (a | 3) & 3;
+}
+
+int and_or_eqs(int a)
+{
+ return (a | 3) & 3;
+}
+
+unsigned int or_and_equ(unsigned int a)
+{
+ return (a & 3) | 3;
+}
+
+int or_and_eqs(int a)
+{
+ return (a & 3) | 3;
+}
+
+/*
+ * check-name: or-and-constant1
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(4): ret\\..*\\$3
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/setcc-mask.c b/validation/optim/setcc-mask.c
new file mode 100644
index 00000000..5d271788
--- /dev/null
+++ b/validation/optim/setcc-mask.c
@@ -0,0 +1,18 @@
+int foo (int a)
+{
+ return ((a == 0) & 1) == (a == 0);
+}
+
+/*
+ * check-name: setcc-mask
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ ret.32 $1
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/setne0-sext.c b/validation/optim/setne0-sext.c
new file mode 100644
index 00000000..4167979b
--- /dev/null
+++ b/validation/optim/setne0-sext.c
@@ -0,0 +1,9 @@
+long foo(int a) { return a != 0; }
+
+/*
+ * check-name: setne0-sext
+ * check-command: test-linearize -m64 -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: sext\\.
+ */
diff --git a/validation/optim/setne0-trunc.c b/validation/optim/setne0-trunc.c
new file mode 100644
index 00000000..6c5494ec
--- /dev/null
+++ b/validation/optim/setne0-trunc.c
@@ -0,0 +1,9 @@
+char foo(int a) { return a != 0; }
+
+/*
+ * check-name: setne0-trunc
+ * check-command: test-linearize -m64 -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: trunc\\.
+ */
diff --git a/validation/optim/setne0-zext.c b/validation/optim/setne0-zext.c
new file mode 100644
index 00000000..8a074f03
--- /dev/null
+++ b/validation/optim/setne0-zext.c
@@ -0,0 +1,9 @@
+unsigned long foo(int a) { return (unsigned int) (a != 0); }
+
+/*
+ * check-name: setne0-zext
+ * check-command: test-linearize -m64 -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: zext\\.
+ */
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/sh-or-and0.c b/validation/optim/sh-or-and0.c
new file mode 100644
index 00000000..02f0cb03
--- /dev/null
+++ b/validation/optim/sh-or-and0.c
@@ -0,0 +1,20 @@
+unsigned lsr_or_and0(unsigned x, unsigned b)
+{
+ return (((x & 0x00000fff) | b) >> 12);
+}
+
+unsigned shl_or_and0(unsigned x, unsigned b)
+{
+ return (((x & 0xfff00000) | b) << 12);
+}
+
+/*
+ * check-name: sh-or-and0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): lsr\\.
+ * check-output-pattern(1): shl\\.
+ * check-output-excludes: or\\.
+ * check-output-excludes: and\\.
+ */
diff --git a/validation/optim/sh-or-and1.c b/validation/optim/sh-or-and1.c
new file mode 100644
index 00000000..7b79bbf3
--- /dev/null
+++ b/validation/optim/sh-or-and1.c
@@ -0,0 +1,20 @@
+unsigned lsr_or_and1(unsigned x, unsigned b)
+{
+ return (((x & 0xfffff000) | b) >> 12);
+}
+
+unsigned shl_or_and1(unsigned x, unsigned b)
+{
+ return (((x & 0x000fffff) | b) << 12);
+}
+
+/*
+ * check-name: sh-or-and1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): lsr\\.
+ * check-output-pattern(1): shl\\.
+ * check-output-pattern(2): or\\.
+ * check-output-excludes: and\\.
+ */
diff --git a/validation/optim/sh-or-and2.c b/validation/optim/sh-or-and2.c
new file mode 100644
index 00000000..241aeaff
--- /dev/null
+++ b/validation/optim/sh-or-and2.c
@@ -0,0 +1,21 @@
+unsigned lsr_or_and2(unsigned x, unsigned b)
+{
+ return (((x & 0xf0ffffff) | b) >> 12);
+}
+
+unsigned shl_or_and2(unsigned x, unsigned b)
+{
+ return (((x & 0xffffff0f) | b) << 12);
+}
+
+/*
+ * check-name: sh-or-and2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): lsr\\.
+ * check-output-pattern(1): shl\\.
+ * check-output-pattern(2): or\\.
+ * check-output-pattern(1): and\\..*\\$0xf0fff000
+ * check-output-pattern(1): and\\..*\\$0xfff0f
+ */
diff --git a/validation/optim/shift-big.c b/validation/optim/shift-big.c
new file mode 100644
index 00000000..84bcd2ce
--- /dev/null
+++ b/validation/optim/shift-big.c
@@ -0,0 +1,82 @@
+typedef unsigned int u32;
+typedef int s32;
+
+s32 asr31(s32 a) { return a >> 31; }
+s32 asr32(s32 a) { return a >> 32; }
+s32 asr33(s32 a) { return a >> 33; }
+
+u32 lsr31(u32 a) { return a >> 31; }
+u32 lsr32(u32 a) { return a >> 32; }
+u32 lsr33(u32 a) { return a >> 33; }
+
+u32 shl31(u32 a) { return a << 31; }
+u32 shl32(u32 a) { return a << 32; }
+u32 shl33(u32 a) { return a << 33; }
+
+/*
+ * check-name: optim/shift-big.c
+ * check-command: test-linearize -Wno-decl -m64 $file
+ *
+ * check-error-ignore
+ * check-output-start
+asr31:
+.L0:
+ <entry-point>
+ asr.32 %r2 <- %arg1, $31
+ ret.32 %r2
+
+
+asr32:
+.L2:
+ <entry-point>
+ asr.32 %r5 <- %arg1, $32
+ ret.32 %r5
+
+
+asr33:
+.L4:
+ <entry-point>
+ asr.32 %r8 <- %arg1, $33
+ ret.32 %r8
+
+
+lsr31:
+.L6:
+ <entry-point>
+ lsr.32 %r11 <- %arg1, $31
+ ret.32 %r11
+
+
+lsr32:
+.L8:
+ <entry-point>
+ ret.32 $0
+
+
+lsr33:
+.L10:
+ <entry-point>
+ ret.32 $0
+
+
+shl31:
+.L12:
+ <entry-point>
+ shl.32 %r20 <- %arg1, $31
+ ret.32 %r20
+
+
+shl32:
+.L14:
+ <entry-point>
+ ret.32 $0
+
+
+shl33:
+.L16:
+ <entry-point>
+ ret.32 $0
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/shift-shift.c b/validation/optim/shift-shift.c
new file mode 100644
index 00000000..12a4b7d4
--- /dev/null
+++ b/validation/optim/shift-shift.c
@@ -0,0 +1,149 @@
+unsigned int shl0(unsigned int x)
+{
+ return x << 15 << 15;
+}
+
+unsigned int shl1(unsigned int x)
+{
+ return x << 16 << 15;
+}
+
+unsigned int shl2(unsigned int x)
+{
+ return x << 16 << 16;
+}
+
+unsigned int shl3(unsigned int x)
+{
+ return x << 12 << 10 << 10;
+}
+
+
+unsigned int lsr0(unsigned int x)
+{
+ return x >> 15 >> 15;
+}
+
+unsigned int lsr1(unsigned int x)
+{
+ return x >> 16 >> 15;
+}
+
+unsigned int lsr2(unsigned int x)
+{
+ return x >> 16 >> 16;
+}
+
+unsigned int lsr3(unsigned int x)
+{
+ return x >> 12 >> 10 >> 10;
+}
+
+
+int asr0(int x)
+{
+ return x >> 15 >> 15;
+}
+
+int asr1(int x)
+{
+ return x >> 16 >> 15;
+}
+
+int asr2(int x)
+{
+ return x >> 16 >> 16;
+}
+
+int asr3(int x)
+{
+ return x >> 12 >> 10 >> 10;
+}
+
+/*
+ * check-name: shift-shift
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+shl0:
+.L0:
+ <entry-point>
+ shl.32 %r3 <- %arg1, $30
+ ret.32 %r3
+
+
+shl1:
+.L2:
+ <entry-point>
+ shl.32 %r7 <- %arg1, $31
+ ret.32 %r7
+
+
+shl2:
+.L4:
+ <entry-point>
+ ret.32 $0
+
+
+shl3:
+.L6:
+ <entry-point>
+ ret.32 $0
+
+
+lsr0:
+.L8:
+ <entry-point>
+ lsr.32 %r20 <- %arg1, $30
+ ret.32 %r20
+
+
+lsr1:
+.L10:
+ <entry-point>
+ lsr.32 %r24 <- %arg1, $31
+ ret.32 %r24
+
+
+lsr2:
+.L12:
+ <entry-point>
+ ret.32 $0
+
+
+lsr3:
+.L14:
+ <entry-point>
+ ret.32 $0
+
+
+asr0:
+.L16:
+ <entry-point>
+ asr.32 %r37 <- %arg1, $30
+ ret.32 %r37
+
+
+asr1:
+.L18:
+ <entry-point>
+ asr.32 %r41 <- %arg1, $31
+ ret.32 %r41
+
+
+asr2:
+.L20:
+ <entry-point>
+ asr.32 %r45 <- %arg1, $31
+ ret.32 %r45
+
+
+asr3:
+.L22:
+ <entry-point>
+ asr.32 %r50 <- %arg1, $31
+ ret.32 %r50
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/shift-zext.c b/validation/optim/shift-zext.c
new file mode 100644
index 00000000..30409bec
--- /dev/null
+++ b/validation/optim/shift-zext.c
@@ -0,0 +1,12 @@
+unsigned int foo(unsigned int x)
+{
+ return (x << 20) >> 20;
+}
+
+/*
+ * check-name: shift-zext
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*%arg1, \\$0xfff
+ */
diff --git a/validation/optim/shl-and0.c b/validation/optim/shl-and0.c
new file mode 100644
index 00000000..894bd882
--- /dev/null
+++ b/validation/optim/shl-and0.c
@@ -0,0 +1,13 @@
+unsigned shl_and0(unsigned x)
+{
+ unsigned t = (x & 0xfff00000);
+ return (t << 12) & t;
+}
+
+/*
+ * check-name: shl-and0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0$
+ */
diff --git a/validation/optim/shl-and1.c b/validation/optim/shl-and1.c
new file mode 100644
index 00000000..13a1675b
--- /dev/null
+++ b/validation/optim/shl-and1.c
@@ -0,0 +1,18 @@
+// If (t << S) is simplified into (x << S)
+// then the whole expression will be 0.
+// The test is only interesting if the sub-expression
+// (x & M) is referenced more than once
+// (because otherwise other simplifications apply).
+unsigned shl_and1(unsigned x)
+{
+ unsigned t = (x & 0x000fffff);
+ return ((t << 12) ^ (x << 12)) & t;
+}
+
+/*
+ * check-name: shl-and1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0$
+ */
diff --git a/validation/optim/shl-lsr0.c b/validation/optim/shl-lsr0.c
new file mode 100644
index 00000000..fc2561bd
--- /dev/null
+++ b/validation/optim/shl-lsr0.c
@@ -0,0 +1,14 @@
+unsigned mask(unsigned x)
+{
+ return (x >> 15) << 15;
+}
+
+/*
+ * check-name: shl-lsr0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: and\\..*0xffff8000
+ * check-output-excludes: lsr\\.
+ * check-output-excludes: shl\\.
+ */
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/trunc-or-shl.c b/validation/optim/trunc-or-shl.c
new file mode 100644
index 00000000..70d8bd1d
--- /dev/null
+++ b/validation/optim/trunc-or-shl.c
@@ -0,0 +1,13 @@
+char foo(int a, int b)
+{
+ return (a << 8) | b;
+}
+
+/*
+ * check-name: trunc-or-shl
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*%arg2
+ */
diff --git a/validation/optim/trunc-seteq0.c b/validation/optim/trunc-seteq0.c
new file mode 100644
index 00000000..5994b17c
--- /dev/null
+++ b/validation/optim/trunc-seteq0.c
@@ -0,0 +1,18 @@
+struct S {
+ int :1;
+ signed int s:2;
+ unsigned int u:3;
+};
+
+int os(int i, struct S *b) { return i || b->s; }
+int ou(int i, struct S *b) { return i || b->u; }
+
+/*
+ * check-name: trunc-seteq0
+ * 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/trunc-setne0.c b/validation/optim/trunc-setne0.c
new file mode 100644
index 00000000..878c05fa
--- /dev/null
+++ b/validation/optim/trunc-setne0.c
@@ -0,0 +1,20 @@
+struct s {
+ unsigned int u:1;
+};
+
+unsigned int foo(struct s x)
+{
+ if (x.u)
+ return 1;
+ else
+ return 0;
+}
+
+/*
+ * check-name: trunc-setne0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: and\\.
+ * check-output-excludes: trunc\\.
+ */
diff --git a/validation/optim/trunc-trunc.c b/validation/optim/trunc-trunc.c
new file mode 100644
index 00000000..6dc50aee
--- /dev/null
+++ b/validation/optim/trunc-trunc.c
@@ -0,0 +1,12 @@
+char foo(int a)
+{
+ return ((((short) a) + 1) - 1);
+}
+
+/*
+ * check-name: trunc-trunc
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): trunc\\.
+ */
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-asr.c b/validation/optim/zext-asr.c
new file mode 100644
index 00000000..5f235ad8
--- /dev/null
+++ b/validation/optim/zext-asr.c
@@ -0,0 +1,13 @@
+unsigned short foo(unsigned short a)
+{
+ return a >> 16;
+}
+
+/*
+ * check-name: zext-asr
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0
+ * check-output-excludes: asr\\.
+ */
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\\.
+ */