From patchwork Fri Jan 10 13:51:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1221100 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-517102-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=U8i6UnG7; 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 47vPYK3kyHz9sPn for ; Sat, 11 Jan 2020 00:52:03 +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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=aILcts+Je7lqVq0/2QLcN24LYXIfPsYjRwicKFl9/dIvYaJQmy yjLNBclbM9t+0lRJZuUlefeQOQBfmMI3t0twJX+H2lOwVosOXOTh3ck4c1Ugqzdn RKbUKfVCrWCX6lGR5fbrx2JQB19HaZhMalojGrs+kK7PVjz/x47iD/y/0= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=fOzoVdYPwG3UbVoH+AvBFiZe9sw=; b=U8i6UnG7EdVFzC8kY4Rq 3k6IqqMN8cEv2tI09hoLNWcaeG/YDLImqODngIamPQLYTHlfJIyppoPc/hc8PRDA SkfvPTmzREM+TUo7HgeJmDw33QQWT5xURqxhDZO1zflH5L9S9QE92e1ItnGfa0yp zDAU/QxZhkJO2tTTmtRA4NQ= Received: (qmail 73528 invoked by alias); 10 Jan 2020 13:51:55 -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 73518 invoked by uid 89); 10 Jan 2020 13:51:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=Andre, prepared, Vieira, 86** X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Jan 2020 13:51:53 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 12702328; Fri, 10 Jan 2020 05:51:52 -0800 (PST) Received: from [10.2.78.48] (e107157-lin.cambridge.arm.com [10.2.78.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 94B2C3F534; Fri, 10 Jan 2020 05:51:51 -0800 (PST) To: gcc-patches Cc: Richard Biener , Richard Sandiford From: "Andre Vieira (lists)" Subject: [PATCH][vect] PR92429: do not fold when updating epilogue statements Message-ID: <03a1edb5-f1d2-9285-70d3-ea008a765bd0@arm.com> Date: Fri, 10 Jan 2020 13:51:50 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 X-IsSubscribed: yes Hi, This patch addresses the problem reported in PR92429. When creating an epilogue for vectorization we have to replace the SSA_NAMEs in the PATTERN_DEF_SEQs and RELATED_STMTs of the epilogue's loop_vec_infos. When doing this we were using simplify_replace_tree which always folds the replacement. This may lead to a different tree-node than the one which was analyzed in vect_loop_analyze. In turn the new tree-node may require a different vectorization than the one we had prepared for which caused the ICE in question. This patch adds a parameter to the simplify_replace_tree function such that we can optionally disable folding as this patch does in update_epilogue_loop_vinfo. Bootstrapped and regression tested on x86_64. Is this OK for trunk? gcc/ChangeLog: 2020-01-10 Andre Vieira PR tree-optimization/92429 * tree-ssa-loop-niter.h (simplify_replace_tree): Add parameter. * tree-ssa-loop-niter.c (simplify_replace_tree): Add parameter to control folding. * tree-vect-loop.c (update_epilogue_vinfo): Do not fold when replacing tree. gcc/testsuite/ChangeLog: 2020-01-10 Andre Vieira PR tree-optimization/92429 * gcc.dg/vect/pr92429.c diff --git a/gcc/testsuite/gcc.dg/vect/pr92429.c b/gcc/testsuite/gcc.dg/vect/pr92429.c new file mode 100644 index 0000000000000000000000000000000000000000..7885cd6e4c2639f553a68edcbd70203d1b7b13bb --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr92429.c @@ -0,0 +1,14 @@ +/* PR92429 */ +/* { dg-do compile } */ +/* { dg-additional-options "-O1 -fno-tree-fre" } */ +/* { dg-additional-options "-mavx2" { target { x86_64-*-* i?86-*-* } } } */ + +void +as (int *gl, int k1) +{ + while (k1 < 1) + { + gl[k1] = gl[k1] * gl[k1] / 2; + ++k1; + } +} diff --git a/gcc/tree-ssa-loop-niter.h b/gcc/tree-ssa-loop-niter.h index 621e2c2e28dfbeda279687dcae78e9c4fbe7f559..eb8d1579479cf6df66f9486c7ce6f9ac20a02e2a 100644 --- a/gcc/tree-ssa-loop-niter.h +++ b/gcc/tree-ssa-loop-niter.h @@ -58,7 +58,7 @@ extern void free_numbers_of_iterations_estimates (class loop *); extern void free_numbers_of_iterations_estimates (function *); extern tree simplify_replace_tree (tree, tree, tree, tree (*)(tree, void *) = NULL, - void * = NULL); + void * = NULL, bool do_fold = true); extern void substitute_in_loop_info (class loop *, tree, tree); #endif /* GCC_TREE_SSA_LOOP_NITER_H */ diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 4d5e04945118880d0c0cfb00d9c5841cc58e46f5..6e6df0bfdb898de948c917640ff488b19cf7911f 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -1934,7 +1934,8 @@ number_of_iterations_cond (class loop *loop, tree simplify_replace_tree (tree expr, tree old, tree new_tree, - tree (*valueize) (tree, void*), void *context) + tree (*valueize) (tree, void*), void *context, + bool do_fold) { unsigned i, n; tree ret = NULL_TREE, e, se; @@ -1966,7 +1967,7 @@ simplify_replace_tree (tree expr, tree old, tree new_tree, for (i = 0; i < n; i++) { e = TREE_OPERAND (expr, i); - se = simplify_replace_tree (e, old, new_tree, valueize, context); + se = simplify_replace_tree (e, old, new_tree, valueize, context, do_fold); if (e == se) continue; @@ -1976,7 +1977,7 @@ simplify_replace_tree (tree expr, tree old, tree new_tree, TREE_OPERAND (ret, i) = se; } - return (ret ? fold (ret) : expr); + return (ret ? (do_fold ? fold (ret) : ret) : expr); } /* Expand definitions of ssa names in EXPR as long as they are simple diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index cf9b7bcb9c41d678b326b41a4167f1e9c00cc5a4..f30e104e9958c0ebaf170004747ff436b1c1d855 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -8440,8 +8440,13 @@ update_epilogue_loop_vinfo (class loop *epilogue, tree advance, gimple_set_op (stmt, j, *new_op); else { + /* PR92429: The last argument of simplify_replace_tree disables + folding when replacing arguments. This is required as + otherwise you might end up with different statements than the + ones analyzed in vect_loop_analyze, leading to different + vectorization. */ op = simplify_replace_tree (op, NULL_TREE, NULL_TREE, - &find_in_mapping, &mapping); + &find_in_mapping, &mapping, false); gimple_set_op (stmt, j, op); } }