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 01/22] add testcases about OP_ADD & OP_SUB simplifications
Date: Tue, 20 Oct 2020 23:10:00 +0200	[thread overview]
Message-ID: <20201020211021.82394-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201020211021.82394-1-luc.vanoostenryck@gmail.com>

Add some testcases about basic simplifications of additions
and subtractions.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/optim/canonical-sub-cte.c      | 10 ++++++++++
 validation/optim/reassoc-op-op1.c         | 15 +++++++++++++++
 validation/optim/simplify-add-neg.c       | 10 ++++++++++
 validation/optim/simplify-cte-sub-addl.c  | 10 ++++++++++
 validation/optim/simplify-cte-sub-addr.c  | 10 ++++++++++
 validation/optim/simplify-cte-sub-subr.c  | 10 ++++++++++
 validation/optim/simplify-neg-add.c       | 10 ++++++++++
 validation/optim/simplify-same-add-subl.c | 16 ++++++++++++++++
 validation/optim/simplify-same-add-subr.c | 16 ++++++++++++++++
 validation/optim/simplify-same-addl-sub.c | 10 ++++++++++
 validation/optim/simplify-same-sub-addl.c | 10 ++++++++++
 validation/optim/simplify-same-subl-add.c | 12 ++++++++++++
 validation/optim/simplify-same-subr-add.c | 12 ++++++++++++
 validation/optim/simplify-sub-neg.c       | 10 ++++++++++
 validation/optim/simplify-zero-sub.c      | 10 ++++++++++
 15 files changed, 171 insertions(+)
 create mode 100644 validation/optim/canonical-sub-cte.c
 create mode 100644 validation/optim/reassoc-op-op1.c
 create mode 100644 validation/optim/simplify-add-neg.c
 create mode 100644 validation/optim/simplify-cte-sub-addl.c
 create mode 100644 validation/optim/simplify-cte-sub-addr.c
 create mode 100644 validation/optim/simplify-cte-sub-subr.c
 create mode 100644 validation/optim/simplify-neg-add.c
 create mode 100644 validation/optim/simplify-same-add-subl.c
 create mode 100644 validation/optim/simplify-same-add-subr.c
 create mode 100644 validation/optim/simplify-same-addl-sub.c
 create mode 100644 validation/optim/simplify-same-sub-addl.c
 create mode 100644 validation/optim/simplify-same-subl-add.c
 create mode 100644 validation/optim/simplify-same-subr-add.c
 create mode 100644 validation/optim/simplify-sub-neg.c
 create mode 100644 validation/optim/simplify-zero-sub.c

diff --git a/validation/optim/canonical-sub-cte.c b/validation/optim/canonical-sub-cte.c
new file mode 100644
index 000000000000..223be96fa5a5
--- /dev/null
+++ b/validation/optim/canonical-sub-cte.c
@@ -0,0 +1,10 @@
+int sub_cte(int x) { return (x - 1) != (x + -1); }
+
+/*
+ * check-name: canonical-sub-cte
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0
+ */
diff --git a/validation/optim/reassoc-op-op1.c b/validation/optim/reassoc-op-op1.c
new file mode 100644
index 000000000000..aa7092ff57a0
--- /dev/null
+++ b/validation/optim/reassoc-op-op1.c
@@ -0,0 +1,15 @@
+int foo(int x, int *ptr)
+{
+	int t = x + 1;
+	*ptr = t;
+	return t + -1;
+}
+
+/*
+ * check-name: reassoc-op-op1
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): add\\.
+ */
diff --git a/validation/optim/simplify-add-neg.c b/validation/optim/simplify-add-neg.c
new file mode 100644
index 000000000000..19b64b096567
--- /dev/null
+++ b/validation/optim/simplify-add-neg.c
@@ -0,0 +1,10 @@
+int add_neg(int x, int y) { return x + -y; }
+
+/*
+ * check-name: simplify-add-neg
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: sub\\..*%arg1, %arg2
+ */
diff --git a/validation/optim/simplify-cte-sub-addl.c b/validation/optim/simplify-cte-sub-addl.c
new file mode 100644
index 000000000000..49e510062c03
--- /dev/null
+++ b/validation/optim/simplify-cte-sub-addl.c
@@ -0,0 +1,10 @@
+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
+ */
diff --git a/validation/optim/simplify-cte-sub-addr.c b/validation/optim/simplify-cte-sub-addr.c
new file mode 100644
index 000000000000..81f5b34551c6
--- /dev/null
+++ b/validation/optim/simplify-cte-sub-addr.c
@@ -0,0 +1,10 @@
+int cte_sub_addr(int x) { return 2 - (x + 1); }
+
+/*
+ * check-name: simplify-cte-sub-addr
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: sub\\..*\\$1, %arg1
+ */
diff --git a/validation/optim/simplify-cte-sub-subr.c b/validation/optim/simplify-cte-sub-subr.c
new file mode 100644
index 000000000000..950b233e60c3
--- /dev/null
+++ b/validation/optim/simplify-cte-sub-subr.c
@@ -0,0 +1,10 @@
+int cte_sub_subr(int x) { return 1 - (1 - x); }
+
+/*
+ * check-name: simplify-cte-sub-subr
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..* %arg1
+ */
diff --git a/validation/optim/simplify-neg-add.c b/validation/optim/simplify-neg-add.c
new file mode 100644
index 000000000000..66a820f28069
--- /dev/null
+++ b/validation/optim/simplify-neg-add.c
@@ -0,0 +1,10 @@
+int neg_add(int x, int y) { return -x + y; }
+
+/*
+ * check-name: simplify-neg-add
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: sub\\..*%arg2, %arg1
+ */
diff --git a/validation/optim/simplify-same-add-subl.c b/validation/optim/simplify-same-add-subl.c
new file mode 100644
index 000000000000..1f17ef0b968e
--- /dev/null
+++ b/validation/optim/simplify-same-add-subl.c
@@ -0,0 +1,16 @@
+int add_subl(int x, int y) { return (x + y) - x; }
+
+/*
+ * check-name: simplify-same-add-subl
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-start
+add_subl:
+.L0:
+	<entry-point>
+	ret.32      %arg2
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/simplify-same-add-subr.c b/validation/optim/simplify-same-add-subr.c
new file mode 100644
index 000000000000..e8540703ee7d
--- /dev/null
+++ b/validation/optim/simplify-same-add-subr.c
@@ -0,0 +1,16 @@
+int add_subr(int x, int y) { return (x + y) - y; }
+
+/*
+ * check-name: simplify-same-add-subr
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-start
+add_subr:
+.L0:
+	<entry-point>
+	ret.32      %arg1
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/simplify-same-addl-sub.c b/validation/optim/simplify-same-addl-sub.c
new file mode 100644
index 000000000000..51d2b07966f4
--- /dev/null
+++ b/validation/optim/simplify-same-addl-sub.c
@@ -0,0 +1,10 @@
+int foo(int x, int y) { return x + (y - x); }
+
+/*
+ * check-name: simplify-same-addl-sub
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*%arg2
+ */
diff --git a/validation/optim/simplify-same-sub-addl.c b/validation/optim/simplify-same-sub-addl.c
new file mode 100644
index 000000000000..78f217399e50
--- /dev/null
+++ b/validation/optim/simplify-same-sub-addl.c
@@ -0,0 +1,10 @@
+int foo(int x, int y) { return (x - y) + y; }
+
+/*
+ * check-name: simplify-same-sub-addl
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*%arg1
+ */
diff --git a/validation/optim/simplify-same-subl-add.c b/validation/optim/simplify-same-subl-add.c
new file mode 100644
index 000000000000..dbc0fe97f126
--- /dev/null
+++ b/validation/optim/simplify-same-subl-add.c
@@ -0,0 +1,12 @@
+int subl_add(int x, int y) { return x - (x + y); }
+
+/*
+ * check-name: simplify-same-subl-add
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: neg\\..* %arg2
+ * check-output-excludes: add\\.
+ * check-output-excludes: sub\\.
+ */
diff --git a/validation/optim/simplify-same-subr-add.c b/validation/optim/simplify-same-subr-add.c
new file mode 100644
index 000000000000..bafd2643bfd0
--- /dev/null
+++ b/validation/optim/simplify-same-subr-add.c
@@ -0,0 +1,12 @@
+int subr_add(int x, int y) { return x - (y + x); }
+
+/*
+ * check-name: simplify-same-subr-add
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: neg\\..* %arg2
+ * check-output-excludes: add\\.
+ * check-output-excludes: sub\\.
+ */
diff --git a/validation/optim/simplify-sub-neg.c b/validation/optim/simplify-sub-neg.c
new file mode 100644
index 000000000000..b6fcc2baabec
--- /dev/null
+++ b/validation/optim/simplify-sub-neg.c
@@ -0,0 +1,10 @@
+int sub_neg(int x, int y) { return x - -y; }
+
+/*
+ * check-name: simplify-sub-neg
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: add\\..*%arg., %arg.
+ */
diff --git a/validation/optim/simplify-zero-sub.c b/validation/optim/simplify-zero-sub.c
new file mode 100644
index 000000000000..cc8fe7a3159b
--- /dev/null
+++ b/validation/optim/simplify-zero-sub.c
@@ -0,0 +1,10 @@
+int zero_sub(int x) { return 0 - x; }
+
+/*
+ * check-name: simplify-zero-sub
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: neg\\..* %arg1
+ */
-- 
2.28.0


  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 ` Luc Van Oostenryck [this message]
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 ` [PATCH 13/22] sub: simplify (C - y) + D --> eval(C+D) - y Luc Van Oostenryck
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-2-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).