aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/optim
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2016-12-11 22:13:27 +0100
committerChristopher Li <sparse@chrisli.org>2017-02-13 09:34:46 +0800
commite5f70312b25b77a57a2ca16acb94d726af15f5f9 (patch)
tree32aa7fb91abf0e7b3112cc650fb9cb11968119e7 /validation/optim
parent77ec9f360da23218a1d7447540302ff77e933a99 (diff)
downloadsparse-dev-e5f70312b25b77a57a2ca16acb94d726af15f5f9.tar.gz
simplify comparisons followed by an equality test against 0 or 1
Expressions involving equality testing against zero are ubiquitious and can often be simplified with previous comparisons. For example, when using test-linearize on the following code: _Bool foo(int a) { return !(a < 3); } the following was emitted: setlt.32 %r2 <- %arg1, $3 seteq.32 %r3 <- %r2, $0 setne.1 %r4 <- %r3, $0 ret.1 %r4 but this can be simplified into: setge.1 %r4 <- %arg1, $3 ret.1 %r4 Implement this simplification and add associated test cases. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation/optim')
-rw-r--r--validation/optim/setcc-setcc.c19
-rw-r--r--validation/optim/setcc-seteq.c13
-rw-r--r--validation/optim/setcc-setne.c13
3 files changed, 45 insertions, 0 deletions
diff --git a/validation/optim/setcc-setcc.c b/validation/optim/setcc-setcc.c
new file mode 100644
index 00000000..fac7520e
--- /dev/null
+++ b/validation/optim/setcc-setcc.c
@@ -0,0 +1,19 @@
+static _Bool blt(int a, int b) { return (a < b); }
+static _Bool bnge(int a, int b) { return !(a >= b); }
+static _Bool bgt(int a, int b) { return (a > b); }
+static _Bool bnle(int a, int b) { return !(a <= b); }
+static _Bool ble(int a, int b) { return (a <= b); }
+static _Bool bngt(int a, int b) { return !(a > b); }
+static _Bool bge(int a, int b) { return (a >= b); }
+static _Bool bnlt(int a, int b) { return !(a < b); }
+
+/*
+ * check-name: optim/setcc-setcc
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-excludes: set..\\.32
+ * check-output-excludes: setne\\.1
+ * check-output-excludes: seteq\\.1
+ * check-output-contains: set[gt][te]\\.1
+ */
diff --git a/validation/optim/setcc-seteq.c b/validation/optim/setcc-seteq.c
new file mode 100644
index 00000000..d8765fe1
--- /dev/null
+++ b/validation/optim/setcc-seteq.c
@@ -0,0 +1,13 @@
+static _Bool beq0(int a) { return (a == 0); }
+static _Bool bnotneq0(int a) { return !(a != 0); }
+static _Bool bnot(int a) { return !a; }
+
+/*
+ * check-name: optim/setcc-seteq
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-excludes: set..\\.32
+ * check-output-excludes: setne\\.1
+ * check-output-contains: seteq\\.1
+ */
diff --git a/validation/optim/setcc-setne.c b/validation/optim/setcc-setne.c
new file mode 100644
index 00000000..f982eb34
--- /dev/null
+++ b/validation/optim/setcc-setne.c
@@ -0,0 +1,13 @@
+static _Bool bnoteq0(int a) { return !(a == 0); }
+static _Bool bne0(int a) { return (a != 0); }
+static _Bool bnotnot(int a) { return !!a; }
+
+/*
+ * check-name: optim/setcc-setne
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-excludes: set..\\.32
+ * check-output-excludes: seteq\\.1
+ * check-output-contains: setne\\.1
+ */