public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [ICE] Check another epilog variable peeling case in vectorizable_nonlinear_induction.
@ 2022-09-14  1:25 liuhongt
  2022-09-14  6:11 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: liuhongt @ 2022-09-14  1:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: crazylht, hjl.tools

In vectorizable_nonlinear_induction, r13-2503-gc13223b790bbc5 prevent variable peeling by
only checking LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo). But when
"!vect_use_loop_mask_for_alignment_p (loop_vinfo) &&
LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0", vectorizer will
still do variable peeling for epilog, and it hits gcc_assert in
vect_peel_nonlinear_iv_init.


Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
The patch also fix ICE of the testcase in the PR for ia64-linux-gnu(verified by cross-compile).

Ok for trunk?

gcc/ChangeLog:

	PR tree-optimization/106905
	* tree-vect-loop.cc (vectorizable_nonlinear_induction): Return
	false when !vect_use_loop_mask_for_alignment_p (loop_vinfo) &&
	LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr106905.c: New test.
	* gcc.target/ia64/pr106905.c: New test.
---
 gcc/testsuite/gcc.target/i386/pr106905.c | 14 ++++++++++++++
 gcc/testsuite/gcc.target/ia64/pr106905.c | 20 ++++++++++++++++++++
 gcc/tree-vect-loop.cc                    |  6 ++++--
 3 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr106905.c
 create mode 100644 gcc/testsuite/gcc.target/ia64/pr106905.c

diff --git a/gcc/testsuite/gcc.target/i386/pr106905.c b/gcc/testsuite/gcc.target/i386/pr106905.c
new file mode 100644
index 00000000000..a190a1c84e6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr106905.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=silvermont -O2 -fvect-cost-model=dynamic" } */
+
+void
+foo_mul_peel (int *a, int b)
+{
+  int i;
+
+  for (i = 0; i < 7; ++i)
+    {
+      b *= 2;
+      a[i] = b;
+    }
+}
diff --git a/gcc/testsuite/gcc.target/ia64/pr106905.c b/gcc/testsuite/gcc.target/ia64/pr106905.c
new file mode 100644
index 00000000000..1b9656e1203
--- /dev/null
+++ b/gcc/testsuite/gcc.target/ia64/pr106905.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -O3 -fPIC" } */
+long ZDICT_fillNoise_p, ZDICT_trainFromBuffer_legacy_result;
+unsigned ZDICT_fillNoise_acc;
+int ZDICT_totalSampleSize_nbFiles;
+static void ZDICT_fillNoise(void *buffer, long length) {
+  unsigned prime2 = 9;
+  for (ZDICT_fillNoise_p = 0; ZDICT_fillNoise_p < length; ZDICT_fillNoise_p++)
+    ZDICT_fillNoise_acc *= ((char *)buffer)[ZDICT_fillNoise_p] = prime2;
+}
+long ZDICT_trainFromBuffer_legacy() {
+  void *newBuff;
+  long total = 0;
+  for (; ZDICT_totalSampleSize_nbFiles;)
+    total += 0;
+  long sBuffSize = total;
+  newBuff = 0;
+  ZDICT_fillNoise(newBuff + sBuffSize, 32);
+  return ZDICT_trainFromBuffer_legacy_result;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 8f88f1755be..9c434b66c5b 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -8646,8 +8646,10 @@ vectorizable_nonlinear_induction (loop_vec_info loop_vinfo,
   /* Also doens't support peel for neg when niter is variable.
      ??? generate something like niter_expr & 1 ? init_expr : -init_expr?  */
   niters_skip = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo);
-  if (niters_skip != NULL_TREE
-      && TREE_CODE (niters_skip) != INTEGER_CST)
+  if ((niters_skip != NULL_TREE
+       && TREE_CODE (niters_skip) != INTEGER_CST)
+      || (!vect_use_loop_mask_for_alignment_p (loop_vinfo)
+	  && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0))
     {
       if (dump_enabled_p ())
 	dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-- 
2.27.0


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

* Re: [PATCH] [ICE] Check another epilog variable peeling case in vectorizable_nonlinear_induction.
  2022-09-14  1:25 [PATCH] [ICE] Check another epilog variable peeling case in vectorizable_nonlinear_induction liuhongt
@ 2022-09-14  6:11 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-09-14  6:11 UTC (permalink / raw)
  To: liuhongt; +Cc: gcc-patches

On Wed, Sep 14, 2022 at 3:25 AM liuhongt via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> In vectorizable_nonlinear_induction, r13-2503-gc13223b790bbc5 prevent variable peeling by
> only checking LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo). But when
> "!vect_use_loop_mask_for_alignment_p (loop_vinfo) &&
> LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0", vectorizer will
> still do variable peeling for epilog, and it hits gcc_assert in
> vect_peel_nonlinear_iv_init.
>
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> The patch also fix ICE of the testcase in the PR for ia64-linux-gnu(verified by cross-compile).
>
> Ok for trunk?

OK.

Thanks,
Richard.

> gcc/ChangeLog:
>
>         PR tree-optimization/106905
>         * tree-vect-loop.cc (vectorizable_nonlinear_induction): Return
>         false when !vect_use_loop_mask_for_alignment_p (loop_vinfo) &&
>         LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/pr106905.c: New test.
>         * gcc.target/ia64/pr106905.c: New test.
> ---
>  gcc/testsuite/gcc.target/i386/pr106905.c | 14 ++++++++++++++
>  gcc/testsuite/gcc.target/ia64/pr106905.c | 20 ++++++++++++++++++++
>  gcc/tree-vect-loop.cc                    |  6 ++++--
>  3 files changed, 38 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr106905.c
>  create mode 100644 gcc/testsuite/gcc.target/ia64/pr106905.c
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr106905.c b/gcc/testsuite/gcc.target/i386/pr106905.c
> new file mode 100644
> index 00000000000..a190a1c84e6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr106905.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=silvermont -O2 -fvect-cost-model=dynamic" } */
> +
> +void
> +foo_mul_peel (int *a, int b)
> +{
> +  int i;
> +
> +  for (i = 0; i < 7; ++i)
> +    {
> +      b *= 2;
> +      a[i] = b;
> +    }
> +}
> diff --git a/gcc/testsuite/gcc.target/ia64/pr106905.c b/gcc/testsuite/gcc.target/ia64/pr106905.c
> new file mode 100644
> index 00000000000..1b9656e1203
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/ia64/pr106905.c
> @@ -0,0 +1,20 @@
> +/* { dg-do compile } */
> +/* { dg-options "-std=c99 -O3 -fPIC" } */
> +long ZDICT_fillNoise_p, ZDICT_trainFromBuffer_legacy_result;
> +unsigned ZDICT_fillNoise_acc;
> +int ZDICT_totalSampleSize_nbFiles;
> +static void ZDICT_fillNoise(void *buffer, long length) {
> +  unsigned prime2 = 9;
> +  for (ZDICT_fillNoise_p = 0; ZDICT_fillNoise_p < length; ZDICT_fillNoise_p++)
> +    ZDICT_fillNoise_acc *= ((char *)buffer)[ZDICT_fillNoise_p] = prime2;
> +}
> +long ZDICT_trainFromBuffer_legacy() {
> +  void *newBuff;
> +  long total = 0;
> +  for (; ZDICT_totalSampleSize_nbFiles;)
> +    total += 0;
> +  long sBuffSize = total;
> +  newBuff = 0;
> +  ZDICT_fillNoise(newBuff + sBuffSize, 32);
> +  return ZDICT_trainFromBuffer_legacy_result;
> +}
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index 8f88f1755be..9c434b66c5b 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -8646,8 +8646,10 @@ vectorizable_nonlinear_induction (loop_vec_info loop_vinfo,
>    /* Also doens't support peel for neg when niter is variable.
>       ??? generate something like niter_expr & 1 ? init_expr : -init_expr?  */
>    niters_skip = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo);
> -  if (niters_skip != NULL_TREE
> -      && TREE_CODE (niters_skip) != INTEGER_CST)
> +  if ((niters_skip != NULL_TREE
> +       && TREE_CODE (niters_skip) != INTEGER_CST)
> +      || (!vect_use_loop_mask_for_alignment_p (loop_vinfo)
> +         && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0))
>      {
>        if (dump_enabled_p ())
>         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
> --
> 2.27.0
>

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

end of thread, other threads:[~2022-09-14  6:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14  1:25 [PATCH] [ICE] Check another epilog variable peeling case in vectorizable_nonlinear_induction liuhongt
2022-09-14  6:11 ` 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).