public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Adonis Ling <adonis0147@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Why does different types of array subscript used to iterate affect auto vectorization
Date: Mon, 27 Jun 2022 10:47:24 +0800	[thread overview]
Message-ID: <CAG5qfXii3dyLDsdULLyZSoigMZjMjk7LmOmjwgZSB44cAQzf-g@mail.gmail.com> (raw)

 Hi all,

Recently, I met an issue with auto vectorization.

As following code shows, why uint32_t prevents the compiler (GCC 12.1 + O3)
from optimizing by auto vectorization. See https://godbolt.org/z/a3GfaKEq6.

#include <cstdint>

// no auto vectorization
void test32(uint32_t *array, uint32_t &nread, uint32_t from, uint32_t to) {
    for (uint32_t i = from; i < to; i++) {
        array[nread++] = i;
    }
}

// auto vectorization
void test64(uint32_t *array, uint64_t &nread, uint32_t from, uint32_t to) {
    for (uint32_t i = from; i < to; i++) {
        array[nread++] = i;
    }
}

// no auto vectorization
void test_another_32(uint32_t *array, uint32_t &nread, uint32_t from,
uint32_t to) {
    uint32_t index = nread;
    for (uint32_t i = from; i < to; i++) {
        array[index++] = i;
    }
    nread = index;
}

// auto vectorization
void test_another_64(uint32_t *array, uint32_t &nread, uint32_t from,
uint32_t to) {
    uint64_t index = nread;
    for (uint32_t i = from; i < to; i++) {
        array[index++] = i;
    }
    nread = index;
}

After I ran the command g++ -O3 -fopt-info-vec-missed -c test.cc -o
/dev/null, I got the following result. How to interpret it?

bash> g++ -O3 -fopt-info-vec-missed -c test.cc -o /dev/null
test.cc:5:31: missed: couldn't vectorize loop
test.cc:6:24: missed: not vectorized: not suitable for scatter store *_5 =
i_18;
test.cc:21:31: missed: couldn't vectorize loop
test.cc:22:24: missed: not vectorized: not suitable for scatter store *_4 =
i_22;

-- 
Best regards,
Adonis

             reply	other threads:[~2022-06-27  2:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27  2:47 Adonis Ling [this message]
2022-06-28 13:06 ` Alexander Monakov
2022-06-28 15:23   ` Adonis Ling
2022-06-28 15:38     ` Alexander Monakov
2022-06-28 15:47       ` Adonis Ling
2022-06-28 15:56         ` Alexander Monakov
2022-06-28 16:00           ` Adonis Ling

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=CAG5qfXii3dyLDsdULLyZSoigMZjMjk7LmOmjwgZSB44cAQzf-g@mail.gmail.com \
    --to=adonis0147@gmail.com \
    --cc=gcc-help@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).