From patchwork Mon Jun 14 12:23:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 55521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 1D4FFB7D8B for ; Mon, 14 Jun 2010 22:23:47 +1000 (EST) Received: (qmail 26047 invoked by alias); 14 Jun 2010 12:23:26 -0000 Received: (qmail 25843 invoked by uid 22791); 14 Jun 2010 12:23:21 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_RG, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate7.de.ibm.com (HELO mtagate7.de.ibm.com) (195.212.17.167) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Jun 2010 12:23:15 +0000 Received: from d12nrmr1507.megacenter.de.ibm.com (d12nrmr1507.megacenter.de.ibm.com [9.149.167.1]) by mtagate7.de.ibm.com (8.13.1/8.13.1) with ESMTP id o5ECNCE3032147 for ; Mon, 14 Jun 2010 12:23:12 GMT Received: from d12av05.megacenter.de.ibm.com (d12av05.megacenter.de.ibm.com [9.149.165.216]) by d12nrmr1507.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5ECNCYs1454302 for ; Mon, 14 Jun 2010 14:23:12 +0200 Received: from d12av05.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av05.megacenter.de.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5ECNBaO027712 for ; Mon, 14 Jun 2010 14:23:11 +0200 Received: from d12mc102.megacenter.de.ibm.com (d12mc102.megacenter.de.ibm.com [9.149.167.114]) by d12av05.megacenter.de.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o5ECNBw3027702 for ; Mon, 14 Jun 2010 14:23:11 +0200 Subject: [patch, vectorizer] Fix PR tree-optimization/44507 X-KeepSent: 1CF9E5A0:6EC369D8-C2257742:0040C86C; type=4; name=$KeepSent To: gcc-patches@gcc.gnu.org Message-ID: From: Ira Rosen Date: Mon, 14 Jun 2010 15:23:07 +0300 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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" } } */ +