From patchwork Mon Jun 14 12:23:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [vectorizer] Fix PR tree-optimization/44507 From: Ira Rosen X-Patchwork-Id: 55521 Message-Id: To: gcc-patches@gcc.gnu.org Date: Mon, 14 Jun 2010 15:23:07 +0300 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. 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 +#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 +#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" } } */ +