public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/65310] New: vectorizer uses wrong alignment
@ 2015-03-04 11:28 rguenth at gcc dot gnu.org
  2015-03-04 11:28 ` [Bug tree-optimization/65310] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-04 11:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65310
           Summary: vectorizer uses wrong alignment
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org

Noticed by Jan Hubicka in PR65270:

Hi,
while looking for a testcase that would trigger with tree-tail-merge (because
gimple-fold seems to also miss MEM_REF merging) I noticed following oddity:

struct a 
{
  int a[100000];
};
typedef struct a b __attribute__ ((aligned (32)));
typedef struct a c __attribute__ ((aligned (8)));
typedef struct a d __attribute__ ((aligned (32)));

__attribute__ ((used))
t(b *a, int aligned, b *d)
{
  int i,v;
        c *ptr = a;
  for (i=0;i<100000;i++)
    {
        ptr->a[i]++;
    }
}
main()
{
}

here the loop gets vectorized with assumed alignmen 32.
Changing declaretion to:
t(c *a, int aligned, b *d)
produces correct 8 byte alignment loop.
Alignment of the type of variable A shall not be used.


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
@ 2015-03-04 11:28 ` rguenth at gcc dot gnu.org
  2015-03-05  9:14 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-04 11:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2015-03-04
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I have a fix.


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
  2015-03-04 11:28 ` [Bug tree-optimization/65310] " rguenth at gcc dot gnu.org
@ 2015-03-05  9:14 ` rguenth at gcc dot gnu.org
  2015-03-05  9:15 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-05  9:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Thu Mar  5 09:14:01 2015
New Revision: 221206

URL: https://gcc.gnu.org/viewcvs?rev=221206&root=gcc&view=rev
Log:
2015-03-05  Richard Biener  <rguenther@suse.de>

    PR tree-optimization/65310
    * tree-vect-data-refs.c (vect_compute_data_ref_alignment):
    Properly preserve alignment of the base of the access.

    * gcc.dg/vect/pr65310.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr65310.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-data-refs.c


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
  2015-03-04 11:28 ` [Bug tree-optimization/65310] " rguenth at gcc dot gnu.org
  2015-03-05  9:14 ` rguenth at gcc dot gnu.org
@ 2015-03-05  9:15 ` rguenth at gcc dot gnu.org
  2015-03-09 21:44 ` pthaugen at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-05  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|                            |5.0
         Resolution|---                         |FIXED

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2015-03-05  9:15 ` rguenth at gcc dot gnu.org
@ 2015-03-09 21:44 ` pthaugen at gcc dot gnu.org
  2015-03-10  8:56 ` rguenther at suse dot de
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pthaugen at gcc dot gnu.org @ 2015-03-09 21:44 UTC (permalink / raw)
  To: gcc-bugs

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

Pat Haugen <pthaugen at gcc dot gnu.org> changed:

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

--- Comment #4 from Pat Haugen <pthaugen at gcc dot gnu.org> ---
g++.dg/vect/slp-pr50819.cc started failing on powerpc64[le]] with r221206.


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2015-03-09 21:44 ` pthaugen at gcc dot gnu.org
@ 2015-03-10  8:56 ` rguenther at suse dot de
  2015-03-10 15:28 ` pthaugen at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenther at suse dot de @ 2015-03-10  8:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from rguenther at suse dot de <rguenther at suse dot de> ---
On Mon, 9 Mar 2015, pthaugen at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65310
> 
> Pat Haugen <pthaugen at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |pthaugen at gcc dot gnu.org
> 
> --- Comment #4 from Pat Haugen <pthaugen at gcc dot gnu.org> ---
> g++.dg/vect/slp-pr50819.cc started failing on powerpc64[le]] with r221206.

works for me with a cross to powerpc64-suse-linux and -mvsx or -maltivec
(not with just -mcpu=power4).

Can you be more specific as with what options it fails?


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2015-03-10  8:56 ` rguenther at suse dot de
@ 2015-03-10 15:28 ` pthaugen at gcc dot gnu.org
  2015-03-11  8:40 ` rguenther at suse dot de
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pthaugen at gcc dot gnu.org @ 2015-03-10 15:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Pat Haugen <pthaugen at gcc dot gnu.org> ---
> Can you be more specific as with what options it fails?

I just tried current trunk (r221324) and the testcase still fails. Only one
"basic block vectorized" string is generated, where the testcase expects two
occurrences.

[pthaugen@igoo testsuite]$ ~/install/gcc/trunk/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/pthaugen/install/gcc/trunk/bin/gcc
COLLECT_LTO_WRAPPER=/home/pthaugen/install/gcc/trunk/libexec/gcc/powerpc64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: powerpc64-unknown-linux-gnu
Configured with: /home/pthaugen/src/gcc/trunk/gcc/configure
--prefix=/home/pthaugen/install/gcc/trunk --enable-decimal-float --enable-lto
--with-as=/home/pthaugen/install/binutils/binutils-2.25/bin/as
--with-ld=/home/pthaugen/install/binutils/binutils-2.25/bin/ld
--with-gmp=/home/pthaugen/install/gcc-host-libs --without-ppl --without-cloog
--enable-languages=c,fortran,c++ --disable-bootstrap
Thread model: posix
gcc version 5.0.0 20150310 (experimental) [trunk revision 221324] (GCC) 

[pthaugen@igoo testsuite]$ ~/install/gcc/trunk/bin/g++ -std=c++98 -O2
-ftree-vectorize -fno-vect-cost-model -maltivec -mvsx -mno-allow-movmisalign
-fdump-tree-slp-details -S -m64 slp-pr50819.cc
[pthaugen@igoo testsuite]$ grep "basic block vectorized"
slp-pr50819.cc.136t.slp2
slp-pr50819.cc:28:17: note: basic block vectorized
[pthaugen@igoo testsuite]$


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2015-03-10 15:28 ` pthaugen at gcc dot gnu.org
@ 2015-03-11  8:40 ` rguenther at suse dot de
  2015-03-11  9:37 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenther at suse dot de @ 2015-03-11  8:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 10 Mar 2015, pthaugen at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65310
> 
> --- Comment #6 from Pat Haugen <pthaugen at gcc dot gnu.org> ---
> > Can you be more specific as with what options it fails?
> 
> I just tried current trunk (r221324) and the testcase still fails. Only one
> "basic block vectorized" string is generated, where the testcase expects two
> occurrences.
> 
> [pthaugen@igoo testsuite]$ ~/install/gcc/trunk/bin/gcc -v
> Using built-in specs.
> COLLECT_GCC=/home/pthaugen/install/gcc/trunk/bin/gcc
> COLLECT_LTO_WRAPPER=/home/pthaugen/install/gcc/trunk/libexec/gcc/powerpc64-unknown-linux-gnu/5.0.0/lto-wrapper
> Target: powerpc64-unknown-linux-gnu
> Configured with: /home/pthaugen/src/gcc/trunk/gcc/configure
> --prefix=/home/pthaugen/install/gcc/trunk --enable-decimal-float --enable-lto
> --with-as=/home/pthaugen/install/binutils/binutils-2.25/bin/as
> --with-ld=/home/pthaugen/install/binutils/binutils-2.25/bin/ld
> --with-gmp=/home/pthaugen/install/gcc-host-libs --without-ppl --without-cloog
> --enable-languages=c,fortran,c++ --disable-bootstrap
> Thread model: posix
> gcc version 5.0.0 20150310 (experimental) [trunk revision 221324] (GCC) 
> 
> [pthaugen@igoo testsuite]$ ~/install/gcc/trunk/bin/g++ -std=c++98 -O2
> -ftree-vectorize -fno-vect-cost-model -maltivec -mvsx -mno-allow-movmisalign
> -fdump-tree-slp-details -S -m64 slp-pr50819.cc
> [pthaugen@igoo testsuite]$ grep "basic block vectorized"
> slp-pr50819.cc.136t.slp2
> slp-pr50819.cc:28:17: note: basic block vectorized
> [pthaugen@igoo testsuite]$

Still can't reproduce it.  Cross configured with

  $ /space/rguenther/tramp3d/trunk/configure --target=powerpc64-suse-linux 
--with-cpu-64=power4 --enable-secureplt --with-long-double-128 
target_alias=powerpc64-suse-linux CFLAGS=-g CXXFLAGS=-g 
--enable-languages=c,c++,lto --no-create --no-recursion

gcc> ./cc1plus -quiet -std=c++98 -O2 -ftree-vectorize -fno-vect-cost-model 
-maltivec -mvsx -mno-allow-movmisalign -fdump-tree-slp-details -m64 
slp-pr50819.cc -I include
gcc> grep 'basic block vectorized' slp-pr50819.cc.135t.slp2
slp-pr50819.cc:28:70: note: basic block vectorized
slp-pr50819.cc:28:70: note: basic block vectorized


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2015-03-11  8:40 ` rguenther at suse dot de
@ 2015-03-11  9:37 ` rguenth at gcc dot gnu.org
  2015-03-11  9:54 ` rguenth at gcc dot gnu.org
  2015-03-11 15:10 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-11  9:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Whoops - tested in the wrong tree.  Can reproduce now - investigating.


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2015-03-11  9:37 ` rguenth at gcc dot gnu.org
@ 2015-03-11  9:54 ` rguenth at gcc dot gnu.org
  2015-03-11 15:10 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-11  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's early SRA dropping alignment info.

-  # .MEM_48 = VDEF <.MEM_47>
-  # lhs access alignment 128+0
-  D.2264.theX = _31;
-  # .MEM_49 = VDEF <.MEM_48>
-  # lhs access alignment 128+32
-  D.2264.theY = _34;
-  # .MEM_50 = VDEF <.MEM_49>
-  # lhs access alignment 128+64
-  D.2264.theZ = _37;
-  # .MEM_51 = VDEF <.MEM_50>
-  # lhs access alignment 128+96
-  D.2264.theT = _40;
-  # .MEM_52 = VDEF <.MEM_51>
-  # lhs access alignment 128+0
-  # rhs access alignment 128+0
-  *res_7(D) = D.2264;
-  # .MEM_9 = VDEF <.MEM_52>
+  SR.22_44 = _31;
+  SR.23_43 = _34;
+  SR.24_42 = _37;
+  SR.25_41 = _40;
+  # .MEM_8 = VDEF <.MEM_1(D)>
+  # lhs access alignment 32+0
+  MEM[(struct LorentzVector *)res_7(D)] = SR.22_44;
+  # .MEM_53 = VDEF <.MEM_8>
+  # lhs access alignment 32+0
+  MEM[(struct LorentzVector *)res_7(D) + 4B] = SR.23_43;
+  # .MEM_54 = VDEF <.MEM_53>
+  # lhs access alignment 32+0
+  MEM[(struct LorentzVector *)res_7(D) + 8B] = SR.24_42;
+  # .MEM_55 = VDEF <.MEM_54>
+  # lhs access alignment 32+0
+  MEM[(struct LorentzVector *)res_7(D) + 12B] = SR.25_41;
+  # .MEM_9 = VDEF <.MEM_55>

of course as it splits up the aggregate store and we can't represent
align + known misalignment with the type used on the MEM_REF we are
somewhat lost here.  We can do better for the first and the third
store though:

  # .MEM_8 = VDEF <.MEM_1(D)>
  # lhs access alignment 128+0
  MEM[(struct LorentzVector *)res_7(D)] = SR.22_44;
  # .MEM_53 = VDEF <.MEM_8>
  # lhs access alignment 32+0
  MEM[(struct LorentzVector *)res_7(D) + 4B] = SR.23_43;
  # .MEM_54 = VDEF <.MEM_53>
  # lhs access alignment 64+0
  MEM[(struct LorentzVector *)res_7(D) + 8B] = SR.24_42;
  # .MEM_55 = VDEF <.MEM_54>
  # lhs access alignment 32+0
  MEM[(struct LorentzVector *)res_7(D) + 12B] = SR.25_41;

that seems to be enough here as the vectorizer is clever enough to only
care about the first ref alignment of a group access.  Phew ;)

Testing

Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c      (revision 221324)
+++ gcc/tree-sra.c      (working copy)
@@ -1597,7 +1597,7 @@ build_ref_for_offset (location_t loc, tr
   misalign = (misalign + offset) & (align - 1);
   if (misalign != 0)
     align = (misalign & -misalign);
-  if (align < TYPE_ALIGN (exp_type))
+  if (align != TYPE_ALIGN (exp_type))
     exp_type = build_aligned_type (exp_type, align);

   mem_ref = fold_build2_loc (loc, MEM_REF, exp_type, base, off);


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

* [Bug tree-optimization/65310] vectorizer uses wrong alignment
  2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2015-03-11  9:54 ` rguenth at gcc dot gnu.org
@ 2015-03-11 15:10 ` rguenth at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-11 15:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Wed Mar 11 15:09:51 2015
New Revision: 221348

URL: https://gcc.gnu.org/viewcvs?rev=221348&root=gcc&view=rev
Log:
2015-03-11  Richard Biener  <rguenther@suse.de>

    PR tree-optimization/65310
    * tree-sra.c (build_ref_for_offset): Also preserve larger
    alignment.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-sra.c


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

end of thread, other threads:[~2015-03-11 15:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-04 11:28 [Bug tree-optimization/65310] New: vectorizer uses wrong alignment rguenth at gcc dot gnu.org
2015-03-04 11:28 ` [Bug tree-optimization/65310] " rguenth at gcc dot gnu.org
2015-03-05  9:14 ` rguenth at gcc dot gnu.org
2015-03-05  9:15 ` rguenth at gcc dot gnu.org
2015-03-09 21:44 ` pthaugen at gcc dot gnu.org
2015-03-10  8:56 ` rguenther at suse dot de
2015-03-10 15:28 ` pthaugen at gcc dot gnu.org
2015-03-11  8:40 ` rguenther at suse dot de
2015-03-11  9:37 ` rguenth at gcc dot gnu.org
2015-03-11  9:54 ` rguenth at gcc dot gnu.org
2015-03-11 15:10 ` 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).