From patchwork Mon Nov 4 08:55:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1188835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512293-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="dne15QmV"; 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 47668b0Xpfz9sP3 for ; Mon, 4 Nov 2019 19:55:56 +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=nOaotC7QgBaFuQnjxMSlXJvHdU+KzVOsU8fza8FU2+rLndrxOqB2I T8vXhgqVr4Jg8sNxbbJ9xsHgLC7wb4+ukTuQX8RGqWur+ZQnjToEM6OFN5h4xY8c fqrDYFV6a422BWWFFVxyIOauDVyWlBaruDQnwJw+8TR2F//YtFo88c= 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=JsQO52aGQCTmqM3R66j4Mb1ZezM=; b=dne15QmV1usvMxdY3x1A wv4U2Kbrrve8Xv4wEnPC5eWDvgNJn+OLXwSRIvHqLVEFNiYnYFjvTTTHlAKEWOHB Eb90bxhOwyR5R5/9Ri8aX8sMRk5X9m7ajMsO0wDMIx25Ozj/3iePRhvTW7hFc3Mu eou/Mfhy4A3zq7ogl6dQ/IY= Received: (qmail 107184 invoked by alias); 4 Nov 2019 08:55:49 -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 107175 invoked by uid 89); 4 Nov 2019 08:55:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.1 spammy= 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; Mon, 04 Nov 2019 08:55:48 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5716EB22E for ; Mon, 4 Nov 2019 08:55:46 +0000 (UTC) Date: Mon, 4 Nov 2019 09:55:46 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR92301 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 The following fixes epilogue loop generation for reductions where the reduction result isn't live. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2019-11-04 Richard Biener PR tree-optimization/92301 * tree-vect-stmts.c (process_use): Force reduction PHI defs live as required by epilogue generation * gcc.dg/pr92301.c: New testcase. Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c (revision 277765) +++ gcc/tree-vect-stmts.c (working copy) @@ -475,6 +475,22 @@ process_use (stmt_vec_info stmt_vinfo, t basic_block def_bb = gimple_bb (dstmt_vinfo->stmt); basic_block bb = gimple_bb (stmt_vinfo->stmt); + /* case 2: A reduction phi (STMT) defined by a reduction stmt (DSTMT_VINFO). + We have to force the stmt live since the epilogue loop needs it to + continue computing the reduction. */ + if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI + && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def + && gimple_code (dstmt_vinfo->stmt) != GIMPLE_PHI + && STMT_VINFO_DEF_TYPE (dstmt_vinfo) == vect_reduction_def + && bb->loop_father == def_bb->loop_father) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, + "reduc-stmt defining reduc-phi in the same nest.\n"); + vect_mark_relevant (worklist, dstmt_vinfo, relevant, true); + return opt_result::success (); + } + /* case 3a: outer-loop stmt defining an inner-loop stmt: outer-loop-header-bb: d = dstmt_vinfo Index: gcc/testsuite/gcc.dg/pr92301.c =================================================================== --- gcc/testsuite/gcc.dg/pr92301.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr92301.c (working copy) @@ -0,0 +1,35 @@ +/* { dg-do run } */ +/* { dg-options "-O3" } */ + +unsigned int m; + +#define N 128 +unsigned int a[N]; + +unsigned int +__attribute__((noipa)) +df_count_refs (_Bool include_defs) +{ + int size = 0; + + for (unsigned int regno = 0; regno < m; regno++) + if (include_defs) + size += a[regno]; + return size; +} + +int main(int argc, char **argv) +{ + for (unsigned i = 0; i < N; i++) + a[i] = i; + + if (argc == 1) + m = 17; + + unsigned int r = df_count_refs(1); + __builtin_printf ("r: %d\n", r); + if (r != 136) + __builtin_abort (); + + return 0; +}