Patchwork [vectorizer] Fix PR tree-optimization/44507

login
register
mail settings
Submitter Ira Rosen
Date June 14, 2010, 12:23 p.m.
Message ID <OF1CF9E5A0.6EC369D8-ONC2257742.0040C86C-C2257742.00440918@il.ibm.com>
Download mbox | patch
Permalink /patch/55521/
State New
Headers show

Comments

Ira Rosen - June 14, 2010, 12:23 p.m.
Hi,

This patch fixes incorrect vector initialization for BIT_AND_EXPR.

Bootstrapped and tested on x86_64-suse-linux.

Committed to trunk. OK for 4.5?

Thanks,
Ira


trunk:

ChangeLog

      PR tree-optimization/44507
      * tree-vect-loop.c (get_initial_def_for_reduction): Use -1
      to build initial vector for BIT_AND_EXPR.
      * tree-vect-slp.c (vect_get_constant_vectors): Likewise.

testsuite/ChangeLog

      PR tree-optimization/44507
      * gcc.dg/vect/pr44507.c: New test.
Richard Guenther - June 14, 2010, 12:37 p.m.
On Mon, Jun 14, 2010 at 2:23 PM, Ira Rosen <IRAR@il.ibm.com> wrote:
>
> Hi,
>
> This patch fixes incorrect vector initialization for BIT_AND_EXPR.
>
> Bootstrapped and tested on x86_64-suse-linux.
>
> Committed to trunk. OK for 4.5?

Ok.

Thanks,
Richard.

> Thanks,
> Ira
>
>
> trunk:
>
> ChangeLog
>
>      PR tree-optimization/44507
>      * tree-vect-loop.c (get_initial_def_for_reduction): Use -1
>      to build initial vector for BIT_AND_EXPR.
>      * tree-vect-slp.c (vect_get_constant_vectors): Likewise.
>
> testsuite/ChangeLog
>
>      PR tree-optimization/44507
>      * gcc.dg/vect/pr44507.c: New test.
>
> Index: tree-vect-loop.c
> ===================================================================
> --- tree-vect-loop.c    (revision 160724)
> +++ tree-vect-loop.c    (working copy)
> @@ -2871,12 +2871,15 @@ get_initial_def_for_reduction (gimple st
>               *adjustment_def = init_val;
>           }
>
> -        if (code == MULT_EXPR || code == BIT_AND_EXPR)
> +        if (code == MULT_EXPR)
>           {
>             real_init_val = dconst1;
>             int_init_val = 1;
>           }
>
> +        if (code == BIT_AND_EXPR)
> +          int_init_val = -1;
> +
>         if (SCALAR_FLOAT_TYPE_P (scalar_type))
>           def_for_init = build_real (scalar_type, real_init_val);
>         else
> Index: tree-vect-slp.c
> ===================================================================
> --- tree-vect-slp.c     (revision 160724)
> +++ tree-vect-slp.c     (working copy)
> @@ -1662,7 +1662,6 @@ vect_get_constant_vectors (slp_tree slp_
>              break;
>
>           case MULT_EXPR:
> -          case BIT_AND_EXPR:
>              if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (op)))
>                neutral_op = build_real (TREE_TYPE (op), dconst1);
>              else
> @@ -1670,6 +1669,10 @@ vect_get_constant_vectors (slp_tree slp_
>
>              break;
>
> +          case BIT_AND_EXPR:
> +            neutral_op = build_int_cst (TREE_TYPE (op), -1);
> +            break;
> +
>           default:
>              neutral_op = NULL;
>         }
> Index: testsuite/gcc.dg/vect/pr44507.c
> ===================================================================
> --- testsuite/gcc.dg/vect/pr44507.c     (revision 0)
> +++ testsuite/gcc.dg/vect/pr44507.c     (revision 0)
> @@ -0,0 +1,55 @@
> +/* { dg-require-effective-target vect_int } */
> +
> +#include <stdlib.h>
> +#include "tree-vect.h"
> +
> +int seeIf256ByteArrayIsConstant(
> +  unsigned char *pArray)
> +{
> +  int index;
> +  unsigned int curVal, orVal, andVal;
> +  int bytesAreEqual = 0;
> +
> +  if (pArray != 0)
> +    {
> +      for (index = 0, orVal = 0, andVal = 0xFFFFFFFF;
> +           index < 64;
> +           index += (int)sizeof(unsigned int))
> +        {
> +          curVal = *((unsigned long *)(&pArray[index]));
> +          orVal = orVal | curVal;
> +          andVal = andVal & curVal;
> +        }
> +
> +      if (!((orVal == andVal)
> +            && ((orVal >> 8) == (andVal & 0x00FFFFFF))))
> +        abort ();
> +    }
> +
> +  return 0;
> +}
> +
> +
> +int main(int argc, char** argv)
> +{
> +  unsigned char array1[64] = {
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +  };
> +
> +  argv = argv;
> +  argc = argc;
> +
> +  check_vect ();
> +
> +  return seeIf256ByteArrayIsConstant(&array1[0]);
> +}
> +
> +/* { dg-final { cleanup-tree-dump "vect" } } */
> +
>
>
>
> 4.5:
>
> ChangeLog
>
>      PR tree-optimization/44507
>      * tree-vect-loop.c (get_initial_def_for_reduction): Use -1
>      to build initial vector for BIT_AND_EXPR.
>
> testsuite/ChangeLog
>
>      PR tree-optimization/44507
>      * gcc.dg/vect/pr44507.c: New test.
>
>
> Index: tree-vect-loop.c
> ===================================================================
> --- tree-vect-loop.c    (revision 160682)
> +++ tree-vect-loop.c    (working copy)
> @@ -2748,12 +2748,15 @@ get_initial_def_for_reduction (gimple st
>               *adjustment_def = init_val;
>           }
>
> -        if (code == MULT_EXPR || code == BIT_AND_EXPR)
> +        if (code == MULT_EXPR)
>           {
>             real_init_val = dconst1;
>             int_init_val = 1;
>           }
>
> +        if (code == BIT_AND_EXPR)
> +          int_init_val = -1;
> +
>         if (SCALAR_FLOAT_TYPE_P (scalar_type))
>           def_for_init = build_real (scalar_type, real_init_val);
>         else
> Index: testsuite/gcc.dg/vect/pr44507.c
> ===================================================================
> --- testsuite/gcc.dg/vect/pr44507.c     (revision 0)
> +++ testsuite/gcc.dg/vect/pr44507.c     (revision 0)
> @@ -0,0 +1,55 @@
> +/* { dg-require-effective-target vect_int } */
> +
> +#include <stdlib.h>
> +#include "tree-vect.h"
> +
> +int seeIf256ByteArrayIsConstant(
> +  unsigned char *pArray)
> +{
> +  int index;
> +  unsigned int curVal, orVal, andVal;
> +  int bytesAreEqual = 0;
> +
> +  if (pArray != 0)
> +    {
> +      for (index = 0, orVal = 0, andVal = 0xFFFFFFFF;
> +           index < 64;
> +           index += (int)sizeof(unsigned int))
> +        {
> +          curVal = *((unsigned long *)(&pArray[index]));
> +          orVal = orVal | curVal;
> +          andVal = andVal & curVal;
> +        }
> +
> +      if (!((orVal == andVal)
> +            && ((orVal >> 8) == (andVal & 0x00FFFFFF))))
> +        abort ();
> +    }
> +
> +  return 0;
> +}
> +
> +
> +int main(int argc, char** argv)
> +{
> +  unsigned char array1[64] = {
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
> +  };
> +
> +  argv = argv;
> +  argc = argc;
> +
> +  check_vect ();
> +
> +  return seeIf256ByteArrayIsConstant(&array1[0]);
> +}
> +
> +/* { dg-final { cleanup-tree-dump "vect" } } */
> +
>
>
>

Patch

Index: tree-vect-loop.c
===================================================================
--- tree-vect-loop.c    (revision 160724)
+++ tree-vect-loop.c    (working copy)
@@ -2871,12 +2871,15 @@  get_initial_def_for_reduction (gimple st
               *adjustment_def = init_val;
           }

-        if (code == MULT_EXPR || code == BIT_AND_EXPR)
+        if (code == MULT_EXPR)
           {
             real_init_val = dconst1;
             int_init_val = 1;
           }

+        if (code == BIT_AND_EXPR)
+          int_init_val = -1;
+
         if (SCALAR_FLOAT_TYPE_P (scalar_type))
           def_for_init = build_real (scalar_type, real_init_val);
         else
Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c     (revision 160724)
+++ tree-vect-slp.c     (working copy)
@@ -1662,7 +1662,6 @@  vect_get_constant_vectors (slp_tree slp_
              break;

           case MULT_EXPR:
-          case BIT_AND_EXPR:
              if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (op)))
                neutral_op = build_real (TREE_TYPE (op), dconst1);
              else
@@ -1670,6 +1669,10 @@  vect_get_constant_vectors (slp_tree slp_

              break;

+          case BIT_AND_EXPR:
+            neutral_op = build_int_cst (TREE_TYPE (op), -1);
+            break;
+
           default:
              neutral_op = NULL;
         }
Index: testsuite/gcc.dg/vect/pr44507.c
===================================================================
--- testsuite/gcc.dg/vect/pr44507.c     (revision 0)
+++ testsuite/gcc.dg/vect/pr44507.c     (revision 0)
@@ -0,0 +1,55 @@ 
+/* { dg-require-effective-target vect_int } */
+
+#include <stdlib.h>
+#include "tree-vect.h"
+
+int seeIf256ByteArrayIsConstant(
+  unsigned char *pArray)
+{
+  int index;
+  unsigned int curVal, orVal, andVal;
+  int bytesAreEqual = 0;
+
+  if (pArray != 0)
+    {
+      for (index = 0, orVal = 0, andVal = 0xFFFFFFFF;
+           index < 64;
+           index += (int)sizeof(unsigned int))
+        {
+          curVal = *((unsigned long *)(&pArray[index]));
+          orVal = orVal | curVal;
+          andVal = andVal & curVal;
+        }
+
+      if (!((orVal == andVal)
+            && ((orVal >> 8) == (andVal & 0x00FFFFFF))))
+        abort ();
+    }
+
+  return 0;
+}
+
+
+int main(int argc, char** argv)
+{
+  unsigned char array1[64] = {
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+  };
+
+  argv = argv;
+  argc = argc;
+
+  check_vect ();
+
+  return seeIf256ByteArrayIsConstant(&array1[0]);
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
+



4.5:

ChangeLog

      PR tree-optimization/44507
      * tree-vect-loop.c (get_initial_def_for_reduction): Use -1
      to build initial vector for BIT_AND_EXPR.

testsuite/ChangeLog

      PR tree-optimization/44507
      * gcc.dg/vect/pr44507.c: New test.


Index: tree-vect-loop.c
===================================================================
--- tree-vect-loop.c    (revision 160682)
+++ tree-vect-loop.c    (working copy)
@@ -2748,12 +2748,15 @@  get_initial_def_for_reduction (gimple st
               *adjustment_def = init_val;
           }

-        if (code == MULT_EXPR || code == BIT_AND_EXPR)
+        if (code == MULT_EXPR)
           {
             real_init_val = dconst1;
             int_init_val = 1;
           }

+        if (code == BIT_AND_EXPR)
+          int_init_val = -1;
+
         if (SCALAR_FLOAT_TYPE_P (scalar_type))
           def_for_init = build_real (scalar_type, real_init_val);
         else
Index: testsuite/gcc.dg/vect/pr44507.c
===================================================================
--- testsuite/gcc.dg/vect/pr44507.c     (revision 0)
+++ testsuite/gcc.dg/vect/pr44507.c     (revision 0)
@@ -0,0 +1,55 @@ 
+/* { dg-require-effective-target vect_int } */
+
+#include <stdlib.h>
+#include "tree-vect.h"
+
+int seeIf256ByteArrayIsConstant(
+  unsigned char *pArray)
+{
+  int index;
+  unsigned int curVal, orVal, andVal;
+  int bytesAreEqual = 0;
+
+  if (pArray != 0)
+    {
+      for (index = 0, orVal = 0, andVal = 0xFFFFFFFF;
+           index < 64;
+           index += (int)sizeof(unsigned int))
+        {
+          curVal = *((unsigned long *)(&pArray[index]));
+          orVal = orVal | curVal;
+          andVal = andVal & curVal;
+        }
+
+      if (!((orVal == andVal)
+            && ((orVal >> 8) == (andVal & 0x00FFFFFF))))
+        abort ();
+    }
+
+  return 0;
+}
+
+
+int main(int argc, char** argv)
+{
+  unsigned char array1[64] = {
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+  };
+
+  argv = argv;
+  argc = argc;
+
+  check_vect ();
+
+  return seeIf256ByteArrayIsConstant(&array1[0]);
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
+