From patchwork Wed Oct 4 12:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= X-Patchwork-Id: 148297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp107491vqb; Wed, 4 Oct 2023 05:51:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNVPGfIKXkc4qnHdaBpV1SX3kZsyLzfWave3OWoXWC/litSnwCxDiYiOZCSafBw2umOEXK X-Received: by 2002:a17:907:1dd5:b0:9ae:70b7:bc9f with SMTP id og21-20020a1709071dd500b009ae70b7bc9fmr1868919ejc.2.1696423866820; Wed, 04 Oct 2023 05:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696423866; cv=none; d=google.com; s=arc-20160816; b=wrVrRVjwaecp0i3UGOR2ZTu/mNSHvpj3lLqgLCf6FREINdGB2F47NcXiHIfICIC2Ni bmw1ad3WDU5N7s9xi8OCTwC/I4vvBhuve0F0yO5SEqNjN0WlUVSqwnM3tnILw3tzrSgC w0dfmaTRv8nFtr1sjvjLro6cbozEfpnCBunfjcWTxz1uddHRecVAtxSWPGSFZNnwY94X fGyyVvum/bLnOO5aJWzydlPvL+/pyDliRICwlVN9vewmrgCbUv4EotKuq3ytnBLQN8gr QSVPiyvVPlUfKWTPZHBb/zhw0almOi9ThilP8K7XmQ5Trwns4c48TmBfU//PxtvQGhxB 5Fiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=lYPsbvkkCVELBNjaSn91cABkx7bZod6Fu0RSB5REdqk=; fh=9YvKuYzPOH4H8p6ZxADoseEyE0mG6135swhZOYPib+Q=; b=ee+MK5WOkNxEhuSUeM4oLQga8GfPprnkMISkcAlkjsfVERVx3Hi7e8s/h5gAsEAUP8 3sHMWPA29iBvO7komvGND2cCxyLFuDvm7LGasLW3YDKwzvo37/gT9OEKZkDhDDv/G0H0 OsGmDqIZJzfZbp99yoa/+Q13a4Nt1ZYcxlzcC/dTnK+RGdp/1Flkt0iZFqp+uxdiQh/1 Yk1pHiglUcrskw1hjXIljMw60cFElrwxXK8Kn9EincZ/5g8uVKjtXbcrjPzxNVx5xApN FK7TNTiTSkbLbMrSjIXgeXKXAHkyDiqYlC7SGxOSUi74ZxhTp1tC4lhJYcYHFzqIC0Ik GP6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b=X7aoYBGJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ci7-20020a170906c34700b009a1bf605ebesi1643414ejb.847.2023.10.04.05.51.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:51:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b=X7aoYBGJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 742C13830B4C for ; Wed, 4 Oct 2023 12:43:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.155]) by sourceware.org (Postfix) with ESMTPS id 4FDE138618D5 for ; Wed, 4 Oct 2023 12:40:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FDE138618D5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lambda.is Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lambda.is Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 7F38F20AB2E8; Wed, 4 Oct 2023 14:40:43 +0200 (CEST) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:date:subject:subject:from:from:received :received:received; s=dkim20160331; t=1696423242; x=1698237643; bh=lYPsbvkkCVELBNjaSn91cABkx7bZod6Fu0RSB5REdqk=; b=X7aoYBGJJtBf I2E+6SR8bn/750h1xsbiOqs+Htq7OOdIsL6IzUbWgi30pheRq0Sog4lDwWCBepcZ YvvBF0RY4CAMmDt18KmTr59m1fIG72RSDVaZBtQcBDyZFJbaUR1NKb5qiqAp2fw3 0X+2xrkSLTooRBlgUZcYqvnHjQ7JhnXPJJgUctYRxOeEL6bZqBNa8e+aHuu0ldM8 3igKUTbw2LfGAkSO2SIEWpwWKL1h9uakvDElkAHFNShQUspMulURKfAIGWmc38fX K1ySVmqfz/HXrD2vv3POOAWBCuwDfRRCGuZ+BXMhIDH3phWqs/+UZeoZRtNS93Bj 3ycigARk6CStOeHibpA02ddXKv02ZDRvkkMM3llcn9ytvPtjRNbZyXtyBsXbpdhu bfcKdNEGyZByi2OwT70oaC8GH7G38xdxW1jL/zi7+Zpasogb9tWa5KVU9ECcjXe9 RNWDBmzoyjmiSBZSkSZvhAUd+NbRwUI4AbtlxwZjFhVUAMjOGC69r8s4TDMhWmr2 vpYLbB5d0SNhkIHwfIC55cA4b6abxODHJuN/+Z5xevRZf+E6mkVY6STqarp+oi8Y QUiSiHgwlgfQyMCfMpe6DBwt85KAErjy1AIKaGWNUI/5Hxa0EE3OfthqiaYihcZJ r1FEkBWTRakf0hCwPkO7lG0XA76M5ag= X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out011.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id OJ5aR69cvJNA; Wed, 4 Oct 2023 14:40:42 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id A494820AB2E2; Wed, 4 Oct 2023 14:40:42 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 8E48820D6AE9; Wed, 4 Oct 2023 14:40:42 +0200 (CEST) From: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= To: gcc-patches@gcc.gnu.org Cc: mliska@suse.cz, jh@suse.cz, =?utf-8?q?J=C3=B8rgen_Kvalsvik?= Subject: [PATCH 09/22] Find reachable conditions unbounded by dominators Date: Wed, 4 Oct 2023 21:39:09 +0900 Message-Id: <20231004123921.634024-10-j@lambda.is> In-Reply-To: <20231004123921.634024-1-j@lambda.is> References: <20231004123921.634024-1-j@lambda.is> MIME-Version: 1.0 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778829352158142653 X-GMAIL-MSGID: 1778829352158142653 Search for reachable conditions without limiting the search to the nodes dominated by the left-most term in the expression. Right operands are conceptually still always dominated by the left-most term, but in arbitrary programs there may be complex edges that breaks this. As it turns out, it is not necessary to limit search by the dominator, and it effectively only served as an optimization. A new test case has been added with the code that triggered the bug. gcc/ChangeLog: * tree-profile.cc (masking_vectors): Tweak comment. (cond_reachable_from): Remove dominated_by_p check. gcc/testsuite/ChangeLog: * gcc.misc-tests/gcov-22.c: New test. --- gcc/testsuite/gcc.misc-tests/gcov-22.c | 40 ++++++++++++++++++++++++++ gcc/tree-profile.cc | 15 +++------- 2 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-22.c diff --git a/gcc/testsuite/gcc.misc-tests/gcov-22.c b/gcc/testsuite/gcc.misc-tests/gcov-22.c new file mode 100644 index 00000000000..8aa8867dbf1 --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/gcov-22.c @@ -0,0 +1,40 @@ +/* { dg-options "-fprofile-conditions -ftest-coverage" } */ +/* { dg-do run { target native } } */ + +#include +jmp_buf buf; + +void noop() {} + +/* This function is a test to verify that the expression isolation does not + break on a CFG with the right set of complex edges. The (_ && setjmp) + created complex edges after the function calls and a circular pair of + complex edges around the setjmp call. This triggered a bug when the search + for right operands only would consider nodes dominated by the left-most + term, as this would only be the case if the complex edges were removed. + + __builtin_setjmp did not trigger this, so we need setjmp from libc. */ +void +pathological001 (int a, int b, int c) +{ + if (a) /* conditions(1/2) true(0) */ + /* conditions(end) */ + noop (); + + if (b) /* conditions(1/2) false(0) */ + /* conditions(end) */ + noop (); + + if (c && setjmp (buf)) /* conditions(1/4) true(0 1) false(1) */ + /* conditions(end) */ + noop (); +} + +int +main () +{ + pathological001 (0, 1, 0); +} + + +/* { dg-final { run-gcov conditions { --conditions gcov-22.c } } } */ diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index c8b917afb9a..adab0f59c07 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -619,10 +619,10 @@ masking_vectors (conds_ctx& ctx, array_slice blocks, } /* Find the nodes reachable from p by following only (possibly contracted) - condition edges dominated by p and ignore DFS back edges. From a high level - this is partitioning the CFG into subgraphs by removing all non-condition - edges and selecting a single connected subgraph. This creates a cut C = (G, - G') where G is the returned explicitly by this function. + condition edges and ignoring DFS back edges. From a high level this is + partitioning the CFG into subgraphs by removing all non-condition edges and + selecting a single connected subgraph. This creates a cut C = (G, G') where + G is the returned explicitly by this function. It is assumed that all paths from p go through q (q post-dominates p). p must always be the first term in an expression and a condition node. @@ -631,11 +631,6 @@ masking_vectors (conds_ctx& ctx, array_slice blocks, this is a multi-term expression or the first block in the then/else block is a conditional expression as well. - Only nodes dominated by p is added - under optimization some blocks may be - merged and multiple independent conditions may share the same outcome - (making successors misidentified as a right operands), but true right-hand - operands are always dominated by the first term. - The function outputs both a bitmap and a vector as both are useful to the caller. */ void @@ -651,8 +646,6 @@ cond_reachable_from (basic_block p, basic_block q, sbitmap expr, basic_block dest = contract_edge (e)->dest; if (dest == q) continue; - if (!dominated_by_p (CDI_DOMINATORS, dest, p)) - continue; if (!block_conditional_p (dest)) continue; if (bitmap_bit_p (expr, dest->index))