linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] fix & extend mask related testcases
@ 2020-09-06 12:40 Luc Van Oostenryck
  2020-09-06 12:40 ` [PATCH 1/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 12:40 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

This is a preparatory step for some incoming series.

Luc Van Oostenryck (3):
  add more testcases for existing AND/OR simplifications
  add more testcases for AND/OR simplification
  optim: fix some testcases related to bitfield manipulation

 validation/optim/and-lsr-or-shl0.c  | 12 ++++++++++++
 validation/optim/and-lsr-or-shl1.c  | 12 ++++++++++++
 validation/optim/and-shl-or-and0.c  | 13 +++++++++++++
 validation/optim/and-shl-or-lsr0.c  | 13 +++++++++++++
 validation/optim/lsr-or-and0.c      | 23 +++++++++++++++++++++++
 validation/optim/lsr-or-lsr0.c      | 20 ++++++++++++++++++++
 validation/optim/sext.c             |  7 +++----
 validation/optim/shl-or-constant0.c | 12 ++++++++++++
 validation/optim/shl-or-constant1.c | 12 ++++++++++++
 validation/optim/shl-or-constant2.c | 12 ++++++++++++
 validation/optim/trunc-or-shl.c     |  4 +++-
 validation/optim/trunc-or-shl0.c    | 19 +++++++++++++++++++
 12 files changed, 154 insertions(+), 5 deletions(-)
 create mode 100644 validation/optim/and-lsr-or-shl0.c
 create mode 100644 validation/optim/and-lsr-or-shl1.c
 create mode 100644 validation/optim/and-shl-or-and0.c
 create mode 100644 validation/optim/and-shl-or-lsr0.c
 create mode 100644 validation/optim/lsr-or-and0.c
 create mode 100644 validation/optim/lsr-or-lsr0.c
 create mode 100644 validation/optim/shl-or-constant0.c
 create mode 100644 validation/optim/shl-or-constant1.c
 create mode 100644 validation/optim/shl-or-constant2.c
 create mode 100644 validation/optim/trunc-or-shl0.c

-- 
2.28.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/3] add more testcases for existing AND/OR simplifications
  2020-09-06 12:40 [PATCH 0/3] fix & extend mask related testcases Luc Van Oostenryck
@ 2020-09-06 12:40 ` Luc Van Oostenryck
  2020-09-06 16:12   ` Ramsay Jones
  2020-09-06 12:40 ` [PATCH 2/3] add more testcases for AND/OR simplification Luc Van Oostenryck
  2020-09-06 12:40 ` [PATCH 3/3] optim: fix some testcases related to bitfield manipulation Luc Van Oostenryck
  2 siblings, 1 reply; 11+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 12:40 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Add a few more testcases to catch possible future regressions.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/optim/and-shl-or-and0.c  | 13 +++++++++++++
 validation/optim/lsr-or-and0.c      | 23 +++++++++++++++++++++++
 validation/optim/shl-or-constant0.c | 12 ++++++++++++
 validation/optim/shl-or-constant1.c | 12 ++++++++++++
 validation/optim/shl-or-constant2.c | 12 ++++++++++++
 5 files changed, 72 insertions(+)
 create mode 100644 validation/optim/and-shl-or-and0.c
 create mode 100644 validation/optim/lsr-or-and0.c
 create mode 100644 validation/optim/shl-or-constant0.c
 create mode 100644 validation/optim/shl-or-constant1.c
 create mode 100644 validation/optim/shl-or-constant2.c

diff --git a/validation/optim/and-shl-or-and0.c b/validation/optim/and-shl-or-and0.c
new file mode 100644
index 000000000000..ea08d2622a95
--- /dev/null
+++ b/validation/optim/and-shl-or-and0.c
@@ -0,0 +1,13 @@
+unsigned and_shl_or_and0(unsigned a, unsigned b)
+{
+	return (((a & 0xfff00000) | b) << 12) & 0xfff00000;
+}
+
+/*
+ * check-name: and-shl-or-and0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ * check-output-excludes: lsr\\.
+ */
diff --git a/validation/optim/lsr-or-and0.c b/validation/optim/lsr-or-and0.c
new file mode 100644
index 000000000000..3c369cb9497e
--- /dev/null
+++ b/validation/optim/lsr-or-and0.c
@@ -0,0 +1,23 @@
+#define	S	12
+
+//	((x & M) | b) >> S;
+// ->	((x >> S) & (M >> S)) | (b >> S)
+// 0a:  (M >> S) == 0
+// 0b:  (x >> S) == 0
+// 0c:  (b >> S) == 0
+
+int lsr_or_and0a(unsigned int x, unsigned int b)
+{
+	return ((x & 0x00000fff) | b) >> S;
+}
+
+/*
+ * check-name: lsr-or-and0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): lsr\\.
+ * check-output-excludes: %arg1\\.
+ * check-output-excludes: and\\.
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/shl-or-constant0.c b/validation/optim/shl-or-constant0.c
new file mode 100644
index 000000000000..25347b4b3b20
--- /dev/null
+++ b/validation/optim/shl-or-constant0.c
@@ -0,0 +1,12 @@
+unsigned shl_or_constant0(unsigned a)
+{
+	return (a | 0xfff00000) << 12;
+}
+
+/*
+ * check-name: shl-or-constant0
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/shl-or-constant1.c b/validation/optim/shl-or-constant1.c
new file mode 100644
index 000000000000..cd3ea8bb011b
--- /dev/null
+++ b/validation/optim/shl-or-constant1.c
@@ -0,0 +1,12 @@
+unsigned shl_or_constant1(unsigned a)
+{
+	return (a | 0x000fffff) << 12;
+}
+
+/*
+ * check-name: shl-or-constant1
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret\\..*\\$0xfffff000
+ */
diff --git a/validation/optim/shl-or-constant2.c b/validation/optim/shl-or-constant2.c
new file mode 100644
index 000000000000..9dbde3b574d7
--- /dev/null
+++ b/validation/optim/shl-or-constant2.c
@@ -0,0 +1,12 @@
+unsigned shl_or_constant1(unsigned a)
+{
+	return (a | 0x00ffff0f) << 12;
+}
+
+/*
+ * check-name: shl-or-constant2
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-contains: or\\..*\\$0xfff0f
+ */
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/3] add more testcases for AND/OR simplification
  2020-09-06 12:40 [PATCH 0/3] fix & extend mask related testcases Luc Van Oostenryck
  2020-09-06 12:40 ` [PATCH 1/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
@ 2020-09-06 12:40 ` Luc Van Oostenryck
  2020-09-06 16:38   ` Ramsay Jones
  2020-09-06 12:40 ` [PATCH 3/3] optim: fix some testcases related to bitfield manipulation Luc Van Oostenryck
  2 siblings, 1 reply; 11+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 12:40 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Add a few testcases showing the effectiveness of these
simplifications and to catch possible future regressions.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/optim/and-lsr-or-shl0.c | 12 ++++++++++++
 validation/optim/and-lsr-or-shl1.c | 12 ++++++++++++
 validation/optim/and-shl-or-lsr0.c | 13 +++++++++++++
 validation/optim/lsr-or-lsr0.c     | 20 ++++++++++++++++++++
 validation/optim/trunc-or-shl0.c   | 19 +++++++++++++++++++
 5 files changed, 76 insertions(+)
 create mode 100644 validation/optim/and-lsr-or-shl0.c
 create mode 100644 validation/optim/and-lsr-or-shl1.c
 create mode 100644 validation/optim/and-shl-or-lsr0.c
 create mode 100644 validation/optim/lsr-or-lsr0.c
 create mode 100644 validation/optim/trunc-or-shl0.c

diff --git a/validation/optim/and-lsr-or-shl0.c b/validation/optim/and-lsr-or-shl0.c
new file mode 100644
index 000000000000..e2a517ab65c4
--- /dev/null
+++ b/validation/optim/and-lsr-or-shl0.c
@@ -0,0 +1,12 @@
+unsigned int and_lsr_or_shl0(unsigned int a, unsigned int b)
+{
+	return ((a | b << 12) >> 12) & 0xfff00000;
+}
+
+/*
+ * check-name: and-lsr-or-shl0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-excludes: shl\\.
+ */
diff --git a/validation/optim/and-lsr-or-shl1.c b/validation/optim/and-lsr-or-shl1.c
new file mode 100644
index 000000000000..6f2d05a0bfdd
--- /dev/null
+++ b/validation/optim/and-lsr-or-shl1.c
@@ -0,0 +1,12 @@
+unsigned int and_lsr_or_shl1(unsigned int a, unsigned int b)
+{
+	return ((a | b << 12) >> 12) & 0x000fffff;
+}
+
+/*
+ * check-name: and-lsr-or-shl1
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-excludes: shl\\.
+ */
diff --git a/validation/optim/and-shl-or-lsr0.c b/validation/optim/and-shl-or-lsr0.c
new file mode 100644
index 000000000000..f2a7cc631258
--- /dev/null
+++ b/validation/optim/and-shl-or-lsr0.c
@@ -0,0 +1,13 @@
+unsigned and_shl_or_lsr0(unsigned a, unsigned b)
+{
+	return ((a | (b >> 12)) << 12) & 0xfff00000;
+}
+
+/*
+ * check-name: and-shl-or-lsr0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/lsr-or-lsr0.c b/validation/optim/lsr-or-lsr0.c
new file mode 100644
index 000000000000..a1687ec21ff0
--- /dev/null
+++ b/validation/optim/lsr-or-lsr0.c
@@ -0,0 +1,20 @@
+#define	S	12
+
+//	((x >> S') | y) >> S;
+// ->	((x >> S >> S) | (y >> S)
+
+int lsr_or_lsr0(unsigned int x, unsigned int b)
+{
+	return ((x >> (32 - S)) | b) >> S;
+}
+
+/*
+ * check-name: lsr-or-lsr0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): lsr\\.
+ * check-output-excludes: and\\.
+ * check-output-excludes: or\\.
+ */
diff --git a/validation/optim/trunc-or-shl0.c b/validation/optim/trunc-or-shl0.c
new file mode 100644
index 000000000000..4d85a6bd4ec4
--- /dev/null
+++ b/validation/optim/trunc-or-shl0.c
@@ -0,0 +1,19 @@
+char trunc_or_shl0a(unsigned a, unsigned b)
+{
+	return (a << 8) | b;
+}
+
+char trunc_or_shl0b(unsigned a, unsigned b)
+{
+	return a | (b << 8);
+}
+
+/*
+ * check-name: trunc-or-shl0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: or\\.
+ * check-output-excludes: shl\\.
+ */
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/3] optim: fix some testcases related to bitfield manipulation
  2020-09-06 12:40 [PATCH 0/3] fix & extend mask related testcases Luc Van Oostenryck
  2020-09-06 12:40 ` [PATCH 1/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
  2020-09-06 12:40 ` [PATCH 2/3] add more testcases for AND/OR simplification Luc Van Oostenryck
@ 2020-09-06 12:40 ` Luc Van Oostenryck
  2 siblings, 0 replies; 11+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 12:40 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

The patterns used here were based on looser semantic for OP_{SEXT,TRUNC}.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/optim/sext.c         | 7 +++----
 validation/optim/trunc-or-shl.c | 4 +++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/validation/optim/sext.c b/validation/optim/sext.c
index 719730d50739..a3aa14945f11 100644
--- a/validation/optim/sext.c
+++ b/validation/optim/sext.c
@@ -6,10 +6,9 @@ int sext(int x)
 /*
  * check-name: sext
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
- * check-output-contains: sext\\.$27
- * check-output-excludes: asr\\.
- * check-output-excludes: shl\\.
+ * check-output-pattern(3): \\.32
+ * check-output-contains: shl\\.
+ * check-output-contains: asr\\.
  */
diff --git a/validation/optim/trunc-or-shl.c b/validation/optim/trunc-or-shl.c
index 70d8bd1de5bb..52b4f041b010 100644
--- a/validation/optim/trunc-or-shl.c
+++ b/validation/optim/trunc-or-shl.c
@@ -9,5 +9,7 @@ char foo(int a, int b)
  * check-known-to-fail
  *
  * check-output-ignore
- * check-output-contains: ret\\..*%arg2
+ * check-output-contains: trunc\\..*%arg2
+ * check-output-excludes: or\\.
+ * check-output-excludes: shl\\.
  */
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/3] add more testcases for existing AND/OR simplifications
  2020-09-06 12:40 ` [PATCH 1/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
@ 2020-09-06 16:12   ` Ramsay Jones
  2020-09-06 18:52     ` Luc Van Oostenryck
  0 siblings, 1 reply; 11+ messages in thread
From: Ramsay Jones @ 2020-09-06 16:12 UTC (permalink / raw)
  To: Luc Van Oostenryck, linux-sparse



On 06/09/2020 13:40, Luc Van Oostenryck wrote:
> Add a few more testcases to catch possible future regressions.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  validation/optim/and-shl-or-and0.c  | 13 +++++++++++++
>  validation/optim/lsr-or-and0.c      | 23 +++++++++++++++++++++++
>  validation/optim/shl-or-constant0.c | 12 ++++++++++++
>  validation/optim/shl-or-constant1.c | 12 ++++++++++++
>  validation/optim/shl-or-constant2.c | 12 ++++++++++++
>  5 files changed, 72 insertions(+)
>  create mode 100644 validation/optim/and-shl-or-and0.c
>  create mode 100644 validation/optim/lsr-or-and0.c
>  create mode 100644 validation/optim/shl-or-constant0.c
>  create mode 100644 validation/optim/shl-or-constant1.c
>  create mode 100644 validation/optim/shl-or-constant2.c
> 
> diff --git a/validation/optim/and-shl-or-and0.c b/validation/optim/and-shl-or-and0.c
> new file mode 100644
> index 000000000000..ea08d2622a95
> --- /dev/null
> +++ b/validation/optim/and-shl-or-and0.c
> @@ -0,0 +1,13 @@
> +unsigned and_shl_or_and0(unsigned a, unsigned b)
> +{
> +	return (((a & 0xfff00000) | b) << 12) & 0xfff00000;

->(((a & 0xfff00000) << 12) | (b << 12)) & 0xfff00000
->(( 0 | (b << 12)) & 0xfff00000
->((b << 12)) & 0xfff00000
> +}
> +
> +/*
> + * check-name: and-shl-or-and0
> + * check-command: test-linearize -Wno-decl $file
> + *
> + * check-output-ignore
> + * check-output-excludes: or\\.
> + * check-output-excludes: lsr\\.

why would there be a right-shift to begin with?
(maybe add check-output-excludes: %arg1)

> + */
> diff --git a/validation/optim/lsr-or-and0.c b/validation/optim/lsr-or-and0.c
> new file mode 100644
> index 000000000000..3c369cb9497e
> --- /dev/null
> +++ b/validation/optim/lsr-or-and0.c
> @@ -0,0 +1,23 @@
> +#define	S	12
> +
> +//	((x & M) | b) >> S;
> +// ->	((x >> S) & (M >> S)) | (b >> S)

OK

> +// 0a:  (M >> S) == 0
> +// 0b:  (x >> S) == 0
> +// 0c:  (b >> S) == 0

I do not understand what these three lines are trying to say! :(

> +
> +int lsr_or_and0a(unsigned int x, unsigned int b)

s/and0a/and0/ - was there an '_and0b' at one time?

> +{
> +	return ((x & 0x00000fff) | b) >> S;

->((x & 0x00000fff) >> S) | (b >> S)
->((0)) | (b >> S)
-> b >> S

> +}
> +
> +/*
> + * check-name: lsr-or-and0
> + * check-command: test-linearize -Wno-decl $file
> + *
> + * check-output-ignore
> + * check-output-pattern(1): lsr\\.
> + * check-output-excludes: %arg1\\.
> + * check-output-excludes: and\\.
> + * check-output-excludes: or\\.

OK

> + */
> diff --git a/validation/optim/shl-or-constant0.c b/validation/optim/shl-or-constant0.c
> new file mode 100644
> index 000000000000..25347b4b3b20
> --- /dev/null
> +++ b/validation/optim/shl-or-constant0.c
> @@ -0,0 +1,12 @@
> +unsigned shl_or_constant0(unsigned a)
> +{
> +	return (a | 0xfff00000) << 12;

->(a << 12) | (0xfff00000 << 12)
->(a << 12) | (0)
-> a << 12

> +}
> +
> +/*
> + * check-name: shl-or-constant0
> + * check-command: test-linearize -Wno-decl $file
> + *
> + * check-output-ignore
> + * check-output-excludes: or\\.

OK

> + */
> diff --git a/validation/optim/shl-or-constant1.c b/validation/optim/shl-or-constant1.c
> new file mode 100644
> index 000000000000..cd3ea8bb011b
> --- /dev/null
> +++ b/validation/optim/shl-or-constant1.c
> @@ -0,0 +1,12 @@
> +unsigned shl_or_constant1(unsigned a)
> +{
> +	return (a | 0x000fffff) << 12;
> +}
> +
> +/*
> + * check-name: shl-or-constant1
> + * check-command: test-linearize -Wno-decl $file
> + *
> + * check-output-ignore
> + * check-output-contains: ret\\..*\\$0xfffff000

OK

> + */
> diff --git a/validation/optim/shl-or-constant2.c b/validation/optim/shl-or-constant2.c
> new file mode 100644
> index 000000000000..9dbde3b574d7
> --- /dev/null
> +++ b/validation/optim/shl-or-constant2.c
> @@ -0,0 +1,12 @@
> +unsigned shl_or_constant1(unsigned a)

s/_constant1/_constant2/

> +{
> +	return (a | 0x00ffff0f) << 12;
> +}
> +
> +/*
> + * check-name: shl-or-constant2
> + * check-command: test-linearize -Wno-decl $file
> + *
> + * check-output-ignore
> + * check-output-contains: or\\..*\\$0xfff0f

OK

> + */
> 

ATB,
Ramsay Jones


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] add more testcases for AND/OR simplification
  2020-09-06 12:40 ` [PATCH 2/3] add more testcases for AND/OR simplification Luc Van Oostenryck
@ 2020-09-06 16:38   ` Ramsay Jones
  2020-09-06 16:46     ` Ramsay Jones
  2020-09-06 19:10     ` Luc Van Oostenryck
  0 siblings, 2 replies; 11+ messages in thread
From: Ramsay Jones @ 2020-09-06 16:38 UTC (permalink / raw)
  To: Luc Van Oostenryck, linux-sparse



On 06/09/2020 13:40, Luc Van Oostenryck wrote:
> Add a few testcases showing the effectiveness of these
> simplifications and to catch possible future regressions.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  validation/optim/and-lsr-or-shl0.c | 12 ++++++++++++
>  validation/optim/and-lsr-or-shl1.c | 12 ++++++++++++
>  validation/optim/and-shl-or-lsr0.c | 13 +++++++++++++
>  validation/optim/lsr-or-lsr0.c     | 20 ++++++++++++++++++++
>  validation/optim/trunc-or-shl0.c   | 19 +++++++++++++++++++
>  5 files changed, 76 insertions(+)
>  create mode 100644 validation/optim/and-lsr-or-shl0.c
>  create mode 100644 validation/optim/and-lsr-or-shl1.c
>  create mode 100644 validation/optim/and-shl-or-lsr0.c
>  create mode 100644 validation/optim/lsr-or-lsr0.c
>  create mode 100644 validation/optim/trunc-or-shl0.c

Given that these are new tests, I was (er..) expecting some
'*.expected' files! However, I guess (since they are all failing
tests anyway) those will come in future patches which will
actually implement the optimization.

> 
> diff --git a/validation/optim/and-lsr-or-shl0.c b/validation/optim/and-lsr-or-shl0.c
> new file mode 100644
> index 000000000000..e2a517ab65c4
> --- /dev/null
> +++ b/validation/optim/and-lsr-or-shl0.c
> @@ -0,0 +1,12 @@
> +unsigned int and_lsr_or_shl0(unsigned int a, unsigned int b)
> +{
> +	return ((a | b << 12) >> 12) & 0xfff00000;
> +}
> +
> +/*
> + * check-name: and-lsr-or-shl0
> + * check-command: test-linearize -Wno-decl $file
> + * check-known-to-fail
> + *
> + * check-output-excludes: shl\\.
> + */
> diff --git a/validation/optim/and-lsr-or-shl1.c b/validation/optim/and-lsr-or-shl1.c
> new file mode 100644
> index 000000000000..6f2d05a0bfdd
> --- /dev/null
> +++ b/validation/optim/and-lsr-or-shl1.c
> @@ -0,0 +1,12 @@
> +unsigned int and_lsr_or_shl1(unsigned int a, unsigned int b)
> +{
> +	return ((a | b << 12) >> 12) & 0x000fffff;
> +}
> +
> +/*
> + * check-name: and-lsr-or-shl1
> + * check-command: test-linearize -Wno-decl $file
> + * check-known-to-fail
> + *
> + * check-output-excludes: shl\\.
> + */
> diff --git a/validation/optim/and-shl-or-lsr0.c b/validation/optim/and-shl-or-lsr0.c
> new file mode 100644
> index 000000000000..f2a7cc631258
> --- /dev/null
> +++ b/validation/optim/and-shl-or-lsr0.c
> @@ -0,0 +1,13 @@
> +unsigned and_shl_or_lsr0(unsigned a, unsigned b)
> +{
> +	return ((a | (b >> 12)) << 12) & 0xfff00000;
> +}
> +
> +/*
> + * check-name: and-shl-or-lsr0
> + * check-command: test-linearize -Wno-decl $file
> + * check-known-to-fail
> + *
> + * check-output-ignore
> + * check-output-excludes: or\\.
> + */
> diff --git a/validation/optim/lsr-or-lsr0.c b/validation/optim/lsr-or-lsr0.c
> new file mode 100644
> index 000000000000..a1687ec21ff0
> --- /dev/null
> +++ b/validation/optim/lsr-or-lsr0.c
> @@ -0,0 +1,20 @@
> +#define	S	12
> +
> +//	((x >> S') | y) >> S;
> +// ->	((x >> S >> S) | (y >> S)

// -> (x >> S' >> S) | (y >> S)
// -> (x >> (32 - S + S)) | (y >> S)
// -> (x >> 32) | (y >> S)
// -> (0) | (y >> S)
// -> y >> S

> +
> +int lsr_or_lsr0(unsigned int x, unsigned int b)
> +{
> +	return ((x >> (32 - S)) | b) >> S;
> +}
> +
> +/*
> + * check-name: lsr-or-lsr0
> + * check-command: test-linearize -Wno-decl $file
> + * check-known-to-fail
> + *
> + * check-output-ignore
> + * check-output-pattern(1): lsr\\.
> + * check-output-excludes: and\\.
> + * check-output-excludes: or\\.
> + */
> diff --git a/validation/optim/trunc-or-shl0.c b/validation/optim/trunc-or-shl0.c
> new file mode 100644
> index 000000000000..4d85a6bd4ec4
> --- /dev/null
> +++ b/validation/optim/trunc-or-shl0.c
> @@ -0,0 +1,19 @@
> +char trunc_or_shl0a(unsigned a, unsigned b)
> +{
> +	return (a << 8) | b;
> +}
> +
> +char trunc_or_shl0b(unsigned a, unsigned b)
> +{
> +	return a | (b << 8);
> +}
> +
> +/*
> + * check-name: trunc-or-shl0
> + * check-command: test-linearize -Wno-decl $file
> + * check-known-to-fail
> + *
> + * check-output-ignore
> + * check-output-excludes: or\\.
> + * check-output-excludes: shl\\.

Hmm, I can't see an optimization for these two! :(
Care to explain just what you expect? (maybe with an
'*.expected' file?)

> + */
> 

ATB,
Ramsay Jones


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] add more testcases for AND/OR simplification
  2020-09-06 16:38   ` Ramsay Jones
@ 2020-09-06 16:46     ` Ramsay Jones
  2020-09-06 19:10     ` Luc Van Oostenryck
  1 sibling, 0 replies; 11+ messages in thread
From: Ramsay Jones @ 2020-09-06 16:46 UTC (permalink / raw)
  To: Luc Van Oostenryck, linux-sparse



On 06/09/2020 17:38, Ramsay Jones wrote:
[snip]

>> diff --git a/validation/optim/trunc-or-shl0.c b/validation/optim/trunc-or-shl0.c
>> new file mode 100644
>> index 000000000000..4d85a6bd4ec4
>> --- /dev/null
>> +++ b/validation/optim/trunc-or-shl0.c
>> @@ -0,0 +1,19 @@
>> +char trunc_or_shl0a(unsigned a, unsigned b)
>> +{
>> +	return (a << 8) | b;
>> +}
>> +
>> +char trunc_or_shl0b(unsigned a, unsigned b)
>> +{
>> +	return a | (b << 8);
>> +}
>> +
>> +/*
>> + * check-name: trunc-or-shl0
>> + * check-command: test-linearize -Wno-decl $file
>> + * check-known-to-fail
>> + *
>> + * check-output-ignore
>> + * check-output-excludes: or\\.
>> + * check-output-excludes: shl\\.
> 
> Hmm, I can't see an optimization for these two! :(
> Care to explain just what you expect? (maybe with an
> '*.expected' file?)
> 

Ah, so I only just noticed the 'char' return types! :-D

OK.

ATB,
Ramsay Jones


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/3] add more testcases for existing AND/OR simplifications
  2020-09-06 16:12   ` Ramsay Jones
@ 2020-09-06 18:52     ` Luc Van Oostenryck
  0 siblings, 0 replies; 11+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 18:52 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: linux-sparse

Hi,

On Sun, Sep 06, 2020 at 05:12:40PM +0100, Ramsay Jones wrote:
> On 06/09/2020 13:40, Luc Van Oostenryck wrote:
> > Add a few more testcases to catch possible future regressions.
> > 
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> > ---
> >  validation/optim/and-shl-or-and0.c  | 13 +++++++++++++
> >  validation/optim/lsr-or-and0.c      | 23 +++++++++++++++++++++++
> >  validation/optim/shl-or-constant0.c | 12 ++++++++++++
> >  validation/optim/shl-or-constant1.c | 12 ++++++++++++
> >  validation/optim/shl-or-constant2.c | 12 ++++++++++++
> >  5 files changed, 72 insertions(+)
> >  create mode 100644 validation/optim/and-shl-or-and0.c
> >  create mode 100644 validation/optim/lsr-or-and0.c
> >  create mode 100644 validation/optim/shl-or-constant0.c
> >  create mode 100644 validation/optim/shl-or-constant1.c
> >  create mode 100644 validation/optim/shl-or-constant2.c
> > 
> > diff --git a/validation/optim/and-shl-or-and0.c b/validation/optim/and-shl-or-and0.c
> > new file mode 100644
> > index 000000000000..ea08d2622a95
> > --- /dev/null
> > +++ b/validation/optim/and-shl-or-and0.c
> > @@ -0,0 +1,13 @@
> > +unsigned and_shl_or_and0(unsigned a, unsigned b)
> > +{
> > +	return (((a & 0xfff00000) | b) << 12) & 0xfff00000;
> 
> ->(((a & 0xfff00000) << 12) | (b << 12)) & 0xfff00000
> ->(( 0 | (b << 12)) & 0xfff00000
> ->((b << 12)) & 0xfff00000
> > +}
> > +
> > +/*
> > + * check-name: and-shl-or-and0
> > + * check-command: test-linearize -Wno-decl $file
> > + *
> > + * check-output-ignore
> > + * check-output-excludes: or\\.
> > + * check-output-excludes: lsr\\.
> 
> why would there be a right-shift to begin with?
> (maybe add check-output-excludes: %arg1)

I'm not sure. It may be an error in the testcase, maybe a copy-paste
from some other tests, but I think it comes from some simplification
steps involving masks and shift and where a masking operation like
(x & 0xfff00000) is first virtually transformed into ((x >> 20) << 20)
before being simplified away.
Yes, checking the absence of %arg1 is a good idea.

> > + */
> > diff --git a/validation/optim/lsr-or-and0.c b/validation/optim/lsr-or-and0.c
> > new file mode 100644
> > index 000000000000..3c369cb9497e
> > --- /dev/null
> > +++ b/validation/optim/lsr-or-and0.c
> > @@ -0,0 +1,23 @@
> > +#define	S	12
> > +
> > +//	((x & M) | b) >> S;
> > +// ->	((x >> S) & (M >> S)) | (b >> S)
> 
> OK
> 
> > +// 0a:  (M >> S) == 0
> > +// 0b:  (x >> S) == 0
> > +// 0c:  (b >> S) == 0
> 
> I do not understand what these three lines are trying to say! :(

It's just some leftover of personal notes about the 3 opportunities 
of simplifications. It's probably best to remove.

> > +
> > +int lsr_or_and0a(unsigned int x, unsigned int b)
> 
> s/and0a/and0/ - was there an '_and0b' at one time?

Yes, most probably.

> > diff --git a/validation/optim/shl-or-constant2.c b/validation/optim/shl-or-constant2.c
> > new file mode 100644
> > index 000000000000..9dbde3b574d7
> > --- /dev/null
> > +++ b/validation/optim/shl-or-constant2.c
> > @@ -0,0 +1,12 @@
> > +unsigned shl_or_constant1(unsigned a)
> 
> s/_constant1/_constant2/

Yes, it's better so.

Thanks,
-- Luc 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] add more testcases for AND/OR simplification
  2020-09-06 16:38   ` Ramsay Jones
  2020-09-06 16:46     ` Ramsay Jones
@ 2020-09-06 19:10     ` Luc Van Oostenryck
  2020-09-06 20:12       ` Ramsay Jones
  1 sibling, 1 reply; 11+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 19:10 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: linux-sparse

On Sun, Sep 06, 2020 at 05:38:54PM +0100, Ramsay Jones wrote:
> 
> 
> On 06/09/2020 13:40, Luc Van Oostenryck wrote:
> > Add a few testcases showing the effectiveness of these
> > simplifications and to catch possible future regressions.
> > 
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> > ---
> >  validation/optim/and-lsr-or-shl0.c | 12 ++++++++++++
> >  validation/optim/and-lsr-or-shl1.c | 12 ++++++++++++
> >  validation/optim/and-shl-or-lsr0.c | 13 +++++++++++++
> >  validation/optim/lsr-or-lsr0.c     | 20 ++++++++++++++++++++
> >  validation/optim/trunc-or-shl0.c   | 19 +++++++++++++++++++
> >  5 files changed, 76 insertions(+)
> >  create mode 100644 validation/optim/and-lsr-or-shl0.c
> >  create mode 100644 validation/optim/and-lsr-or-shl1.c
> >  create mode 100644 validation/optim/and-shl-or-lsr0.c
> >  create mode 100644 validation/optim/lsr-or-lsr0.c
> >  create mode 100644 validation/optim/trunc-or-shl0.c
> 
> Given that these are new tests, I was (er..) expecting some
> '*.expected' files! However, I guess (since they are all failing
> tests anyway) those will come in future patches which will
> actually implement the optimization.

Yes, I've pending series for these (and a lot of others) which
more or less depends on these tests. For *.expected files, I really
want to avoid this because it would be more things that should be
kept up to date. I prefer to add some comments and use the patterns
tests, all n the same file.
 
> > diff --git a/validation/optim/trunc-or-shl0.c b/validation/optim/trunc-or-shl0.c
> > new file mode 100644
> > index 000000000000..4d85a6bd4ec4
> > --- /dev/null
> > +++ b/validation/optim/trunc-or-shl0.c
> > @@ -0,0 +1,19 @@
> > +char trunc_or_shl0a(unsigned a, unsigned b)
> > +{
> > +	return (a << 8) | b;
> > +}
> > +
> > +char trunc_or_shl0b(unsigned a, unsigned b)
> > +{
> > +	return a | (b << 8);
> > +}
> > +
> > +/*
> > + * check-name: trunc-or-shl0
> > + * check-command: test-linearize -Wno-decl $file
> > + * check-known-to-fail
> > + *
> > + * check-output-ignore
> > + * check-output-excludes: or\\.
> > + * check-output-excludes: shl\\.
> 
> Hmm, I can't see an optimization for these two! :(
> Care to explain just what you expect? (maybe with an
> '*.expected' file?)

I saw your other email about it but I just would like to add
these sort of tests should really be read at the IR level,
the output of 'test-linearize $file.c'. Sometimes, the C file
is just a convoluted way to create some specific sequence of
IR instructions. Also, often the name of the file and the
comments directly refer to these instructions (like here 'trunc'
for the instruction OP_TRUNC).

For the simplification phase, it would be nice and easier to be
able to do the tests directly in the IR format. It shouldn't take
much time but ... one day ... maybe :)

-- Luc

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] add more testcases for AND/OR simplification
  2020-09-06 19:10     ` Luc Van Oostenryck
@ 2020-09-06 20:12       ` Ramsay Jones
  2020-09-06 21:15         ` Luc Van Oostenryck
  0 siblings, 1 reply; 11+ messages in thread
From: Ramsay Jones @ 2020-09-06 20:12 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: linux-sparse



On 06/09/2020 20:10, Luc Van Oostenryck wrote:
> On Sun, Sep 06, 2020 at 05:38:54PM +0100, Ramsay Jones wrote:
>> On 06/09/2020 13:40, Luc Van Oostenryck wrote:

>> Hmm, I can't see an optimization for these two! :(
>> Care to explain just what you expect? (maybe with an
>> '*.expected' file?)
> 
> I saw your other email about it but I just would like to add
> these sort of tests should really be read at the IR level,
> the output of 'test-linearize $file.c'. Sometimes, the C file
> is just a convoluted way to create some specific sequence of
> IR instructions. Also, often the name of the file and the

Yeah, indeed - which is kinda why I would have liked to see
an '*.expected' file! It is just hard to try looking at the
C code and imagine the likely optimization opportunities and
the effect they have on the IR. :-D

Having said that, I do understand why you would rather not do
that. It just makes reviewing such patches a hard job, requiring
a bit of imagination (which I don't have!). :-P

> comments directly refer to these instructions (like here 'trunc'
> for the instruction OP_TRUNC).
> 
> For the simplification phase, it would be nice and easier to be
> able to do the tests directly in the IR format. It shouldn't take
> much time but ... one day ... maybe :)

yeah, we can dream! ;-)

ATB,
Ramsay Jones


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] add more testcases for AND/OR simplification
  2020-09-06 20:12       ` Ramsay Jones
@ 2020-09-06 21:15         ` Luc Van Oostenryck
  0 siblings, 0 replies; 11+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 21:15 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: linux-sparse

On Sun, Sep 06, 2020 at 09:12:21PM +0100, Ramsay Jones wrote:
> 
> 
> On 06/09/2020 20:10, Luc Van Oostenryck wrote:
> > On Sun, Sep 06, 2020 at 05:38:54PM +0100, Ramsay Jones wrote:
> >> On 06/09/2020 13:40, Luc Van Oostenryck wrote:
> 
> >> Hmm, I can't see an optimization for these two! :(
> >> Care to explain just what you expect? (maybe with an
> >> '*.expected' file?)
> > 
> > I saw your other email about it but I just would like to add
> > these sort of tests should really be read at the IR level,
> > the output of 'test-linearize $file.c'. Sometimes, the C file
> > is just a convoluted way to create some specific sequence of
> > IR instructions. Also, often the name of the file and the
> 
> Yeah, indeed - which is kinda why I would have liked to see
> an '*.expected' file! It is just hard to try looking at the
> C code and imagine the likely optimization opportunities and
> the effect they have on the IR. :-D
> 
> Having said that, I do understand why you would rather not do
> that. It just makes reviewing such patches a hard job, requiring

Yes, sorry. I realized this only now.

I've added a very small comment with the expected result to
the tests.

-- Luc

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-09-06 21:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-06 12:40 [PATCH 0/3] fix & extend mask related testcases Luc Van Oostenryck
2020-09-06 12:40 ` [PATCH 1/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
2020-09-06 16:12   ` Ramsay Jones
2020-09-06 18:52     ` Luc Van Oostenryck
2020-09-06 12:40 ` [PATCH 2/3] add more testcases for AND/OR simplification Luc Van Oostenryck
2020-09-06 16:38   ` Ramsay Jones
2020-09-06 16:46     ` Ramsay Jones
2020-09-06 19:10     ` Luc Van Oostenryck
2020-09-06 20:12       ` Ramsay Jones
2020-09-06 21:15         ` Luc Van Oostenryck
2020-09-06 12:40 ` [PATCH 3/3] optim: fix some testcases related to bitfield manipulation Luc Van Oostenryck

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).