public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] middle-end/106630 - avoid ping-pong between extract_muldiv and match.pd
@ 2022-08-16  9:19 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-08-16  9:19 UTC (permalink / raw)
  To: gcc-patches

The following avoids ping-pong between the match.pd pattern changing
(sizetype) ((a_9 + 1) * 48) to (sizetype)(a_9 + 1) * 48 and
extract_muldiv performing the reverse transform by restricting the
match.pd pattern to narrowing conversions as the comment indicates.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR middle-end/106630
	* match.pd ((T)(x * CST) -> (T)x * CST): Restrict to
	narrowing conversions.

	* gcc.dg/torture/pr106630.c: New testcase.
---
 gcc/match.pd                            |  2 +-
 gcc/testsuite/gcc.dg/torture/pr106630.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106630.c

diff --git a/gcc/match.pd b/gcc/match.pd
index e32bda64e64..07d0a61fc3a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1917,7 +1917,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2))
  (if (INTEGRAL_TYPE_P (type)
       && INTEGRAL_TYPE_P (TREE_TYPE (@0))
-      && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0)))
+      && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)))
   (mult (convert @1) (convert @2))))
 
 /* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p.
diff --git a/gcc/testsuite/gcc.dg/torture/pr106630.c b/gcc/testsuite/gcc.dg/torture/pr106630.c
new file mode 100644
index 00000000000..d608b9151be
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106630.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+short d, e;
+int f;
+extern short g[][24];
+char c;
+void h() {
+  char a = 6;
+  c = a;
+  for (unsigned long a = (d || e) - 1; a < c; a += f)
+    for (signed b = 0; b < 24; b++)
+      g[a][b] = 4;
+}
-- 
2.35.3

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

* [PATCH] middle-end/106630 - avoid ping-pong between extract_muldiv and match.pd
@ 2022-08-16  9:19 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-08-16  9:19 UTC (permalink / raw)
  To: gcc-patches

The following avoids ping-pong between the match.pd pattern changing
(sizetype) ((a_9 + 1) * 48) to (sizetype)(a_9 + 1) * 48 and
extract_muldiv performing the reverse transform by restricting the
match.pd pattern to narrowing conversions as the comment indicates.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR middle-end/106630
	* match.pd ((T)(x * CST) -> (T)x * CST): Restrict to
	narrowing conversions.

	* gcc.dg/torture/pr106630.c: New testcase.
---
 gcc/match.pd                            |  2 +-
 gcc/testsuite/gcc.dg/torture/pr106630.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106630.c

diff --git a/gcc/match.pd b/gcc/match.pd
index e32bda64e64..07d0a61fc3a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1917,7 +1917,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2))
  (if (INTEGRAL_TYPE_P (type)
       && INTEGRAL_TYPE_P (TREE_TYPE (@0))
-      && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0)))
+      && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)))
   (mult (convert @1) (convert @2))))
 
 /* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p.
diff --git a/gcc/testsuite/gcc.dg/torture/pr106630.c b/gcc/testsuite/gcc.dg/torture/pr106630.c
new file mode 100644
index 00000000000..d608b9151be
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106630.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+short d, e;
+int f;
+extern short g[][24];
+char c;
+void h() {
+  char a = 6;
+  c = a;
+  for (unsigned long a = (d || e) - 1; a < c; a += f)
+    for (signed b = 0; b < 24; b++)
+      g[a][b] = 4;
+}
-- 
2.35.3

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

* [PATCH] middle-end/106630 - avoid ping-pong between extract_muldiv and match.pd
@ 2022-08-16  9:19 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-08-16  9:19 UTC (permalink / raw)
  To: gcc-patches

The following avoids ping-pong between the match.pd pattern changing
(sizetype) ((a_9 + 1) * 48) to (sizetype)(a_9 + 1) * 48 and
extract_muldiv performing the reverse transform by restricting the
match.pd pattern to narrowing conversions as the comment indicates.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR middle-end/106630
	* match.pd ((T)(x * CST) -> (T)x * CST): Restrict to
	narrowing conversions.

	* gcc.dg/torture/pr106630.c: New testcase.
---
 gcc/match.pd                            |  2 +-
 gcc/testsuite/gcc.dg/torture/pr106630.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106630.c

diff --git a/gcc/match.pd b/gcc/match.pd
index e32bda64e64..07d0a61fc3a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1917,7 +1917,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2))
  (if (INTEGRAL_TYPE_P (type)
       && INTEGRAL_TYPE_P (TREE_TYPE (@0))
-      && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0)))
+      && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)))
   (mult (convert @1) (convert @2))))
 
 /* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p.
diff --git a/gcc/testsuite/gcc.dg/torture/pr106630.c b/gcc/testsuite/gcc.dg/torture/pr106630.c
new file mode 100644
index 00000000000..d608b9151be
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106630.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+short d, e;
+int f;
+extern short g[][24];
+char c;
+void h() {
+  char a = 6;
+  c = a;
+  for (unsigned long a = (d || e) - 1; a < c; a += f)
+    for (signed b = 0; b < 24; b++)
+      g[a][b] = 4;
+}
-- 
2.35.3

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

end of thread, other threads:[~2022-08-16  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16  9:19 [PATCH] middle-end/106630 - avoid ping-pong between extract_muldiv and match.pd Richard Biener
  -- strict thread matches above, loose matches on Subject: below --
2022-08-16  9:19 Richard Biener
2022-08-16  9:19 Richard Biener

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 read-only IMAP folder(s) and NNTP newsgroup(s).