From patchwork Sun May 22 08:11:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 96720 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 1394CB6FB2 for ; Sun, 22 May 2011 18:11:49 +1000 (EST) Received: (qmail 12518 invoked by alias); 22 May 2011 08:11:46 -0000 Received: (qmail 12509 invoked by uid 22791); 22 May 2011 08:11:43 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate1.uk.ibm.com (HELO mtagate1.uk.ibm.com) (194.196.100.161) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 22 May 2011 08:11:24 +0000 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p4M8BMPp027381 for ; Sun, 22 May 2011 08:11:22 GMT Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4M8BMNE2486300 for ; Sun, 22 May 2011 09:11:22 +0100 Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4M8BMWT029759 for ; Sun, 22 May 2011 02:11:22 -0600 Received: from d12mc102.megacenter.de.ibm.com (d12mc102.megacenter.de.ibm.com [9.149.167.114]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p4M8BMYr029756; Sun, 22 May 2011 02:11:22 -0600 In-Reply-To: References: <4DD67554.5050904@qnx.com> Subject: [patch] Fix PR 49087 (was Re: Fix crash in vect_is_slp_reduction) X-KeepSent: D2D58475:C4B522E0-C2257898:002A6B67; type=4; name=$KeepSent To: Ira Rosen Cc: gcc-patches@gcc.gnu.org, Richard Guenther , Ryan Mansfield Message-ID: From: Ira Rosen Date: Sun, 22 May 2011 11:11:19 +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 > > > > No, we shouldn't arrive with a NULL use_stmt here. > > I think a proper fix will be to fail if there are no uses. > I'll prepare a patch on Sunday. > Here is the patch. It bails out if LHS has no uses. Bootstrapped and tested on powerpc64-suse-linux. Committed. Ira ChangeLog: PR tree-optimization/49087 * tree-vect-loop.c (vect_is_slp_reduction): Fail if LHS has no uses. testsuite/ChangeLog: PR tree-optimization/49087 * gcc.dg/vect/O3-pr49087.c: New test. Index: tree-vect-loop.c =================================================================== --- tree-vect-loop.c (revision 174025) +++ tree-vect-loop.c (working copy) @@ -1704,7 +1704,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, nuses; bool found = false; if (loop != vect_loop) @@ -1715,9 +1715,11 @@ vect_is_slp_reduction (loop_vec_info loop_info, gi while (1) { nloop_uses = 0; + nuses = 0; FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs) { use_stmt = USE_STMT (use_p); + nuses++; if (is_gimple_debug (use_stmt)) continue; @@ -1739,6 +1741,10 @@ vect_is_slp_reduction (loop_vec_info loop_info, gi return false; } + /* We reached a statement with no uses. */ + if (nuses == 0) + return false; + if (found) break; Index: testsuite/gcc.dg/vect/O3-pr49087.c =================================================================== --- testsuite/gcc.dg/vect/O3-pr49087.c (revision 0) +++ testsuite/gcc.dg/vect/O3-pr49087.c (revision 0) @@ -0,0 +1,37 @@ +/* { dg-do compile } */ + +static char func2() { } + +struct S0 +{ + int t; +}; + +int g; + +struct S0 s0; + +int +foo (int arg) +{ + int *ptr = &g; + int i, j; + for (i = 0; i < 10; i += 1) + { + for (j = 0; j < 1; j += 1) + { + int k; + if (arg) + { + int l; + for (k = 1; arg < 10; arg = func2 ()) + { + return l; + } + } + *ptr = func2 () ^ s0.t; + } + } +} + +/* { dg-final { cleanup-tree-dump "vect" } } */