From patchwork Fri Aug 5 11:12:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 108640 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 55D20B6F75 for ; Fri, 5 Aug 2011 21:13:16 +1000 (EST) Received: (qmail 2593 invoked by alias); 5 Aug 2011 11:13:14 -0000 Received: (qmail 2580 invoked by uid 22791); 5 Aug 2011 11:13:12 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from mtagate7.uk.ibm.com (HELO mtagate7.uk.ibm.com) (194.196.100.167) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 05 Aug 2011 11:12:56 +0000 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p75BCtwf002293 for ; Fri, 5 Aug 2011 11:12:55 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p75BCsxT2293810 for ; Fri, 5 Aug 2011 12:12:55 +0100 Received: from d06av07.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p75BCsDh002606 for ; Fri, 5 Aug 2011 05:12:54 -0600 Received: from d12mc102.megacenter.de.ibm.com (d12mc102.megacenter.de.ibm.com [9.149.167.114]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p75BCs1x002601 for ; Fri, 5 Aug 2011 05:12:54 -0600 Subject: [patch, vectorizer] Fix a bug in creation of reduction epilogue X-KeepSent: C58B9842:A91FFDB7-C22578E3:00364C0F; type=4; name=$KeepSent To: gcc-patches@gcc.gnu.org Cc: Ulrich Weigand Message-ID: From: Ira Rosen Date: Fri, 5 Aug 2011 14:12:50 +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, In case of multiple loop exit phis in vectorization of reduction we reduce them to one vector. The result of this reduction is later ignored in case we do the final value extraction with scalar code. This causes wrong code generation for gfortran.dg/forall_7.f90 with -O3 -funroll-loops on Cell SPU. This patch fixes this. Bootstrapped on powerpc64-suse-linux and tested on powerpc64-suse-linux and on spu-redhat-linux. Committed. Ira ChangeLog: * tree-vect-loop.c (vect_create_epilog_for_reduction): Use the result of multiple results reduction when extracting the final value using scalar code. Index: tree-vect-loop.c =================================================================== --- tree-vect-loop.c (revision 177266) +++ tree-vect-loop.c (working copy) @@ -3683,13 +3683,13 @@ vect_create_epilog_for_reduction (VEC (tree, heap) { tree first_vect = PHI_RESULT (VEC_index (gimple, new_phis, 0)); tree tmp; + gimple new_vec_stmt = NULL; vec_dest = vect_create_destination_var (scalar_dest, vectype); for (k = 1; k < VEC_length (gimple, new_phis); k++) { gimple next_phi = VEC_index (gimple, new_phis, k); tree second_vect = PHI_RESULT (next_phi); - gimple new_vec_stmt; tmp = build2 (code, vectype, first_vect, second_vect); new_vec_stmt = gimple_build_assign (vec_dest, tmp); @@ -3699,6 +3699,11 @@ vect_create_epilog_for_reduction (VEC (tree, heap) } new_phi_result = first_vect; + if (new_vec_stmt) + { + VEC_truncate (gimple, new_phis, 0); + VEC_safe_push (gimple, heap, new_phis, new_vec_stmt); + } } else new_phi_result = PHI_RESULT (VEC_index (gimple, new_phis, 0)); @@ -3809,7 +3814,10 @@ vect_create_epilog_for_reduction (VEC (tree, heap) vec_size_in_bits = tree_low_cst (TYPE_SIZE (vectype), 1); FOR_EACH_VEC_ELT (gimple, new_phis, i, new_phi) { - vec_temp = PHI_RESULT (new_phi); + if (gimple_code (new_phi) == GIMPLE_PHI) + vec_temp = PHI_RESULT (new_phi); + else + vec_temp = gimple_assign_lhs (new_phi); rhs = build3 (BIT_FIELD_REF, scalar_type, vec_temp, bitsize, bitsize_zero_node); epilog_stmt = gimple_build_assign (new_scalar_dest, rhs);