public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]middle-end: fix epilog reductions when vector iters peeled [PR113364]
@ 2024-01-23 15:40 Tamar Christina
  2024-01-23 15:41 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Tamar Christina @ 2024-01-23 15:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, rguenther, jlaw

[-- Attachment #1: Type: text/plain, Size: 2542 bytes --]

Hi All,

This fixes a bug where vect_create_epilog_for_reduction does not handle the
case where all exits are early exits.  In this case we should do like induction
handling code does and not have a main exit.

Bootstrapped Regtested on x86_64-pc-linux-gnu
with --enable-checking=release --enable-lto --with-arch=native
--with-build-config=bootstrap-O3 --enable-checking=yes,rtl,extra.

This shows that some new miscompiles are happening (stage3 is likely miscompiled)
but that's unrelated to this patch and I'll look at it next.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	PR tree-optimization/113364
	* tree-vect-loop.cc (vect_create_epilog_for_reduction): If all exits all
	early exits then we must reduce from the first offset for all of them.

gcc/testsuite/ChangeLog:

	PR tree-optimization/113364
	* gcc.dg/vect/vect-early-break_107-pr113364.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c
new file mode 100644
index 0000000000000000000000000000000000000000..f489265dbfe5eb8fe302dcc34901abaf6e6d5c14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-w" } */
+
+typedef const unsigned char *It;
+It DecodeSLEB128(It begin, It end, int *v) {
+  int value = 0;
+  unsigned shift = 0;
+  unsigned char byte;
+  do
+  {
+    if (begin == end)
+      return begin;
+    byte = *(begin++);
+    int slice = byte & 0x7f;
+    value |= slice << shift;
+  } while (byte >= 128);
+  *v = value;
+  return begin;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index fe631252dc2258e8ea42179b4ba068a480be9e38..4da1421c8f09746ef4b293573e4f861b642349e1 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -5982,7 +5982,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
      loop-closed PHI of the inner loop which we remember as
      def for the reduction PHI generation.  */
   bool double_reduc = false;
-  bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit;
+  bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit
+		     && !LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo);
   stmt_vec_info rdef_info = stmt_info;
   if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_double_reduction_def)
     {




-- 

[-- Attachment #2: rb18197.patch --]
[-- Type: text/plain, Size: 1640 bytes --]

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c
new file mode 100644
index 0000000000000000000000000000000000000000..f489265dbfe5eb8fe302dcc34901abaf6e6d5c14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-w" } */
+
+typedef const unsigned char *It;
+It DecodeSLEB128(It begin, It end, int *v) {
+  int value = 0;
+  unsigned shift = 0;
+  unsigned char byte;
+  do
+  {
+    if (begin == end)
+      return begin;
+    byte = *(begin++);
+    int slice = byte & 0x7f;
+    value |= slice << shift;
+  } while (byte >= 128);
+  *v = value;
+  return begin;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index fe631252dc2258e8ea42179b4ba068a480be9e38..4da1421c8f09746ef4b293573e4f861b642349e1 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -5982,7 +5982,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
      loop-closed PHI of the inner loop which we remember as
      def for the reduction PHI generation.  */
   bool double_reduc = false;
-  bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit;
+  bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit
+		     && !LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo);
   stmt_vec_info rdef_info = stmt_info;
   if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_double_reduction_def)
     {




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

* Re: [PATCH]middle-end: fix epilog reductions when vector iters peeled [PR113364]
  2024-01-23 15:40 [PATCH]middle-end: fix epilog reductions when vector iters peeled [PR113364] Tamar Christina
@ 2024-01-23 15:41 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-01-23 15:41 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd, jlaw

On Tue, 23 Jan 2024, Tamar Christina wrote:

> Hi All,
> 
> This fixes a bug where vect_create_epilog_for_reduction does not handle the
> case where all exits are early exits.  In this case we should do like induction
> handling code does and not have a main exit.
> 
> Bootstrapped Regtested on x86_64-pc-linux-gnu
> with --enable-checking=release --enable-lto --with-arch=native
> --with-build-config=bootstrap-O3 --enable-checking=yes,rtl,extra.
> 
> This shows that some new miscompiles are happening (stage3 is likely miscompiled)
> but that's unrelated to this patch and I'll look at it next.
> 
> Ok for master?

OK, but can you, as followup, change the name of main_exit_p which
doesn't reflect how it's computed now?

> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/113364
> 	* tree-vect-loop.cc (vect_create_epilog_for_reduction): If all exits all
> 	early exits then we must reduce from the first offset for all of them.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/113364
> 	* gcc.dg/vect/vect-early-break_107-pr113364.c: New test.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..f489265dbfe5eb8fe302dcc34901abaf6e6d5c14
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c
> @@ -0,0 +1,22 @@
> +/* { dg-do compile } */
> +/* { dg-add-options vect_early_break } */
> +/* { dg-require-effective-target vect_early_break } */
> +/* { dg-require-effective-target vect_int } */
> +/* { dg-additional-options "-w" } */
> +
> +typedef const unsigned char *It;
> +It DecodeSLEB128(It begin, It end, int *v) {
> +  int value = 0;
> +  unsigned shift = 0;
> +  unsigned char byte;
> +  do
> +  {
> +    if (begin == end)
> +      return begin;
> +    byte = *(begin++);
> +    int slice = byte & 0x7f;
> +    value |= slice << shift;
> +  } while (byte >= 128);
> +  *v = value;
> +  return begin;
> +}
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index fe631252dc2258e8ea42179b4ba068a480be9e38..4da1421c8f09746ef4b293573e4f861b642349e1 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -5982,7 +5982,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
>       loop-closed PHI of the inner loop which we remember as
>       def for the reduction PHI generation.  */
>    bool double_reduc = false;
> -  bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit;
> +  bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit
> +		     && !LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo);
>    stmt_vec_info rdef_info = stmt_info;
>    if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_double_reduction_def)
>      {
> 
> 
> 
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

end of thread, other threads:[~2024-01-23 15:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-23 15:40 [PATCH]middle-end: fix epilog reductions when vector iters peeled [PR113364] Tamar Christina
2024-01-23 15:41 ` 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).