public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54803] New: Manual constant unfolding breaks vectorization
@ 2012-10-04  0:00 jasongross9+bugzilla at gmail dot com
  2012-10-04  0:15 ` [Bug tree-optimization/54803] Rotates are not vectorized pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jasongross9+bugzilla at gmail dot com @ 2012-10-04  0:00 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54803

             Bug #: 54803
           Summary: Manual constant unfolding breaks vectorization
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jasongross9+bugzilla@gmail.com


Created attachment 28348
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28348
code files

Manually unfolding constants sometimes prevents vectorization.

For example, these loops vectorize:

void multi_left_shift0(uint64_t *const array, size_t len, size_t num_bits) {
  for (size_t i = 0; i < len; i++) {
    array[i] = (array[i] >> 31) | (array[i] << 31);
  }
}

void multi_left_shift2(uint64_t *const array, size_t len, size_t num_bits) {
  for (size_t i = 0; i < len; i++) {
    const uint64_t tempa = array[i] >> 32;
    const uint64_t tempb = array[i] << 32;
    array[i] = tempa | tempb;
  }
}


but this loops does not:

void multi_left_shiftb0(uint64_t *const array, size_t len, size_t num_bits) {
  for (size_t i = 0; i < len; i++) {
    array[i] = (array[i] >> 32) | (array[i] << 32);
  }
}


See attached file for the code, preprocessed code, gcc command line log, and
assembly.


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

* [Bug tree-optimization/54803] Rotates are not vectorized
  2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
@ 2012-10-04  0:15 ` pinskia at gcc dot gnu.org
  2012-10-04 12:11 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-10-04  0:15 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54803

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Manual constant unfolding   |Rotates are not vectorized
                   |breaks vectorization        |

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-10-04 00:14:52 UTC ---
  D.1826_10 = D.1825_9 r<< 32;

So the rotate by 32 is not being vectorizered into two shift followed by an or.


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

* [Bug tree-optimization/54803] Rotates are not vectorized
  2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
  2012-10-04  0:15 ` [Bug tree-optimization/54803] Rotates are not vectorized pinskia at gcc dot gnu.org
@ 2012-10-04 12:11 ` rguenth at gcc dot gnu.org
  2015-06-12 13:21 ` alalaw01 at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-10-04 12:11 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54803

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-04
             Blocks|                            |53947
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-10-04 12:11:21 UTC ---
Thus, confirmed.


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

* [Bug tree-optimization/54803] Rotates are not vectorized
  2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
  2012-10-04  0:15 ` [Bug tree-optimization/54803] Rotates are not vectorized pinskia at gcc dot gnu.org
  2012-10-04 12:11 ` rguenth at gcc dot gnu.org
@ 2015-06-12 13:21 ` alalaw01 at gcc dot gnu.org
  2015-08-10 22:34 ` miyuki at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: alalaw01 at gcc dot gnu.org @ 2015-06-12 13:21 UTC (permalink / raw)
  To: gcc-bugs

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

alalaw01 at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |UNCONFIRMED
                 CC|                            |alalaw01 at gcc dot gnu.org
     Ever confirmed|1                           |0

--- Comment #3 from alalaw01 at gcc dot gnu.org ---
on gcc6.0 development branch, for aarch64, at -O3: shiftb0 is vectorized
exactly as shift2.


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

* [Bug tree-optimization/54803] Rotates are not vectorized
  2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
                   ` (2 preceding siblings ...)
  2015-06-12 13:21 ` alalaw01 at gcc dot gnu.org
@ 2015-08-10 22:34 ` miyuki at gcc dot gnu.org
  2015-08-13 10:44 ` vekumar at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: miyuki at gcc dot gnu.org @ 2015-08-10 22:34 UTC (permalink / raw)
  To: gcc-bugs

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

Mikhail Maltsev <miyuki at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |miyuki at gcc dot gnu.org

--- Comment #4 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
On x86_64 the testcase is also vectorized. For example, with -O3
-march=haswell:

.L9:
        vmovdqa (%r9,%rax), %ymm0
        addq    $1, %r8
        vpsrlq  $32, %ymm0, %ymm1
        vpsllq  $32, %ymm0, %ymm0
        vpor    %ymm0, %ymm1, %ymm0
        vmovdqa %ymm0, (%r9,%rax)
        addq    $32, %rax
        cmpq    %r8, %rcx
        ja      .L9

On bdver2 vprotq insn is used:

.L14:
        incq    %rcx
        vprotq  $32, (%rax,%r8), %xmm0
        vmovaps %xmm0, (%rdx,%r8)
        addq    $16, %r8
        cmpq    %r10, %rcx
        jb      .L14


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

* [Bug tree-optimization/54803] Rotates are not vectorized
  2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
                   ` (3 preceding siblings ...)
  2015-08-10 22:34 ` miyuki at gcc dot gnu.org
@ 2015-08-13 10:44 ` vekumar at gcc dot gnu.org
  2015-08-13 10:52 ` vekumar at gcc dot gnu.org
  2021-08-24 22:50 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: vekumar at gcc dot gnu.org @ 2015-08-13 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

vekumar at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vekumar at gcc dot gnu.org

--- Comment #5 from vekumar at gcc dot gnu.org ---
On bdver4 when we enable -march=bdver4 and -mno-prefer-avx128 vectorizes using
YMM
Otherwise uses vprotq instruction.

.L13:
        vmovdqa (%r8,%r9), %ymm0
        incq    %rax
        vpsrlq  $32, %ymm0, %ymm1
        vpsllq  $32, %ymm0, %ymm0
        vpor    %ymm0, %ymm1, %ymm0
        vmovdqa %ymm0, (%rdx,%r9)
        addq    $32, %r9
        cmpq    %rax, %r10
        ja      .L13


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

* [Bug tree-optimization/54803] Rotates are not vectorized
  2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
                   ` (4 preceding siblings ...)
  2015-08-13 10:44 ` vekumar at gcc dot gnu.org
@ 2015-08-13 10:52 ` vekumar at gcc dot gnu.org
  2021-08-24 22:50 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: vekumar at gcc dot gnu.org @ 2015-08-13 10:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from vekumar at gcc dot gnu.org ---
(In reply to vekumar from comment #5)
> On bdver4 when we enable -march=bdver4 and -mno-prefer-avx128 vectorizes
> using YMM
> Otherwise uses vprotq instruction.
> 
> .L13:
>         vmovdqa (%r8,%r9), %ymm0
>         incq    %rax
>         vpsrlq  $32, %ymm0, %ymm1
>         vpsllq  $32, %ymm0, %ymm0
>         vpor    %ymm0, %ymm1, %ymm0
>         vmovdqa %ymm0, (%rdx,%r9)
>         addq    $32, %r9
>         cmpq    %rax, %r10
>         ja      .L13


This is with trunk gcc version 6.0.0 20150810 (experimental) (GCC)


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

* [Bug tree-optimization/54803] Rotates are not vectorized
  2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
                   ` (5 preceding siblings ...)
  2015-08-13 10:52 ` vekumar at gcc dot gnu.org
@ 2021-08-24 22:50 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-24 22:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.9.0
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 4.9.0 by r0-123435.

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

end of thread, other threads:[~2021-08-24 22:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-04  0:00 [Bug c/54803] New: Manual constant unfolding breaks vectorization jasongross9+bugzilla at gmail dot com
2012-10-04  0:15 ` [Bug tree-optimization/54803] Rotates are not vectorized pinskia at gcc dot gnu.org
2012-10-04 12:11 ` rguenth at gcc dot gnu.org
2015-06-12 13:21 ` alalaw01 at gcc dot gnu.org
2015-08-10 22:34 ` miyuki at gcc dot gnu.org
2015-08-13 10:44 ` vekumar at gcc dot gnu.org
2015-08-13 10:52 ` vekumar at gcc dot gnu.org
2021-08-24 22:50 ` 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).