linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] fix & extend mask related testcases
@ 2020-09-06 21:16 Luc Van Oostenryck
  2020-09-06 21:16 ` [PATCH v2 1/3] optim: fix some testcases related to bitfield manipulation Luc Van Oostenryck
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 21:16 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, Luc Van Oostenryck

This is a preparatory step for some incoming series.

Changes since v1:
* take in account Ramsay's remarks:
  * add some short explanation of the expected simplification
  * add a few tests of the absence of %arg[12]
  * s/shl_or_constant1/shl_or_constant2/ in shl_or_constant2.c
* move patch fixng existing testcases first.

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

 validation/optim/and-lsr-or-shl0.c  | 13 +++++++++++++
 validation/optim/and-lsr-or-shl1.c  | 13 +++++++++++++
 validation/optim/and-shl-or-and0.c  | 15 +++++++++++++++
 validation/optim/and-shl-or-lsr0.c  | 13 +++++++++++++
 validation/optim/lsr-or-and0.c      | 22 ++++++++++++++++++++++
 validation/optim/lsr-or-lsr0.c      | 22 ++++++++++++++++++++++
 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     |  7 ++++++-
 validation/optim/trunc-or-shl0.c    | 22 ++++++++++++++++++++++
 12 files changed, 165 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] 9+ messages in thread

* [PATCH v2 1/3] optim: fix some testcases related to bitfield manipulation
  2020-09-06 21:16 [PATCH v2 0/3] fix & extend mask related testcases Luc Van Oostenryck
@ 2020-09-06 21:16 ` Luc Van Oostenryck
  2020-09-06 21:16 ` [PATCH v2 2/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
  2020-09-06 21:16 ` [PATCH v2 3/3] add more testcases for AND/OR simplification Luc Van Oostenryck
  2 siblings, 0 replies; 9+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 21:16 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, 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 | 7 ++++++-
 2 files changed, 9 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..04bc8383a81e 100644
--- a/validation/optim/trunc-or-shl.c
+++ b/validation/optim/trunc-or-shl.c
@@ -1,3 +1,5 @@
+// => TRUNC(b, 8)
+
 char foo(int a, int b)
 {
 	return (a << 8) | b;
@@ -9,5 +11,8 @@ 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\\.
+ * check-output-excludes: %arg1\\.
  */
-- 
2.28.0


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

* [PATCH v2 2/3] add more testcases for existing AND/OR simplifications
  2020-09-06 21:16 [PATCH v2 0/3] fix & extend mask related testcases Luc Van Oostenryck
  2020-09-06 21:16 ` [PATCH v2 1/3] optim: fix some testcases related to bitfield manipulation Luc Van Oostenryck
@ 2020-09-06 21:16 ` Luc Van Oostenryck
  2020-09-06 21:54   ` Ramsay Jones
  2020-09-06 21:16 ` [PATCH v2 3/3] add more testcases for AND/OR simplification Luc Van Oostenryck
  2 siblings, 1 reply; 9+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 21:16 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, 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  | 15 +++++++++++++++
 validation/optim/lsr-or-and0.c      | 22 ++++++++++++++++++++++
 validation/optim/shl-or-constant0.c | 12 ++++++++++++
 validation/optim/shl-or-constant1.c | 12 ++++++++++++
 validation/optim/shl-or-constant2.c | 12 ++++++++++++
 5 files changed, 73 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..298dcb434fc7
--- /dev/null
+++ b/validation/optim/and-shl-or-and0.c
@@ -0,0 +1,15 @@
+// =>	(b << 12) & 0xfff00000
+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\\.
+ * 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..fe3a2649eea2
--- /dev/null
+++ b/validation/optim/lsr-or-and0.c
@@ -0,0 +1,22 @@
+#define	S	12
+
+//	((x & M) | b) >> S;
+// ->	((x >> S) & (M >> S)) | (b >> S)
+// but	(M >> S) == 0
+// =>	(b >> S)
+
+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..d4618eb1bab8
--- /dev/null
+++ b/validation/optim/shl-or-constant2.c
@@ -0,0 +1,12 @@
+unsigned shl_or_constant2(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] 9+ messages in thread

* [PATCH v2 3/3] add more testcases for AND/OR simplification
  2020-09-06 21:16 [PATCH v2 0/3] fix & extend mask related testcases Luc Van Oostenryck
  2020-09-06 21:16 ` [PATCH v2 1/3] optim: fix some testcases related to bitfield manipulation Luc Van Oostenryck
  2020-09-06 21:16 ` [PATCH v2 2/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
@ 2020-09-06 21:16 ` Luc Van Oostenryck
  2020-09-07  0:15   ` Ramsay Jones
  2 siblings, 1 reply; 9+ messages in thread
From: Luc Van Oostenryck @ 2020-09-06 21:16 UTC (permalink / raw)
  To: linux-sparse; +Cc: Ramsay Jones, 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 | 13 +++++++++++++
 validation/optim/and-lsr-or-shl1.c | 13 +++++++++++++
 validation/optim/and-shl-or-lsr0.c | 13 +++++++++++++
 validation/optim/lsr-or-lsr0.c     | 22 ++++++++++++++++++++++
 validation/optim/trunc-or-shl0.c   | 22 ++++++++++++++++++++++
 5 files changed, 83 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..46ab1bde5249
--- /dev/null
+++ b/validation/optim/and-lsr-or-shl0.c
@@ -0,0 +1,13 @@
+// =>	0
+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..22fee362b16b
--- /dev/null
+++ b/validation/optim/and-lsr-or-shl1.c
@@ -0,0 +1,13 @@
+// =>	(((a | b << 12) >> 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..aad4aa7fda56
--- /dev/null
+++ b/validation/optim/lsr-or-lsr0.c
@@ -0,0 +1,22 @@
+#define	S	12
+
+//	((x >> S') | y) >> S;
+// ->	((x >> S' >> S) | (y >> S)
+// ->	((x >> 32) | (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..ab92aca1b711
--- /dev/null
+++ b/validation/optim/trunc-or-shl0.c
@@ -0,0 +1,22 @@
+// => TRUNC(b, 8)
+char trunc_or_shl0a(unsigned a, unsigned b)
+{
+	return (a << 8) | b;
+}
+
+// => TRUNC(a, 8)
+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\\.
+ * check-output-pattern(2): %arg
+ */
-- 
2.28.0


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

* Re: [PATCH v2 2/3] add more testcases for existing AND/OR simplifications
  2020-09-06 21:16 ` [PATCH v2 2/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
@ 2020-09-06 21:54   ` Ramsay Jones
  2020-09-07 22:28     ` Luc Van Oostenryck
  0 siblings, 1 reply; 9+ messages in thread
From: Ramsay Jones @ 2020-09-06 21:54 UTC (permalink / raw)
  To: Luc Van Oostenryck, linux-sparse



On 06/09/2020 22:16, 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  | 15 +++++++++++++++
>  validation/optim/lsr-or-and0.c      | 22 ++++++++++++++++++++++
>  validation/optim/shl-or-constant0.c | 12 ++++++++++++
>  validation/optim/shl-or-constant1.c | 12 ++++++++++++
>  validation/optim/shl-or-constant2.c | 12 ++++++++++++
>  5 files changed, 73 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..298dcb434fc7
> --- /dev/null
> +++ b/validation/optim/and-shl-or-and0.c
> @@ -0,0 +1,15 @@
> +// =>	(b << 12) & 0xfff00000
> +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\\.

Hmm, this still doesn't sit right - have you discovered the
reason for this?

> + * 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..fe3a2649eea2
> --- /dev/null
> +++ b/validation/optim/lsr-or-and0.c
> @@ -0,0 +1,22 @@
> +#define	S	12
> +
> +//	((x & M) | b) >> S;
> +// ->	((x >> S) & (M >> S)) | (b >> S)
> +// but	(M >> S) == 0
> +// =>	(b >> S)

yep, better.

ATB,
Ramsay Jones

> +
> +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..d4618eb1bab8
> --- /dev/null
> +++ b/validation/optim/shl-or-constant2.c
> @@ -0,0 +1,12 @@
> +unsigned shl_or_constant2(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
> + */
> 

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

* Re: [PATCH v2 3/3] add more testcases for AND/OR simplification
  2020-09-06 21:16 ` [PATCH v2 3/3] add more testcases for AND/OR simplification Luc Van Oostenryck
@ 2020-09-07  0:15   ` Ramsay Jones
  2020-09-07 22:21     ` Luc Van Oostenryck
  0 siblings, 1 reply; 9+ messages in thread
From: Ramsay Jones @ 2020-09-07  0:15 UTC (permalink / raw)
  To: Luc Van Oostenryck, linux-sparse



On 06/09/2020 22:16, Luc Van Oostenryck wrote:
> Add a few testcases showing the effectiveness of these
> simplifications and to catch possible future regressions.
> 

Sorry, I had to step away from the keyboard for a couple
of hours ...

> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  validation/optim/and-lsr-or-shl0.c | 13 +++++++++++++
>  validation/optim/and-lsr-or-shl1.c | 13 +++++++++++++
>  validation/optim/and-shl-or-lsr0.c | 13 +++++++++++++
>  validation/optim/lsr-or-lsr0.c     | 22 ++++++++++++++++++++++
>  validation/optim/trunc-or-shl0.c   | 22 ++++++++++++++++++++++
>  5 files changed, 83 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..46ab1bde5249
> --- /dev/null
> +++ b/validation/optim/and-lsr-or-shl0.c
> @@ -0,0 +1,13 @@
> +// =>	0
> +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\\.

Why not something like:
  * check-output-contains: ret.32 *\\$0
  * check-output-excludes: shl\\.
  * check-output-excludes: or\\.
  * check-output-excludes: lsr\\.
  * check-output-excludes: and\\.

> + */
> diff --git a/validation/optim/and-lsr-or-shl1.c b/validation/optim/and-lsr-or-shl1.c
> new file mode 100644
> index 000000000000..22fee362b16b
> --- /dev/null
> +++ b/validation/optim/and-lsr-or-shl1.c
> @@ -0,0 +1,13 @@
> +// =>	(((a | b << 12) >> 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\\.

Hmm, this should be ': and\\.' right?

> + */
> 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 @@

Hmm, I can't see the optimization, just ...

> +unsigned and_shl_or_lsr0(unsigned a, unsigned b)
> +{
> +	return ((a | (b >> 12)) << 12) & 0xfff00000;

->((a << 12) | ((b >> 12) << 12)) & 0xfff00000
->((a << 12) | b) & 0xfff00000
so that ...

> +}
> +
> +/*
> + * check-name: and-shl-or-lsr0
> + * check-command: test-linearize -Wno-decl $file
> + * check-known-to-fail
> + *
> + * check-output-ignore
> + * check-output-excludes: or\\.

... this wouldn't be correct. puzzled! :(

> + */
> diff --git a/validation/optim/lsr-or-lsr0.c b/validation/optim/lsr-or-lsr0.c
> new file mode 100644
> index 000000000000..aad4aa7fda56
> --- /dev/null
> +++ b/validation/optim/lsr-or-lsr0.c
> @@ -0,0 +1,22 @@
> +#define	S	12
> +
> +//	((x >> S') | y) >> S;
> +// ->	((x >> S' >> S) | (y >> S)

s/((x/(x/

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

s/((x/(x/

> +// =>	(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\\.

why would an 'and' be here anyway?

> + * 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..ab92aca1b711
> --- /dev/null
> +++ b/validation/optim/trunc-or-shl0.c
> @@ -0,0 +1,22 @@
> +// => TRUNC(b, 8)
> +char trunc_or_shl0a(unsigned a, unsigned b)
> +{
> +	return (a << 8) | b;
> +}
> +
> +// => TRUNC(a, 8)
> +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\\.
> + * check-output-pattern(2): %arg

OK, good.

> + */
> 

ATB,
Ramsay Jones


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

* Re: [PATCH v2 3/3] add more testcases for AND/OR simplification
  2020-09-07  0:15   ` Ramsay Jones
@ 2020-09-07 22:21     ` Luc Van Oostenryck
  2020-09-08 15:39       ` Ramsay Jones
  0 siblings, 1 reply; 9+ messages in thread
From: Luc Van Oostenryck @ 2020-09-07 22:21 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: linux-sparse

On Mon, Sep 07, 2020 at 01:15:18AM +0100, Ramsay Jones wrote:
> On 06/09/2020 22:16, Luc Van Oostenryck wrote:
> > Add a few testcases showing the effectiveness of these
> > simplifications and to catch possible future regressions.
> > 
> 
> Sorry, I had to step away from the keyboard for a couple
> of hours ...

No, problem, of course.
 
> > diff --git a/validation/optim/and-lsr-or-shl0.c b/validation/optim/and-lsr-or-shl0.c
> > new file mode 100644
> > index 000000000000..46ab1bde5249
> > --- /dev/null
> > +++ b/validation/optim/and-lsr-or-shl0.c
> > @@ -0,0 +1,13 @@
> > +// =>	0
> > +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\\.
> 
> Why not something like:
>   * check-output-contains: ret.32 *\\$0

Yes, at the end this check is the only thing that matters. And since
it's all pure expressions, if there is a return with a constant,
no other instructions can possibly be present.

>   * check-output-excludes: shl\\.
>   * check-output-excludes: or\\.
>   * check-output-excludes: lsr\\.
>   * check-output-excludes: and\\.

But these tests were written (more than 2 years ago, so I forgot the
details about them) for very specific steps in the simplification
phase, most probably aiming bitfields (hence the constant shifts &
masks). In this case it was for a simplification that removed the '<<'.

> > diff --git a/validation/optim/and-lsr-or-shl1.c b/validation/optim/and-lsr-or-shl1.c
> > new file mode 100644
> > index 000000000000..22fee362b16b
> > --- /dev/null
> > +++ b/validation/optim/and-lsr-or-shl1.c
> > @@ -0,0 +1,13 @@
> > +// =>	(((a | b << 12) >> 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\\.
> 
> Hmm, this should be ': and\\.' right?

My intention was most certainly to test the shl but my comment
here above is wrong. It should have been:
	//	((a | (b << 12)) >> 12) & 0x000fffff
	// ->	((a >> S) | ((b << S) >> S)) & 0x000fffff
	// ->	((a >> S) | (b & 0x000fffff)) & 0x000fffff
	// =>	((a >> S) | b) & 0x000fffff
	// or	(a >> S) | (b & 0x000fffff)

> > 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 @@
> 
> Hmm, I can't see the optimization, just ...
> 
> > +unsigned and_shl_or_lsr0(unsigned a, unsigned b)
> > +{
> > +	return ((a | (b >> 12)) << 12) & 0xfff00000;
> 
> ->((a << 12) | ((b >> 12) << 12)) & 0xfff00000
> ->((a << 12) | b) & 0xfff00000
> so that ...
> > +}
> > +
> > +/*
> > + * check-name: and-shl-or-lsr0
> > + * check-command: test-linearize -Wno-decl $file
> > + * check-known-to-fail
> > + *
> > + * check-output-ignore
> > + * check-output-excludes: or\\.
> 
> ... this wouldn't be correct. puzzled! :(

Indeed, I probably meant 0x00000fff instead of 0xfff00000
	//	((a | (b >> S)) << S) & 0x00000fff
	// ->	((a << S) | ((b >> S) << S)) & 0x00000fff
	// ->	((a << S) | (b & 0xfffff000)) & 0x00000fff
	// ->	(a << S) & 0x00000fff
and then:
	// =>	0

> > diff --git a/validation/optim/lsr-or-lsr0.c b/validation/optim/lsr-or-lsr0.c
> > new file mode 100644
> > index 000000000000..aad4aa7fda56
> > --- /dev/null
> > +++ b/validation/optim/lsr-or-lsr0.c
> > @@ -0,0 +1,22 @@
> > +#define	S	12
> > +
> > +//	((x >> S') | y) >> S;
> > +// ->	((x >> S' >> S) | (y >> S)
> 
> s/((x/(x/
> 
> > +// ->	((x >> 32) | (y >> S)
> 
> s/((x/(x/
> 
> > +// =>	(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\\.
> 
> why would an 'and' be here anyway?

Because each shift has a implicit mask associated with it:
	(x >> S) == ((x & 0xffffffff) >> S) == (x >> S) & 0x000fffff
In some simplifications I made, it becomes an explicit mask and
sometimes there was a left-over. But yes, it's not very interesting here.

Thanks for noticing all this. I'll sort & reorganize them.

-- Luc

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

* Re: [PATCH v2 2/3] add more testcases for existing AND/OR simplifications
  2020-09-06 21:54   ` Ramsay Jones
@ 2020-09-07 22:28     ` Luc Van Oostenryck
  0 siblings, 0 replies; 9+ messages in thread
From: Luc Van Oostenryck @ 2020-09-07 22:28 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: linux-sparse

On Sun, Sep 06, 2020 at 10:54:25PM +0100, Ramsay Jones wrote:
> > 
> > diff --git a/validation/optim/and-shl-or-and0.c b/validation/optim/and-shl-or-and0.c
> > new file mode 100644
> > index 000000000000..298dcb434fc7
> > --- /dev/null
> > +++ b/validation/optim/and-shl-or-and0.c
> > @@ -0,0 +1,15 @@
> > +// =>	(b << 12) & 0xfff00000
> > +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\\.
> 
> Hmm, this still doesn't sit right - have you discovered the
> reason for this?

Sorry, I don't understand what I can add.
Such expressions are simplified into something where the OR and
the LSR are absent. This is what is checked by the test.
 
-- Luc

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

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



On 07/09/2020 23:21, Luc Van Oostenryck wrote:

>>> diff --git a/validation/optim/and-lsr-or-shl0.c b/validation/optim/and-lsr-or-shl0.c
>>> new file mode 100644
>>> index 000000000000..46ab1bde5249
>>> --- /dev/null
>>> +++ b/validation/optim/and-lsr-or-shl0.c
>>> @@ -0,0 +1,13 @@
>>> +// =>	0
>>> +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\\.
>>
>> Why not something like:
>>   * check-output-contains: ret.32 *\\$0
> 
> Yes, at the end this check is the only thing that matters. And since
> it's all pure expressions, if there is a return with a constant,
> no other instructions can possibly be present.

:-D 

OK, so let's imagine there is a bug (perhaps an off-by-one, say)
that results in some IR _not_ being removed properly, will this
test catch that? Does it matter? why not?

Given that you don't provide an '*.expected' file, adding the
following to the test won't guarantee to catch that bug either,
but would hopefully increase the odds. (this assumes that the
pre-optimization pass IR contains 'shl', 'or', 'lsr' and 'and',
of course).

> 
>>   * check-output-excludes: shl\\.
>>   * check-output-excludes: or\\.
>>   * check-output-excludes: lsr\\.
>>   * check-output-excludes: and\\.
> 
> But these tests were written (more than 2 years ago, so I forgot the
> details about them) for very specific steps in the simplification
> phase, most probably aiming bitfields (hence the constant shifts &
> masks). In this case it was for a simplification that removed the '<<'.> 
[snip]

>>> diff --git a/validation/optim/lsr-or-lsr0.c b/validation/optim/lsr-or-lsr0.c
>>> new file mode 100644
>>> index 000000000000..aad4aa7fda56
>>> --- /dev/null
>>> +++ b/validation/optim/lsr-or-lsr0.c
>>> @@ -0,0 +1,22 @@
>>> +#define	S	12
>>> +
>>> +//	((x >> S') | y) >> S;
>>> +// ->	((x >> S' >> S) | (y >> S)
>>
>> s/((x/(x/
>>
>>> +// ->	((x >> 32) | (y >> S)
>>
>> s/((x/(x/
>>
>>> +// =>	(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\\.
>>
>> why would an 'and' be here anyway?
> 
> Because each shift has a implicit mask associated with it:
> 	(x >> S) == ((x & 0xffffffff) >> S) == (x >> S) & 0x000fffff
> In some simplifications I made, it becomes an explicit mask and
> sometimes there was a left-over. But yes, it's not very interesting here.

;-P

So, imagine you didn't know the inner workings of the
optimization code, looking at the test text alone, would
you understand why the test asserts what it does?
(The input IR to the algorithm doesn't have an 'and', right?)

[Similar comment about other email on patch #2, the input IR
doesn't have an 'lsr', right?]

OK, I promise not to comment further on this series! ;-)

ATB,
Ramsay Jones

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

end of thread, other threads:[~2020-09-08 19:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-06 21:16 [PATCH v2 0/3] fix & extend mask related testcases Luc Van Oostenryck
2020-09-06 21:16 ` [PATCH v2 1/3] optim: fix some testcases related to bitfield manipulation Luc Van Oostenryck
2020-09-06 21:16 ` [PATCH v2 2/3] add more testcases for existing AND/OR simplifications Luc Van Oostenryck
2020-09-06 21:54   ` Ramsay Jones
2020-09-07 22:28     ` Luc Van Oostenryck
2020-09-06 21:16 ` [PATCH v2 3/3] add more testcases for AND/OR simplification Luc Van Oostenryck
2020-09-07  0:15   ` Ramsay Jones
2020-09-07 22:21     ` Luc Van Oostenryck
2020-09-08 15:39       ` Ramsay Jones

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