public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/105490] unvectorized loop due to bool condition loaded from memory and different size data
Date: Thu, 31 Aug 2023 06:34:02 +0000	[thread overview]
Message-ID: <bug-105490-4-421Rzis93K@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105490-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from rguenther at suse dot de <rguenther at suse dot de> ---
On Wed, 30 Aug 2023, pinskia at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105490
> 
> --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> Here is an even odder case:
> ```
> #define N 256
> typedef short T;
> extern T a[N];
> extern T b[N];
> extern T c[N];
> extern _Bool pb[N];
> extern _Bool pb1[N];
> extern _Bool pb2[N];
> 
> void predicate_by_booland()
> {
>   for (int i = 0; i < N; i++)
>     c[i] = ((pb1[i] != pb[i]) != pb2[i]) ? a[i] : b[i];
> }
> ```
> This vectorizes currently with `-O3` but not with `-O3 -fno-tree-vrp`.
> IR with -fno-tree-vrp:
> ```
>   _1 = pb1[i_15];
>   _2 = pb[i_15];
>   _3 = _1 != _2;
>   _4 = pb2[i_15];
>   iftmp.0_10 = a[i_15];
>   _5 = _3 != _4;
>   iftmp.0_9 = b[i_15];
> ```
> IR without (VRP turned on):
> ```
>   _1 = pb1[i_15];
>   _2 = pb[i_15];
>   _3 = _1 ^ _2;
>   _4 = pb2[i_15];
>   iftmp.0_10 = a[i_15];
>   _5 = _3 != _4;
>   iftmp.0_9 = b[i_15];
> ```
> 
> So it is even more confusing ...

This is usually due to limits/bugs in the vectorizer bool pattern
recognition code which is supposed to replace "mask" uses of
bool with x ? -1 : 0 (or make sure comparisons produce them)
and data uses with x ? 1 : 0 (or make sure "data" stmts produce them).
There are defenses in vectorizable_* to detect cases where that did
go wrong (which it does sometimes), leading to missed vectorizations
(or wrong code in the worst case).

It's a mess.

      parent reply	other threads:[~2023-08-31  6:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05  8:39 [Bug tree-optimization/105490] New: " rguenth at gcc dot gnu.org
2022-05-05  8:39 ` [Bug tree-optimization/105490] " rguenth at gcc dot gnu.org
2022-10-31 15:46 ` pinskia at gcc dot gnu.org
2023-08-30  6:07 ` pinskia at gcc dot gnu.org
2023-08-30 15:32 ` pinskia at gcc dot gnu.org
2023-08-31  6:34 ` rguenther at suse dot de [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-105490-4-421Rzis93K@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).