public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/112331] Fail vectorization after loop interchange
Date: Thu, 02 Nov 2023 10:48:09 +0000	[thread overview]
Message-ID: <bug-112331-4-JcCuAyNiej@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112331-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112331

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'm not sure what the problem is with a zero DR step for an inner loop
reference 
(possibly dependence analysis runs into some unhandled cases - who knows).  The
following vectorizes the inner loop (the load is hoisted as invariant, but
the store is not sunk - there's no sinking phase after interchange).

diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index d5c9c4a11c2..7d1f0697fe7 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -2944,6 +2944,7 @@ vect_analyze_data_ref_access (vec_info *vinfo,
dr_vec_info *dr_info)
       DR_GROUP_FIRST_ELEMENT (stmt_info) = NULL;
       if (!nested_in_vect_loop_p (loop, stmt_info))
        return DR_IS_READ (dr);
+#if 0
       /* Allow references with zero step for outer loops marked
         with pragma omp simd only - it guarantees absence of
         loop-carried dependencies between inner loop iterations.  */
@@ -2954,6 +2955,7 @@ vect_analyze_data_ref_access (vec_info *vinfo,
dr_vec_info *dr_info)
                             "zero step in inner loop of nest\n");
          return false;
        }
+#endif
     }

   if (loop && nested_in_vect_loop_p (loop, stmt_info))


Note when we don't vectorize we are eliding the inner loop later, when
we vectorize we don't.

unvectorized:

s111:
.LFB0:
        .cfi_startproc
        xorl    %eax, %eax
.L2:
        movl    Y(%rax), %ecx
        addq    $4, %rax
        leal    1(%rcx), %edx
        movl    %edx, X-4(%rax)
        cmpq    $128000, %rax
        jne     .L2
        xorl    %eax, %eax
        ret

vectorized:

s111:
.LFB0:
        .cfi_startproc
        movdqa  .LC0(%rip), %xmm1
        xorl    %ecx, %ecx
.L2:
        movdqa  Y(%rcx), %xmm0
        leaq    X(%rcx), %rdx
        movl    $400000, %eax
        paddd   %xmm1, %xmm0
        .p2align 4,,10
        .p2align 3
.L3:
        movaps  %xmm0, (%rdx)
        subl    $2, %eax
        jne     .L3
        addq    $16, %rcx
        cmpq    $128000, %rcx
        jne     .L2
        xorl    %eax, %eax
        ret

      parent reply	other threads:[~2023-11-02 10:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01  9:20 [Bug c/112331] New: middle-end: Fail vectorization juzhe.zhong at rivai dot ai
2023-11-01  9:24 ` [Bug c/112331] " juzhe.zhong at rivai dot ai
2023-11-02  7:42 ` [Bug tree-optimization/112331] " juzhe.zhong at rivai dot ai
2023-11-02 10:00 ` [Bug tree-optimization/112331] Fail vectorization after loop interchange rguenth at gcc dot gnu.org
2023-11-02 10:14 ` juzhe.zhong at rivai dot ai
2023-11-02 10:48 ` rguenth at gcc dot gnu.org [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-112331-4-JcCuAyNiej@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).