public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110223] New: Missed optimization vectorizing booleans comparisons
@ 2023-06-12 13:04 tnfchris at gcc dot gnu.org
  2023-06-26  5:24 ` [Bug tree-optimization/110223] " pinskia at gcc dot gnu.org
  2023-11-06  7:52 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2023-06-12 13:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110223
           Summary: Missed optimization vectorizing booleans comparisons
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tnfchris at gcc dot gnu.org
  Target Milestone: ---

== truncate before bool

float a[1024], b[1024], c[1024], d[1024];
int k[1024];
_Bool res[1024];

int main ()
{
  int i;
  for (i = 0; i < 1024; i++)
    res[i] = k[i] != ((i - 3) == 0);
}

vectorizes but does the bit clear before the truncate. Due to the high unroll
factor if done the other way around we can save the extra bitclears.

== reduce using unpack

float a[1024], b[1024], c[1024], d[1024];
_Bool k[1024];
_Bool res[1024];

int main ()
{
  int i;
  for (i = 0; i < 1024; i++)
    res[i] = k[i] != (i == 0);
}

Doesn't vectorize as the compiler doesn't know how to compare different boolean
vector element sizes.  Because i is an integer the result is a V4SI backed
boolean type, vs the V16QI one for k[i].  So it has to compare 4 V4SI vectors
against 1 V16QI, it can do this by truncating the the 4 V4SI bools to 1 V16QI
bool.

== mask vs non-mask type

_Bool k[1024];
_Bool res[1024];

int main ()
{
  char i;
  for (i = 0; i < 64; i++)
    res[i] = k[i] != (i == 0);
}

doesn't vectorize because the compiler doesn't know how to compare a boolean
mask vs a non-mask boolean.  There's a comment in the source code that this can
be done using a pattern (presumably casting the types earlier).

in my case I need these to work on gcond as well, not just assigns,  and since
we don't codegen conds, it might be better to handle them in vectorizable_*.

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

* [Bug tree-optimization/110223] Missed optimization vectorizing booleans comparisons
  2023-06-12 13:04 [Bug tree-optimization/110223] New: Missed optimization vectorizing booleans comparisons tnfchris at gcc dot gnu.org
@ 2023-06-26  5:24 ` pinskia at gcc dot gnu.org
  2023-11-06  7:52 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-26  5:24 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-06-26
           Severity|normal                      |enhancement

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug tree-optimization/110223] Missed optimization vectorizing booleans comparisons
  2023-06-12 13:04 [Bug tree-optimization/110223] New: Missed optimization vectorizing booleans comparisons tnfchris at gcc dot gnu.org
  2023-06-26  5:24 ` [Bug tree-optimization/110223] " pinskia at gcc dot gnu.org
@ 2023-11-06  7:52 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-06  7:52 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=111149

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I ran into boolean vectorizer issues too when making ^ be used instead of !=
for boolean types. I wonder how much is related to what is here.

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

end of thread, other threads:[~2023-11-06  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-12 13:04 [Bug tree-optimization/110223] New: Missed optimization vectorizing booleans comparisons tnfchris at gcc dot gnu.org
2023-06-26  5:24 ` [Bug tree-optimization/110223] " pinskia at gcc dot gnu.org
2023-11-06  7:52 ` pinskia at gcc dot gnu.org

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).