public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101639] New: vectorization with bool reduction
@ 2021-07-27 10:58 glisse at gcc dot gnu.org
  2021-07-27 11:21 ` [Bug tree-optimization/101639] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2021-07-27 10:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101639
           Summary: vectorization with bool reduction
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-*-*

bool f(char* p, long n)
{
  bool r = true;
  for(long i = 0; i < n; ++i)
    r &= (p[i] != 0);
  return r;
}

is not vectorized, while if I simply declare r as char instead of bool, it is
(not quite optimal since it fails to pull &1 out of the loop, but that's a
separate issue).

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

* [Bug tree-optimization/101639] vectorization with bool reduction
  2021-07-27 10:58 [Bug tree-optimization/101639] New: vectorization with bool reduction glisse at gcc dot gnu.org
@ 2021-07-27 11:21 ` rguenth at gcc dot gnu.org
  2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-27 11:21 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |53947
   Last reconfirmed|                            |2021-07-27
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
vectorizable_reduction fails the

6692      scalar_dest = gimple_assign_lhs (stmt);
6693      scalar_type = TREE_TYPE (scalar_dest);
6694      if (!POINTER_TYPE_P (scalar_type) && !INTEGRAL_TYPE_P (scalar_type)
6695          && !SCALAR_FLOAT_TYPE_P (scalar_type))
6696        return false;
6697
6698      /* Do not try to vectorize bit-precision reductions.  */
6699      if (!type_has_mode_precision_p (scalar_type))
6700        return false;

check.  I guess we could relax that for BIT_*_EXPR reductions.  But then
we run into

t5.c:4:21: note:   vect_is_simple_use: vectype vector(16) unsigned char
t5.c:4:21: missed:   mixed mask and nonmask vector types
t5.c:1:6: missed:   not vectorized: relevant stmt not supported: _7 = _4 &
r_14;
t5.c:4:21: missed:  bad operation or unsupported loop bound.

I guess that's mainly a fault of missed bool pattern handling of the
reduction - we fail to make p[i] != 0 available as non-boolean vector.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations

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

* [Bug tree-optimization/101639] vectorization with bool reduction
  2021-07-27 10:58 [Bug tree-optimization/101639] New: vectorization with bool reduction glisse at gcc dot gnu.org
  2021-07-27 11:21 ` [Bug tree-optimization/101639] " rguenth at gcc dot gnu.org
@ 2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-18  6:25 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2021-07-27 00:00:00         |2024-6-18
                 CC|                            |rguenth at gcc dot gnu.org,
                   |                            |rsandifo at gcc dot gnu.org

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Re-confirmed.  To recap:

t.c:4:21: note:   === vect_determine_precisions ===
t.c:4:21: note:   using normal nonmask vectors for r_14 = PHI <_8(6), 1(5)>
t.c:4:21: note:   using boolean precision 8 for _4 = _3 != 0;
t.c:4:21: note:   using boolean precision 8 for _8 = _4 & r_14;
...
t.c:4:21: note:   ==> examining phi: r_14 = PHI <_8(6), 1(5)>
t.c:4:21: note:   get vectype for scalar type:  bool
t.c:4:21: note:   vectype: vector(16) unsigned char
..
t.c:4:21: note:   ==> examining statement: _4 = _3 != 0;
t.c:4:21: note:   vectype: vector(16) <signed-boolean:8>
t.c:4:21: note:   nunits = 16
t.c:4:21: note:   ==> examining statement: _8 = _4 & r_14;
t.c:4:21: note:   vectype: vector(16) <signed-boolean:8>
t.c:4:21: note:   nunits = 16

that doesn't match up.  The solution might be to realize _8 is live and
thus needed as nonmask.

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

* [Bug tree-optimization/101639] vectorization with bool reduction
  2021-07-27 10:58 [Bug tree-optimization/101639] New: vectorization with bool reduction glisse at gcc dot gnu.org
  2021-07-27 11:21 ` [Bug tree-optimization/101639] " rguenth at gcc dot gnu.org
  2024-06-18  6:25 ` rguenth at gcc dot gnu.org
@ 2024-06-18  6:25 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-18  6:25 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |max.sagebaum at scicomp dot uni-kl
                   |                            |.de

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 115520 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2024-06-18  6:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 10:58 [Bug tree-optimization/101639] New: vectorization with bool reduction glisse at gcc dot gnu.org
2021-07-27 11:21 ` [Bug tree-optimization/101639] " rguenth at gcc dot gnu.org
2024-06-18  6:25 ` rguenth at gcc dot gnu.org
2024-06-18  6:25 ` rguenth 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).