From patchwork Wed Feb 25 11:35:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 443365 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B18441400B6 for ; Wed, 25 Feb 2015 22:36:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Vt7hlfQc; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=D+2P1/U5e9wkRnfDGR c0BSCOoMdtUMGuKhB7/IehTx8Dm83mO4o0eTyBnkEvgKL3mMeKV6nUT7gH3QKdeC 8sLOHdOrgqMi1uoMv3nQkutsTBlOg9pAzH+zJx764qNdprff02bY65kpWWfe7UJ4 KhmWu6iUuvAMr4L2i3ymIKHjg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=yVdLcP4g9nP+jiLJWFZZXW9c WRk=; b=Vt7hlfQcRinRLAV1Y5DLHnnP4P3j1D5BUr2WWO6bYEqix4CGZ8y4v3l0 882gR6taSYi1j7kujrD9yDC9THSD6bNMsaUzzEyiOIREIfsJjeJv7v2ohWsyUqf9 tkQdUOk/JFMzPm09IjwlkL/aFc9tGJ7de7xSHHccCEW+HHwyRSE= Received: (qmail 101427 invoked by alias); 25 Feb 2015 11:35:53 -0000 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 Received: (qmail 101417 invoked by uid 89); 25 Feb 2015 11:35:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ob0-f181.google.com Received: from mail-ob0-f181.google.com (HELO mail-ob0-f181.google.com) (209.85.214.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 25 Feb 2015 11:35:51 +0000 Received: by mail-ob0-f181.google.com with SMTP id vb8so3099705obc.12 for ; Wed, 25 Feb 2015 03:35:49 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.202.204.88 with SMTP id c85mr1685047oig.81.1424864149877; Wed, 25 Feb 2015 03:35:49 -0800 (PST) Received: by 10.76.98.137 with HTTP; Wed, 25 Feb 2015 03:35:49 -0800 (PST) In-Reply-To: References: Date: Wed, 25 Feb 2015 12:35:49 +0100 Message-ID: Subject: Re: [patch]: [Bug tree-optimization/61917] [4.9/5 Regression] ICE on valid code at -O3 on x86_64-linux-gnu in vectorizable_reduction, at tree-vect-loop.c:4913 From: Richard Biener To: Kai Tietz Cc: GCC Patches , Jakub Jelinek X-IsSubscribed: yes On Wed, Feb 25, 2015 at 12:05 PM, Kai Tietz wrote: > 2015-02-25 11:57 GMT+01:00 Richard Biener : >> On Wed, Feb 25, 2015 at 11:06 AM, Kai Tietz wrote: >>> Hello, >>> >>> ChangeLog >>> >>> 2015-02-25 Kai Tietz >>> >>> PR tree-optimization/61917 >>> * tree-vect-loop.c (vectorizable_reduction): Allow >>> vect_internal_def without reduction to exit graceful. >>> >>> ChagneLog testsuite/ >>> >>> 2015-02-25 Kai Tietz >>> >>> PR tree-optimization/61917 >>> * gcc.dg/vect/vect-pr61917.c: New file. >>> >>> Tested for x86_64-unkown-linux. Ok for apply? >> >> It doesn't make much sense to fail here as said in the comment >> because of patterns if the actual case isn't a pattern. Also >> the patch causing this made vect_external_def possible, so >> why does this affect vect_internal_def here? >> >> It may paper over the issue - but clearly the fix is bogus. > > Well, actually I don't see any good reason for failing here at all, > but I assumed that author wanted to get by it some missed cases. > AFAIU the code we actually don't need/want to assert here either on > internal (where it is pretty likely no pattern present), and also on > externals, too. > I would be fine to remove this assert here completely, but I thought > it might be of interest to see that orig_stmt isn't NULL for nested > case I agree that the code is overusing asserts but the path you bail out on is bogus. Fact is that we somehow detected a reduction here (via special-casing of minus I guess) but fail to properly handle it later. In fact we assert that we end up with a PHI node in the definition but would ICE there as well. Thus a better patch would be Richard. > Kai > >> Richard. >> >>> Regards, >>> Kai >>> >>> Index: tree-vect-loop.c >>> =================================================================== >>> --- tree-vect-loop.c (Revision 220958) >>> +++ tree-vect-loop.c (Arbeitskopie) >>> @@ -4990,7 +4990,7 @@ vectorizable_reduction (gimple stmt, gimple_stmt_i >>> /* For pattern recognized stmts, orig_stmt might be a reduction, >>> but some helper statements for the pattern might not, or >>> might be COND_EXPRs with reduction uses in the condition. */ >>> - gcc_assert (orig_stmt); >>> + gcc_assert (orig_stmt || dt == vect_internal_def); >>> return false; >>> } >>> if (!found_nested_cycle_def) >>> Index: gcc/gcc/testsuite/gcc.dg/vect/vect-pr61917.c >>> =================================================================== >>> --- /dev/null >>> +++ gcc/gcc/testsuite/gcc.dg/vect/vect-pr61917.c >>> @@ -0,0 +1,13 @@ >>> +/* { dg-do compile } */ >>> +/* { dg-additional-options "-O3" } */ >>> + >>> +int a, b, c, d; >>> + >>> +int >>> +fn1 () >>> +{ >>> + for (; c; c++) >>> + for (b = 0; b < 2; b++) >>> + d = a - d; >>> + return d; >>> +} Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 220958) +++ gcc/tree-vect-loop.c (working copy) @@ -4981,6 +4981,13 @@ vectorizable_reduction (gimple stmt, gim if (!vectype_in) vectype_in = tem; gcc_assert (is_simple_use); + + /* If the defining stmt isn't a PHI node then this isn't a reduction. */ + if (!found_nested_cycle_def) + reduc_def_stmt = def_stmt; + if (gimple_code (reduc_def_stmt) != GIMPLE_PHI) + return false; + if (!(dt == vect_reduction_def || dt == vect_nested_cycle || ((dt == vect_internal_def || dt == vect_external_def @@ -4993,10 +5000,7 @@ vectorizable_reduction (gimple stmt, gim gcc_assert (orig_stmt); return false; } - if (!found_nested_cycle_def) - reduc_def_stmt = def_stmt; - gcc_assert (gimple_code (reduc_def_stmt) == GIMPLE_PHI); if (orig_stmt) gcc_assert (orig_stmt == vect_is_simple_reduction (loop_vinfo, reduc_def_stmt,