From patchwork Tue Nov 13 13:57:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 997125 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489890-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FSMYolVb"; dkim-atps=neutral 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 42vThs6RNzz9s3x for ; Wed, 14 Nov 2018 00:57:32 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=ha68qHmSDITpxJq2Zd8uKZvl4drtdAZpmp7t89+HEDz20Ljz5PTOV NFMfJftVvi420rOp1IHyItgbsBEkAJz+ZRIIJsPxTdNNSTlAUsAFL8YaO2CIrvlI nIg1VXr1W2nxmk+YV9xskJGiqtl/PpcEhZ8y+ezGpU9m3g+VKKnRLI= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=3hB5vBaQ5aBIo+BtCzbCXTdbJLg=; b=FSMYolVbASXdZi8iLGU6 spC1XZaJj3yk7M3sO9tMWeDuy63fKfTsqZ42n04jPJiNEA+2TjidNMbgw4JExl9/ X0C0Wo5JftE/bsBOVmosWtvAdd3z4h7yTpDHUoZU6/L1+7DbXk9CGxHNEarSHiRx R13sWJvzHA9Gu6CWIlmnEHE= Received: (qmail 9982 invoked by alias); 13 Nov 2018 13:57:25 -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 9967 invoked by uid 89); 13 Nov 2018 13:57:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy=lying, delaying, PHI_RESULT, Delay X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Nov 2018 13:57:23 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D0C9EB13B for ; Tue, 13 Nov 2018 13:57:20 +0000 (UTC) Date: Tue, 13 Nov 2018 14:57:20 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR86991 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This PR shows we have stale reduction groups lying around because the fixup doesn't work reliably with reduction chains. Fixed by delaying the build to after detection is successful. Bootstrap & regtest running on x86_64-unknown-linux-gnu. Richard. 2018-11-13 Richard Biener PR tree-optimization/86991 * tree-vect-loop.c (vect_is_slp_reduction): Delay reduction group building until we have successfully detected the SLP reduction. (vect_is_simple_reduction): Remove fixup code here. * gcc.dg/pr86991.c: New testcase. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 266071) +++ gcc/tree-vect-loop.c (working copy) @@ -2476,6 +2476,7 @@ vect_is_slp_reduction (loop_vec_info loo if (loop != vect_loop) return false; + auto_vec reduc_chain; lhs = PHI_RESULT (phi); code = gimple_assign_rhs_code (first_stmt); while (1) @@ -2528,17 +2529,9 @@ vect_is_slp_reduction (loop_vec_info loo /* Insert USE_STMT into reduction chain. */ use_stmt_info = loop_info->lookup_stmt (loop_use_stmt); - if (current_stmt_info) - { - REDUC_GROUP_NEXT_ELEMENT (current_stmt_info) = use_stmt_info; - REDUC_GROUP_FIRST_ELEMENT (use_stmt_info) - = REDUC_GROUP_FIRST_ELEMENT (current_stmt_info); - } - else - REDUC_GROUP_FIRST_ELEMENT (use_stmt_info) = use_stmt_info; + reduc_chain.safe_push (use_stmt_info); lhs = gimple_assign_lhs (loop_use_stmt); - current_stmt_info = use_stmt_info; size++; } @@ -2548,10 +2541,9 @@ vect_is_slp_reduction (loop_vec_info loo /* Swap the operands, if needed, to make the reduction operand be the second operand. */ lhs = PHI_RESULT (phi); - stmt_vec_info next_stmt_info = REDUC_GROUP_FIRST_ELEMENT (current_stmt_info); - while (next_stmt_info) + for (unsigned i = 0; i < reduc_chain.length (); ++i) { - gassign *next_stmt = as_a (next_stmt_info->stmt); + gassign *next_stmt = as_a (reduc_chain[i]->stmt); if (gimple_assign_rhs2 (next_stmt) == lhs) { tree op = gimple_assign_rhs1 (next_stmt); @@ -2565,7 +2557,6 @@ vect_is_slp_reduction (loop_vec_info loo && vect_valid_reduction_input_p (def_stmt_info)) { lhs = gimple_assign_lhs (next_stmt); - next_stmt_info = REDUC_GROUP_NEXT_ELEMENT (next_stmt_info); continue; } @@ -2600,9 +2591,16 @@ vect_is_slp_reduction (loop_vec_info loo } lhs = gimple_assign_lhs (next_stmt); - next_stmt_info = REDUC_GROUP_NEXT_ELEMENT (next_stmt_info); } + /* Build up the actual chain. */ + for (unsigned i = 0; i < reduc_chain.length () - 1; ++i) + { + REDUC_GROUP_FIRST_ELEMENT (reduc_chain[i]) = reduc_chain[0]; + REDUC_GROUP_NEXT_ELEMENT (reduc_chain[i]) = reduc_chain[i+1]; + } + REDUC_GROUP_NEXT_ELEMENT (reduc_chain.last ()) = NULL; + /* Save the chain for further analysis in SLP detection. */ stmt_vec_info first_stmt_info = REDUC_GROUP_FIRST_ELEMENT (current_stmt_info); @@ -3182,16 +3196,6 @@ vect_is_simple_reduction (loop_vec_info return def_stmt_info; } - /* Dissolve group eventually half-built by vect_is_slp_reduction. */ - stmt_vec_info first = REDUC_GROUP_FIRST_ELEMENT (def_stmt_info); - while (first) - { - stmt_vec_info next = REDUC_GROUP_NEXT_ELEMENT (first); - REDUC_GROUP_FIRST_ELEMENT (first) = NULL; - REDUC_GROUP_NEXT_ELEMENT (first) = NULL; - first = next; - } - /* Look for the expression computing loop_arg from loop PHI result. */ if (check_reduction_path (vect_location, loop, phi, loop_arg, code)) return def_stmt_info; Index: gcc/testsuite/gcc.dg/pr86991.c =================================================================== --- gcc/testsuite/gcc.dg/pr86991.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr86991.c (working copy) @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +int b; +extern unsigned c[]; +unsigned d; +long e; + +void f() +{ + unsigned g, h; + for (; d; d += 2) { + g = 1; + for (; g; g += 3) { + h = 2; + for (; h < 6; h++) + c[h] = c[h] - b - ~e; + } + } +}