All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 09/10] cmps: canonicalize SEL(x {<,<=} y, a, b) --> SEL(x {>=,>} y, b, a)
Date: Tue, 26 Jan 2021 23:04:31 +0100	[thread overview]
Message-ID: <20210126220432.58265-10-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20210126220432.58265-1-luc.vanoostenryck@gmail.com>

Both compares and OP_SELECT are anti-symmetrical: swapping
the arguments is equivalent to inversing the condition.
As consequence, when combined, they're symmetrical:
swapping the arguments of the compare (or equivalently reversing
the direction of the compare) and swapping the operand of the
OP_SELECT is a no-op, both forms are equivalent.

So, canonicalize these to always use OP_GT or OP_GE.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                            | 7 +++++++
 validation/optim/canonical-cmps-sel.c | 1 -
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/simplify.c b/simplify.c
index b29f5d5b2444..10cdf50dcbf1 100644
--- a/simplify.c
+++ b/simplify.c
@@ -2301,6 +2301,13 @@ static int simplify_select(struct instruction *insn)
 		if (src2 == def->src1 && src1 == def->src2)
 			return replace_with_pseudo(insn, src1); // SEL(y!=x,x,y) --> x
 		break;
+	case OP_SET_LE: case OP_SET_LT:
+	case OP_SET_BE: case OP_SET_B:
+		if (!one_use(cond))
+			break;
+		// SEL(x {<,<=} y, a, b) --> SEL(x {>=,>} y, b, a)
+		def->opcode = opcode_negate(def->opcode);
+		return switch_pseudo(insn, &insn->src2, insn, &insn->src3);
 	case OP_SEL:
 		if (constant(def->src2) && constant(def->src3)) {
 			// Is the def of the conditional another select?
diff --git a/validation/optim/canonical-cmps-sel.c b/validation/optim/canonical-cmps-sel.c
index f0a0effc7954..bba5e5c894f8 100644
--- a/validation/optim/canonical-cmps-sel.c
+++ b/validation/optim/canonical-cmps-sel.c
@@ -19,7 +19,6 @@ _Bool sel_leu(unsigned int a, unsigned int b, int x, int y)
 /*
  * check-name: canonical-cmps-sel
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-returns: 1
-- 
2.30.0


  parent reply	other threads:[~2021-01-27  3:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 22:04 [PATCH 00/10] simplify and canonicalize signed compares Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 01/10] cmps: make clearer we're using the operands' size Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 02/10] cmps: fix simplification of sext(x) + signed compare of {SMAX,SMIN} Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 03/10] cmpu: fix canonicalization of unsigned (x {<,>=} C) --> (x {<=,>} C-1) Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 04/10] cmps: add testcases for simplification of signed compares Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 05/10] cmps: simplify signed compares with SMIN or SMAX Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 06/10] cmps: canonicalize signed compares with SMIN/SMAX Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 07/10] cmps: canonicalize SMIN/SMAX +- 1 --> EQ/NE Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 08/10] cmps: canonicalize signed compares with constant Luc Van Oostenryck
2021-01-26 22:04 ` Luc Van Oostenryck [this message]
2021-01-26 22:04 ` [PATCH 10/10] cmps: canonicalize SEL(x > 0, a, -a) --> SEL(x >= 0, a, -a) Luc Van Oostenryck
2021-04-17 17:16 ` [PATCH 00/10] simplify and canonicalize signed compares Linus Torvalds
2021-04-17 18:20   ` Luc Van Oostenryck

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=20210126220432.58265-10-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.