linux-sparse.vger.kernel.org archive mirror
 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 13/22] sub: simplify (C - y) + D --> eval(C+D) - y
Date: Tue, 20 Oct 2020 23:10:12 +0200	[thread overview]
Message-ID: <20201020211021.82394-14-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201020211021.82394-1-luc.vanoostenryck@gmail.com>

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

diff --git a/simplify.c b/simplify.c
index 7d1897e65b07..929a177631e5 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1096,6 +1096,24 @@ static int simplify_constant_mask(struct instruction *insn, unsigned long long m
 	return 0;
 }
 
+static int simplify_const_rightadd(struct instruction *def, struct instruction *insn)
+{
+	unsigned size = insn->size;
+	pseudo_t src2 = insn->src2;
+
+	switch (def->opcode) {
+	case OP_SUB:
+		if (constant(def->src1)) { // (C - y) + D --> eval(C+D) - y
+			pseudo_t val = eval_op(OP_ADD, size, def->src1, src2);
+			insn->opcode = OP_SUB;
+			use_pseudo(insn, def->src2, &insn->src2);
+			return replace_pseudo(insn, &insn->src1, val);
+		}
+		break;
+	}
+	return 0;
+}
+
 static int simplify_constant_rightside(struct instruction *insn)
 {
 	long long value = insn->src2->value;
@@ -1128,6 +1146,8 @@ static int simplify_constant_rightside(struct instruction *insn)
 	case OP_ADD:
 		if (!value)
 			return replace_with_pseudo(insn, insn->src1);
+		if (insn->src1->type == PSEUDO_REG)	// (x # y) + z
+			changed |= simplify_const_rightadd(insn->src1->def, insn);
 		return changed;
 	case OP_ASR:
 	case OP_SHL:
diff --git a/validation/optim/simplify-cte-sub-addl.c b/validation/optim/simplify-cte-sub-addl.c
index 49e510062c03..137029636f2d 100644
--- a/validation/optim/simplify-cte-sub-addl.c
+++ b/validation/optim/simplify-cte-sub-addl.c
@@ -3,7 +3,6 @@ int cte_sub_addl(int x) { return (1 - x) + 1; }
 /*
  * check-name: simplify-cte-sub-addl
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-contains: sub\\..*\\$2, %arg1
-- 
2.28.0


  parent reply	other threads:[~2020-10-20 21:10 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20 21:09 [PATCH 00/22] essential OP_ADD & OP_SUB simplifications Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 01/22] add testcases about " Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 02/22] let switch_pseudo() return REPEAT_CSE Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 03/22] extract eval_op() from eval_insn() Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 04/22] unop: add helper eval_unop() Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 05/22] unop: add helper replace_with_unop() Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 06/22] add a flag to identify commutative & associative ops Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 07/22] constants must be truncated to the operation's size Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 08/22] reassoc: simplify (x # C) # K --> x # eval(C # K) Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 09/22] sub: reorganize handling of OP_{ADD,SUB}s with constant rightside Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 10/22] sub: canonicalize (0 - x) into -x Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 11/22] sub: simplify C - (y + D) --> eval(C-D) - y Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 12/22] sub: simplify C - (D - z) --> z + eval(C-D) Luc Van Oostenryck
2020-10-20 21:10 ` Luc Van Oostenryck [this message]
2020-10-20 21:10 ` [PATCH 14/22] sub: simplify (x - -y) --> (x + y) Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 15/22] add: simplify (x + -y) --> (x - y) Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 16/22] add: simplify (-x + y) --> (y - x) Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 17/22] sub: simplify (x + y) - x --> y Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 18/22] sub: simplify (x + y) - y --> x Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 19/22] sub: simplify x - (x + y) --> -y Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 20/22] sub: simplify x - (y + x) " Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 21/22] sub: simplify (x - y) + y --> x Luc Van Oostenryck
2020-10-20 21:10 ` [PATCH 22/22] sub: simplify x + (y - x) --> y 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=20201020211021.82394-14-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).