From patchwork Mon Aug 1 16:59:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 107784 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 5E658B702E for ; Tue, 2 Aug 2011 02:59:24 +1000 (EST) Received: (qmail 1928 invoked by alias); 1 Aug 2011 16:59:20 -0000 Received: (qmail 1900 invoked by uid 22791); 1 Aug 2011 16:59:19 -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; Mon, 01 Aug 2011 16:59:05 +0000 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p71Gx33R001473 for ; Mon, 1 Aug 2011 16:59:03 GMT Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p71Gx3sF1941648 for ; Mon, 1 Aug 2011 17:59:03 +0100 Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p71Gx3uc021340 for ; Mon, 1 Aug 2011 17:59:03 +0100 Received: from d12mc102.megacenter.de.ibm.com (d12mc102.megacenter.de.ibm.com [9.149.167.114]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p71Gx3UD021337 for ; Mon, 1 Aug 2011 17:59:03 +0100 Subject: [patch] Fix PR tree-optimization/49926 X-KeepSent: 833544DB:8E8CDE67-C22578DF:005A4A04; type=4; name=$KeepSent To: gcc-patches@gcc.gnu.org Message-ID: From: Ira Rosen Date: Mon, 1 Aug 2011 19:59:00 +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 adds another missing check for SLP reduction detection: we should check that a statement in a reduction chain has either one use inside the loop, or two uses: in the reduction phi node and the loop exit phi node. Bootstrapped and tested on powerpc64-suse-linux. Applied to trunk. Ira ChangeLog: PR tree-optimization/49926 * tree-vect-loop.c (vect_is_slp_reduction): Check that a statement in a chain doesn't have uses both inside and outside the loop. testsuite/ChangeLog: PR tree-optimization/49926 * gcc.dg/vect/pr49926.c: New test. Index: tree-vect-loop.c =================================================================== --- tree-vect-loop.c (revision 177062) +++ tree-vect-loop.c (working copy) @@ -1730,7 +1730,7 @@ vect_is_slp_reduction (loop_vec_info loop_info, gi tree lhs; imm_use_iterator imm_iter; use_operand_p use_p; - int nloop_uses, size = 0; + int nloop_uses, size = 0, n_out_of_loop_uses; bool found = false; if (loop != vect_loop) @@ -1741,6 +1741,7 @@ vect_is_slp_reduction (loop_vec_info loop_info, gi while (1) { nloop_uses = 0; + n_out_of_loop_uses = 0; FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs) { gimple use_stmt = USE_STMT (use_p); @@ -1757,16 +1758,22 @@ vect_is_slp_reduction (loop_vec_info loop_info, gi break; } - if (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)) - && vinfo_for_stmt (use_stmt) - && !STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (use_stmt))) - { - loop_use_stmt = use_stmt; - nloop_uses++; - } + if (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt))) + { + if (vinfo_for_stmt (use_stmt) + && !STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (use_stmt))) + { + loop_use_stmt = use_stmt; + nloop_uses++; + } + } + else + n_out_of_loop_uses++; - if (nloop_uses > 1) - return false; + /* There are can be either a single use in the loop or two uses in + phi nodes. */ + if (nloop_uses > 1 || (n_out_of_loop_uses && nloop_uses)) + return false; } if (found) Index: testsuite/gcc.dg/vect/pr49926.c =================================================================== --- testsuite/gcc.dg/vect/pr49926.c (revision 0) +++ testsuite/gcc.dg/vect/pr49926.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ + +int a, b, c[10]; + +void +foo (unsigned int x, int y, int z, int *w) +{ + do + { + *w = z; + y = x; + if (y) + for (b = -4; b; b++) + { + z = y &= a &= 1; + y &= c[b + 4]; + } + } + while (1); +} + +/* { dg-final { cleanup-tree-dump "vect" } } */