From patchwork Mon Sep 21 12:06:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1368307 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bw37p59H2z9sTW for ; Mon, 21 Sep 2020 22:06:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80C3D386F417; Mon, 21 Sep 2020 12:06:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 3A1603857021 for ; Mon, 21 Sep 2020 12:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3A1603857021 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2F485ACA3 for ; Mon, 21 Sep 2020 12:06:57 +0000 (UTC) Date: Mon, 21 Sep 2020 14:06:20 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/97135 - fix dependence check in store-motion Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The following fixes a dependence check where in the particular place we cannot ignore self-dependences. Bootstrapped / tested on x86_64-unknown-linux-gnu, pushed. 2020-09-21 Richard Biener PR tree-optimization/97135 * tree-ssa-loop-im.c (sm_seq_push_down): Do not ignore self-dependences. * gcc.dg/torture/pr97135.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr97135.c | 21 +++++++++++++++++++++ gcc/tree-ssa-loop-im.c | 8 +++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr97135.c diff --git a/gcc/testsuite/gcc.dg/torture/pr97135.c b/gcc/testsuite/gcc.dg/torture/pr97135.c new file mode 100644 index 00000000000..223f4d05b85 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr97135.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ + +long long e, *d = &e; +int a, b, c; + +int +main () +{ + for (; c <= 5; c++) + for (b = 0; b <= 5; b++) + { + for (a = 1; a <= 5; a++) + ; + *d = 0; + if (c) + break; + } + if (a != 6) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index f87c287d742..139c7e76e66 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -2232,9 +2232,11 @@ sm_seq_push_down (vec &seq, unsigned ptr, unsigned *at) || (against.second == sm_other && against.from != NULL_TREE)) /* Found the tail of the sequence. */ break; - if (!refs_independent_p (memory_accesses.refs_list[new_cand.first], - memory_accesses.refs_list[against.first], - false)) + /* We may not ignore self-dependences here. */ + if (new_cand.first == against.first + || !refs_independent_p (memory_accesses.refs_list[new_cand.first], + memory_accesses.refs_list[against.first], + false)) /* ??? Prune new_cand from the list of refs to apply SM to. */ return false; std::swap (new_cand, against);