From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH] simplify '~(~x)' and '-(-x)' to 'x'
Date: Wed, 7 Dec 2016 17:05:47 +0100 [thread overview]
Message-ID: <20161207160547.9821-1-luc.vanoostenryck@gmail.com> (raw)
Currently those double operations are not simplified.
This patch add those simplifications and some small test cases.
Note: the 'boolean not': '!(!x)' is not handled by this patch
because this operator is processed differently (it doesn't generate
an unop instruction but directly generates 'seteq' operations).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
WARNING: the test cases, to give the correct results, need the patches
from the serie "fix uses of killed instructions" sent previously.
simplify.c | 17 +++++++++++++++++
validation/optim/double-unop.c | 15 +++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 validation/optim/double-unop.c
diff --git a/simplify.c b/simplify.c
index b5cd0ea7..7e4bce5b 100644
--- a/simplify.c
+++ b/simplify.c
@@ -588,6 +588,23 @@ static int simplify_unop(struct instruction *insn)
return REPEAT_CSE;
if (constant(insn->src1))
return simplify_constant_unop(insn);
+
+ switch (insn->opcode) {
+ struct instruction *def;
+
+ case OP_NOT:
+ def = insn->src->def;
+ if (def && def->opcode == OP_NOT)
+ return replace_with_pseudo(insn, def->src);
+ break;
+ case OP_NEG:
+ def = insn->src->def;
+ if (def && def->opcode == OP_NEG)
+ return replace_with_pseudo(insn, def->src);
+ break;
+ default:
+ return 0;
+ }
return 0;
}
diff --git a/validation/optim/double-unop.c b/validation/optim/double-unop.c
new file mode 100644
index 00000000..f0e6d94f
--- /dev/null
+++ b/validation/optim/double-unop.c
@@ -0,0 +1,15 @@
+typedef unsigned int u32;
+
+u32 unotnot(u32 a) { return ~(~a); }
+int snotnot(int a) { return ~(~a); }
+u32 unegneg(int a) { return -(-a); }
+int snegneg(int a) { return -(-a); }
+
+/*
+ * check-name: double-unop
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-excludes: not\\.
+ * check-output-excludes: neg\\.
+ */
--
2.10.2
reply other threads:[~2016-12-07 16:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161207160547.9821-1-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).