From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 7/7] not: simplify ((x cmp y) {&,|,^} (x !cmp y)) --> {0,1,1}
Date: Sun, 22 Nov 2020 16:27:31 +0100 [thread overview]
Message-ID: <20201122152731.10994-8-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201122152731.10994-1-luc.vanoostenryck@gmail.com>
Simplify bitwise operations on a compare and its complement
into 0 (for &) or 1 for (| and ^).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 24 +++++++++++++++++++++---
validation/optim/cse-not02.c | 1 -
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/simplify.c b/simplify.c
index b41c155735d1..9938a5974744 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1632,7 +1632,7 @@ static int simplify_compare(struct instruction *insn)
static int simplify_and_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2)
{
- struct instruction *def;
+ struct instruction *def, *defr = NULL;
pseudo_t src1 = *p1;
switch (DEF_OPCODE(def, src1)) {
@@ -1640,6 +1640,12 @@ static int simplify_and_one_side(struct instruction *insn, pseudo_t *p1, pseudo_
if (def->src == *p2)
return replace_with_value(insn, 0);
break;
+ case OP_BINCMP ... OP_BINCMP_END:
+ if (DEF_OPCODE(defr, *p2) == opcode_negate(def->opcode)) {
+ if (def->src1 == defr->src1 && def->src2 == defr->src2)
+ return replace_with_value(insn, 0);
+ }
+ break;
}
return 0;
}
@@ -1652,7 +1658,7 @@ static int simplify_and(struct instruction *insn)
static int simplify_ior_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2)
{
- struct instruction *def;
+ struct instruction *def, *defr = NULL;
pseudo_t src1 = *p1;
switch (DEF_OPCODE(def, src1)) {
@@ -1660,6 +1666,12 @@ static int simplify_ior_one_side(struct instruction *insn, pseudo_t *p1, pseudo_
if (def->src == *p2)
return replace_with_value(insn, bits_mask(insn->size));
break;
+ case OP_BINCMP ... OP_BINCMP_END:
+ if (DEF_OPCODE(defr, *p2) == opcode_negate(def->opcode)) {
+ if (def->src1 == defr->src1 && def->src2 == defr->src2)
+ return replace_with_value(insn, 1);
+ }
+ break;
}
return 0;
}
@@ -1672,7 +1684,7 @@ static int simplify_ior(struct instruction *insn)
static int simplify_xor_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2)
{
- struct instruction *def;
+ struct instruction *def, *defr = NULL;
pseudo_t src1 = *p1;
switch (DEF_OPCODE(def, src1)) {
@@ -1680,6 +1692,12 @@ static int simplify_xor_one_side(struct instruction *insn, pseudo_t *p1, pseudo_
if (def->src == *p2)
return replace_with_value(insn, bits_mask(insn->size));
break;
+ case OP_BINCMP ... OP_BINCMP_END:
+ if (DEF_OPCODE(defr, *p2) == opcode_negate(def->opcode)) {
+ if (def->src1 == defr->src1 && def->src2 == defr->src2)
+ return replace_with_value(insn, 1);
+ }
+ break;
}
return 0;
}
diff --git a/validation/optim/cse-not02.c b/validation/optim/cse-not02.c
index aa54a375a9ea..70addebcfbb6 100644
--- a/validation/optim/cse-not02.c
+++ b/validation/optim/cse-not02.c
@@ -5,7 +5,6 @@ int xor(int a, int b) { return ((a == b) ^ (a != b)) == 1; }
/*
* check-name: cse-not02
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.29.2
prev parent reply other threads:[~2020-11-22 15:27 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-22 15:27 [PATCH 0/7] simplify logical negation Luc Van Oostenryck
2020-11-22 15:27 ` [PATCH 1/7] not: add testcases for canonicalization & simplification of negations Luc Van Oostenryck
2020-11-22 19:00 ` Linus Torvalds
2020-11-22 19:57 ` Luc Van Oostenryck
2020-11-22 20:13 ` Linus Torvalds
2020-11-22 20:38 ` Luc Van Oostenryck
2020-11-22 22:26 ` Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 0/6] 'bits translation' simplification Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 1/6] add testscases for 'bits translation' optimization Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 2/6] factorize SEL(x, OP(y,z), y) into OP(SEL(x, z, 0), y) Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 3/6] add helper is_power_of_2() Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 4/6] add helper is_pow2() Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 5/6] add log base 2 function: log2_exact() Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 6/6] convert SEL(x & BIT1, BIT2, 0) into SHIFT(x & BIT1, S) Luc Van Oostenryck
2020-11-27 22:25 ` [PATCH 7/7] move up instructions blocking if-conversion Luc Van Oostenryck
2020-11-27 22:44 ` [PATCH 0/6] 'bits translation' simplification Linus Torvalds
2020-11-22 15:27 ` [PATCH 2/7] canon: put PSEUDO_ARGs in canonical order too Luc Van Oostenryck
2020-11-22 15:27 ` [PATCH 3/7] canon: put PSEUDO_REGs " Luc Van Oostenryck
2020-11-22 15:27 ` [PATCH 4/7] canon: simplify calculation of canonical order Luc Van Oostenryck
2020-11-22 15:27 ` [PATCH 5/7] opcode: add helpers opcode_negate() & opcode_swap() Luc Van Oostenryck
2020-11-22 15:27 ` [PATCH 6/7] not: simplify (~x {&,|,^} x) --> {0,~0,~0} Luc Van Oostenryck
2020-11-22 15:27 ` Luc Van Oostenryck [this message]
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=20201122152731.10994-8-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.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).