diff mbox series

[1/3] add more testcases for existing AND/OR simplifications

Message ID 20200906124038.46786-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series fix & extend mask related testcases | expand

Commit Message

Luc Van Oostenryck Sept. 6, 2020, 12:40 p.m. UTC
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

Comments

Ramsay Jones Sept. 6, 2020, 4:12 p.m. UTC | #1
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
Luc Van Oostenryck Sept. 6, 2020, 6:52 p.m. UTC | #2
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
diff mbox series

Patch

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