public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-8433] tree-optimization/96075 - fix bogus misalignment calculation
@ 2020-07-07 11:01 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2020-07-07 11:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7d535ca86a548b76384f3687e1d46677cb652bdb

commit r10-8433-g7d535ca86a548b76384f3687e1d46677cb652bdb
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jul 6 16:26:50 2020 +0200

    tree-optimization/96075 - fix bogus misalignment calculation
    
    This fixes bogus misalignment calculation for negative steps
    since an assertion a previous comment indicated no longer holds:
    
          /* DR_STEP(dr) is the same as -TYPE_SIZE of the scalar type,
             otherwise we wouldn't be here.  */
    
    Thus the following replaces DR_STEP by -TYPE_SIZE.
    
    2020-07-06  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/96075
            * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Use
            TYPE_SIZE_UNIT of the vector component type instead of DR_STEP
            for the misalignment calculation for negative step.
    
            * gcc.dg/vect/slp-46.c: New testcase.
    
    (cherry picked from commit dccbf1e2a6e544f71b4a5795f0c79015db019fc3)

Diff:
---
 gcc/testsuite/gcc.dg/vect/slp-46.c | 96 ++++++++++++++++++++++++++++++++++++++
 gcc/tree-vect-data-refs.c          |  2 +-
 2 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/slp-46.c b/gcc/testsuite/gcc.dg/vect/slp-46.c
new file mode 100644
index 00000000000..17dfa285ec1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/slp-46.c
@@ -0,0 +1,96 @@
+/* { dg-require-effective-target vect_double } */
+
+#include "tree-vect.h"
+
+double x[1024], y[1024];
+
+void __attribute__((noipa)) foo()
+{
+  for (int i = 0; i < 512; ++i)
+    {
+      x[2*i] = y[i];
+      x[2*i+1] = y[i];
+    }
+}
+
+void __attribute__((noipa)) bar()
+{
+  for (int i = 0; i < 512; ++i)
+    {
+      x[2*i] = y[2*i];
+      x[2*i+1] = y[2*i];
+    }
+}
+
+void __attribute__((noipa)) baz()
+{
+  for (int i = 0; i < 512; ++i)
+    {
+      x[2*i] = y[511-i];
+      x[2*i+1] = y[511-i];
+    }
+}
+
+void __attribute__((noipa)) boo()
+{
+  for (int i = 0; i < 512; ++i)
+    {
+      x[2*i] = y[2*(511-i)];
+      x[2*i+1] = y[2*(511-i)];
+    }
+}
+
+int 
+main ()
+{
+  check_vect ();
+
+  for (int i = 0; i < 1024; ++i)
+    {
+      x[i] = 0;
+      y[i] = i;
+      __asm__ volatile ("");
+    }
+
+  foo ();
+  for (int i = 0; i < 1024; ++i)
+    if (x[i] != y[i/2])
+      abort ();
+
+  for (int i = 0; i < 1024; ++i)
+    {
+      x[i] = 0;
+      __asm__ volatile ("");
+    }
+
+  bar ();
+  for (int i = 0; i < 1024; ++i)
+    if (x[i] != y[2*(i/2)])
+      abort ();
+
+  for (int i = 0; i < 1024; ++i)
+    {
+      x[i] = 0;
+      __asm__ volatile ("");
+    }
+
+  baz ();
+  for (int i = 0; i < 1024; ++i)
+    if (x[i] != y[511 - i/2])
+      abort ();
+
+  for (int i = 0; i < 1024; ++i)
+    {
+      x[i] = 0;
+      __asm__ volatile ("");
+    }
+
+  boo ();
+  for (int i = 0; i < 1024; ++i)
+    if (x[i] != y[2*(511 - i/2)])
+      abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect" } } */
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index 0192aa64636..404c3984fec 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -1056,7 +1056,7 @@ vect_compute_data_ref_alignment (dr_vec_info *dr_info)
   if (tree_int_cst_sgn (drb->step) < 0)
     /* PLUS because STEP is negative.  */
     misalignment += ((TYPE_VECTOR_SUBPARTS (vectype) - 1)
-		     * TREE_INT_CST_LOW (drb->step));
+		     * -TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
 
   unsigned int const_misalignment;
   if (!known_misalignment (misalignment, vect_align_c, &const_misalignment))


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-07 11:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-07 11:01 [gcc r10-8433] tree-optimization/96075 - fix bogus misalignment calculation Richard Biener

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