aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2016-12-11 22:13:28 +0100
committerChristopher Li <sparse@chrisli.org>2017-02-13 09:34:46 +0800
commite460239ea1bc22517e1e62dabd24e9e9ddb66c15 (patch)
tree7613ec2f419acbc78ec742076d1d8bcb2cc136e7 /validation
parente5f70312b25b77a57a2ca16acb94d726af15f5f9 (diff)
downloadsparse-dev-e460239ea1bc22517e1e62dabd24e9e9ddb66c15.tar.gz
simplify '(x || x)' and '(x && x)'
The operators '||' and '&&' being idempotent, the expressions '(x || x)' and '(x && x)' can be simplified to a test against zero. Note: they could even be replaced by 'x' itself but only if 'x' is already a boolean expression/has already been tested against zero. If it is the case, the redundant test this will be optimized away in further steps. For example, test-linearize on the following code: int ior(int a) { return a || a; } emitted the following instructions: or-bool.32 %r3 <- %arg1, %arg1 after the patch, it now emits: setne.32 %r3 <- %arg1, $0 which is easier to combine with others simplifications. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation')
-rw-r--r--validation/optim/bool-same-args.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/validation/optim/bool-same-args.c b/validation/optim/bool-same-args.c
new file mode 100644
index 00000000..0ae4684e
--- /dev/null
+++ b/validation/optim/bool-same-args.c
@@ -0,0 +1,12 @@
+static int ior(int a) { return a || a; }
+static int and(int a) { return a && a; }
+
+/*
+ * check-name: bool-same-args
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-excludes: or-bool\\.
+ * check-output-excludes: and-bool\\.
+ * check-output-contains: setne\\.
+ */