From patchwork Thu Aug 6 10:20:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1341567 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=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4BMkyw26Nrz9sR4 for ; Thu, 6 Aug 2020 20:20:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D8C23857C41; Thu, 6 Aug 2020 10:20:38 +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 154613858D37 for ; Thu, 6 Aug 2020 10:20:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 154613858D37 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 4ADFDAD83 for ; Thu, 6 Aug 2020 10:20:52 +0000 (UTC) Date: Thu, 6 Aug 2020 12:20:35 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/96491 - avoid store commoning across abnormal edges 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" This avoids store commoning across abnormal edges since that easily can disrupt abnormal coalescing because it might create overlapping lifetime of variables. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2020-08-06 Richard Biener PR tree-optimization/96491 * tree-ssa-sink.c (sink_common_stores_to_bb): Avoid sinking across abnormal edges. * gcc.dg/torture/pr96491.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr96491.c | 29 ++++++++++++++++++++++++++ gcc/tree-ssa-sink.c | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr96491.c diff --git a/gcc/testsuite/gcc.dg/torture/pr96491.c b/gcc/testsuite/gcc.dg/torture/pr96491.c new file mode 100644 index 00000000000..784559f4754 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr96491.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ + +int rj; + +void __attribute__ ((returns_twice)) +da (void) +{ + rj = 1; +} + +void +c5 (void) +{ + for (;;) + ++rj; +} + +void +ls (int kz) +{ + if (kz == 0) + { + rj = 0; + c5 (); + } + + da (); + c5 (); +} diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c index 962ad076968..4cc5195f2f8 100644 --- a/gcc/tree-ssa-sink.c +++ b/gcc/tree-ssa-sink.c @@ -503,7 +503,8 @@ sink_common_stores_to_bb (basic_block bb) tree arg = gimple_phi_arg_def (phi, i); gimple *def = SSA_NAME_DEF_STMT (arg); if (! is_gimple_assign (def) - || stmt_can_throw_internal (cfun, def)) + || stmt_can_throw_internal (cfun, def) + || (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL)) { /* ??? We could handle some cascading with the def being another PHI. We'd have to insert multiple PHIs for