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 1/6] add testscases for 'bits translation' optimization
Date: Fri, 27 Nov 2020 23:25:10 +0100	[thread overview]
Message-ID: <20201127222516.44915-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201127222516.44915-1-luc.vanoostenryck@gmail.com>

Add some testcase related to the simplification of expressions like:
	if (val1 & BIT1)
		val2 |= BIT2;
into
	val2 |= (val1 & BIT1) {SHL/LSR} |BIT2-BIT1|;

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/optim/fact-select01.c    | 26 ++++++++++++++++++++++++++
 validation/optim/select-and-shift.c | 18 ++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 validation/optim/fact-select01.c
 create mode 100644 validation/optim/select-and-shift.c

diff --git a/validation/optim/fact-select01.c b/validation/optim/fact-select01.c
new file mode 100644
index 000000000000..ef4e5e89a7be
--- /dev/null
+++ b/validation/optim/fact-select01.c
@@ -0,0 +1,26 @@
+int add_yx_y(int p, int x, int y) { return (p ? (y+x) : y) == ((p ? x : 0) + y); }
+int add_xy_y(int p, int y, int x) { return (p ? (x+y) : y) == ((p ? x : 0) + y); }
+int add_xy_x(int p, int x, int y) { return (p ? (x+y) : x) == ((p ? y : 0) + x); }
+int add_yx_x(int p, int y, int x) { return (p ? (y+x) : x) == ((p ? y : 0) + x); }
+int add_y_yx(int p, int x, int y) { return (p ? y : (y+x)) == ((p ? 0 : x) + y); }
+
+int ior_yx_y(int p, int x, int y) { return (p ? (y|x) : y) == ((p ? x : 0) | y); }
+int ior_xy_y(int p, int y, int x) { return (p ? (x|y) : y) == ((p ? x : 0) | y); }
+int ior_xy_x(int p, int x, int y) { return (p ? (x|y) : x) == ((p ? y : 0) | x); }
+int ior_yx_x(int p, int y, int x) { return (p ? (y|x) : x) == ((p ? y : 0) | x); }
+int ior_y_yx(int p, int x, int y) { return (p ? y : (y|x)) == ((p ? 0 : x) | y); }
+
+int xor_yx_y(int p, int x, int y) { return (p ? (y^x) : y) == ((p ? x : 0) ^ y); }
+int xor_xy_y(int p, int y, int x) { return (p ? (x^y) : y) == ((p ? x : 0) ^ y); }
+int xor_xy_x(int p, int x, int y) { return (p ? (x^y) : x) == ((p ? y : 0) ^ x); }
+int xor_yx_x(int p, int y, int x) { return (p ? (y^x) : x) == ((p ? y : 0) ^ x); }
+int xor_y_yx(int p, int x, int y) { return (p ? y : (y^x)) == ((p ? 0 : x) ^ y); }
+
+/*
+ * check-name: fact-select01
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/select-and-shift.c b/validation/optim/select-and-shift.c
new file mode 100644
index 000000000000..fbe044c7cb44
--- /dev/null
+++ b/validation/optim/select-and-shift.c
@@ -0,0 +1,18 @@
+#define S1	2
+#define S2	5
+#define S	(S2 - S1)
+
+#define	A	(1 << S1)
+#define	B	(1 << S2)
+
+int foo(int p) { return ((p & A) ? B : 0) == ((((unsigned)p) & A) << S); }
+int bar(int p) { return ((p & B) ? A : 0) == ((((unsigned)p) & B) >> S); }
+
+/*
+ * check-name: select-and-shift
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
-- 
2.29.2


  reply	other threads:[~2020-11-27 22:28 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           ` Luc Van Oostenryck [this message]
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 ` [PATCH 7/7] not: simplify ((x cmp y) {&,|,^} (x !cmp y)) --> {0,1,1} 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=20201127222516.44915-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 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.