From patchwork Mon Nov 7 13:03:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 16404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2035786wru; Mon, 7 Nov 2022 05:05:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM7sWrUhICfmTbGl0JHdoxPMsPCfJFHZG9xuSl1BOiVMr/JMIyt3KiDGmL5HP1WCQSXewftN X-Received: by 2002:a17:907:7f02:b0:73d:dffa:57b3 with SMTP id qf2-20020a1709077f0200b0073ddffa57b3mr49584519ejc.19.1667826328978; Mon, 07 Nov 2022 05:05:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667826328; cv=none; d=google.com; s=arc-20160816; b=nFKf623qLXEzlIhFufidUO+013WrUHQzSRHeL6SGSjXnRu1waQ9urZQed0N9bpRBVy ry9Jlz11HxZkGc+P75L1nP30KyD2NzRKfBDg7sMVonpZwGh7dEl10Aql9RKJdkbnNhpa 3mKZj45xX5ruHCvvLLtJs5OpxSV4FKl8PBDCf/Pt9FGymW0OXibrQk/fS5PXeh7IZMMu mb+0F/nrU7pKDDeBH5agGHTRR6Igt5buTxVp5nCgYxNAk6EDfIbKjyzZ61KMjES/8xlJ xM0CFxLG4fWZf31xPYt7OyUxaomazkZQsMXlfIGGBmc0XVExHokqrzGy+Q0fL/zu7eY9 fxAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-filter :dmarc-filter:delivered-to; bh=xbcYejwkdW6Nw0EDFn5l3AFdxaZtuzH2xVqZYdcX++s=; b=hpTZIRw5upBSAXN6FM1hyVdhSwBRvOssUdIPaoqvlr5/JIfVv9Mdu00Eeya+yJ738X 26kg6n/0ts8+4kWVf/jKUn9IamfcCwFn9n9k5+4YTUGW/Ikh1kbvHbBK6BlvlX+CTpjn tHBjoHE+YvdqERrnwp29mo2vwou+jOLksyAOr9XP66r1uvyHYB1+B865KFaXRM10aK7J ty1fVQFzbTdX20wuQrXJwYEAU4gIiZo1J0z+s2hyvkA1B0+0AyMdfF1qt0M0R6yyv+sZ +OGSFyf2HnSpwUsaV3rzWQoz7DbVIyYKHRnelRFjtRwS+sLqSb/WEMN/TAEXe0W7Pb5q squA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id sh32-20020a1709076ea000b0078d8db64fffsi9061534ejc.20.2022.11.07.05.05.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 05:05:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1A223857012 for ; Mon, 7 Nov 2022 13:04:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 300203858402 for ; Mon, 7 Nov 2022 13:03:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 300203858402 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id BFE5C40737DB; Mon, 7 Nov 2022 13:03:07 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru BFE5C40737DB From: Alexander Monakov To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [committed] tree-ssa-sink: do not touch calls that return twice Date: Mon, 7 Nov 2022 16:03:02 +0300 Message-Id: <20221107130302.22073-1-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748842660662004840?= X-GMAIL-MSGID: =?utf-8?q?1748842660662004840?= Avoid moving pure/const calls that may return twice in tree-ssa-sink: properly redirecting the associated abnormal edge is non-trivial. gcc/ChangeLog: PR tree-optimization/107505 * tree-ssa-sink.cc (statement_sink_location): Additionally reject ECF_RETURNS_TWICE calls. gcc/testsuite/ChangeLog: PR tree-optimization/107505 * gcc.dg/pr107505.c: New test. --- Preapproved by Richi on the Bugzilla, pushed after testing. gcc/testsuite/gcc.dg/pr107505.c | 26 ++++++++++++++++++++++++++ gcc/tree-ssa-sink.cc | 5 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr107505.c diff --git a/gcc/testsuite/gcc.dg/pr107505.c b/gcc/testsuite/gcc.dg/pr107505.c new file mode 100644 index 000000000..01270eac9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107505.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-guess-branch-probability" } */ + +int n; + +void +bar (void); + +__attribute__ ((noinline, returns_twice)) int +zero (void) +{ + return 0; +} + +void +foo (void) +{ + int a = zero (); + + for (n = 0; n < 2; ++n) + { + } + + if (a) + bar (); +} diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc index 921305201..eb7c2e681 100644 --- a/gcc/tree-ssa-sink.cc +++ b/gcc/tree-ssa-sink.cc @@ -263,12 +263,13 @@ statement_sink_location (gimple *stmt, basic_block frombb, *zero_uses_p = false; - /* We only can sink assignments and non-looping const/pure calls. */ + /* We only can sink assignments and const/pure calls that are guaranteed + to return exactly once. */ int cf; if (!is_gimple_assign (stmt) && (!is_gimple_call (stmt) || !((cf = gimple_call_flags (stmt)) & (ECF_CONST|ECF_PURE)) - || (cf & ECF_LOOPING_CONST_OR_PURE))) + || (cf & (ECF_LOOPING_CONST_OR_PURE|ECF_RETURNS_TWICE)))) return false; /* We only can sink stmts with a single definition. */