From patchwork Wed Oct 4 12:39:21 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: 148302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp108922vqb; Wed, 4 Oct 2023 05:54:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRmEdoOn0R7+V6TdV4GzycvWbzC68JIv77mUYUoGHZGGnhX1bcCuEzotHgQwMCM3MzB92k X-Received: by 2002:a17:906:51d5:b0:9b2:ba66:bbb0 with SMTP id v21-20020a17090651d500b009b2ba66bbb0mr1596413ejk.28.1696424041043; Wed, 04 Oct 2023 05:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696424041; cv=none; d=google.com; s=arc-20160816; b=0ftKwO0VUtGtq1ijNt4VQulUFii9SCOfSHnUZvuT+zI91+LdDXGUc69WZZLMIe8ZMf nCGyAqQaxg54csZNwNeVdET5as8WAOf9kHFT1OGzIb0EEA4R/aPIdwqngh6Ex3q1Gzqn nsILBh1SGWLZYtJ1SB32xsej/+mC6its+zxZv1EGWXu+wRpjf1N15OPZAqPqE5gTmkBg zu6j1jZeTOU8QlbPgHIT7yV6mL2YDBP+82QiwvobULRr8YxmvgpH/G0ExUj+bPXZwmSo /mMMZP3FXU/wTxuwwOjDYVRD+6uCOTe3XHkjTLVwcfgs7W7TeTdAZDqR8S0VhV2fRx+t OCnA== 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=C4DCuaNJlpCaibogSeLEGxmk0mfixSnIHN0hSaskNHk=; fh=9YvKuYzPOH4H8p6ZxADoseEyE0mG6135swhZOYPib+Q=; b=FkmwAMySEIk3sJzNFZxB/MewaqSGGUoJBcHkfp68OSI0c/wwAnbk5rElb8F3Sv0ipo IpWK9QdZzckCf5mSinMcjQiMux6wUZ63P+DebehQ6Eqy8+gqtPldofB8ixWzt4VYw1DN 3m8sS55ubnQBdCmv9uu822DMiiZ3q/vf+t/dmbh9u7qTJEuCfX6ayVsBCCihBSHfQTmP rABm0gHD+7q9vbUST8H3foT48FoYDdHojB1US+q8D5n8TkXqLX8H03WlQZHhTcJu8hA2 PE+9ewoQGXCJBjj/PZ3jJSQIXQ/1xTirC+BoLwJ3O7PF3uzTZZ4Oq37xi7xGSzkp7Qdx yrfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b=xS6hqH7V; 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 la12-20020a170906ad8c00b00992b55d152esi1708617ejb.242.2023.10.04.05.54.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:54:01 -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=xS6hqH7V; 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 E96683871035 for ; Wed, 4 Oct 2023 12:45:05 +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 0AE2B3830B53 for ; Wed, 4 Oct 2023 12:41:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0AE2B3830B53 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 3A0FE20D6200; Wed, 4 Oct 2023 14:41:12 +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=1696423271; x=1698237672; bh=C4DCuaNJlpCaibogSeLEGxmk0mfixSnIHN0hSaskNHk=; b=xS6hqH7VaStq nXvOpuHPegF8EVykUjm0q0ZS2VSf9RI8qiXo6ps3XEtKkb/2zpw7I3M88ZfRFDYz 1JXtDgC2S2kuFuVA5TkW7L9OwHw5Mcm8VP9D4MYTf0UZSPXpFC25J4ac8HQe3BQd 5caNv4lxsQ956g5bhgrvUYBdhFUcQhyfEAvUMe7yiFF8Q66XtfI+gk+qMsolsig4 +n8BaI8GRrdznpA+euTlAdFM8ri/wN9DLtPdVyXzmPMbe9/p+0SZCVoOLmBsRrv1 8Ie8oY8VRn+UcudxHkdpOt1CMM5iTSjv9bFpBMgfRRHITcLZTH2gu65Xh2e39png KIQDrdvgho1zEKz5HOPQqIZS5sxT7xfI+lygZxycYz45jBUNZCn6/+/tlpNKIqTw Sb0XcMiG5EPu/a5gEGsk7Iu7eADF/Ss1aTtOUmRUxOstPJJFsy+e8h6DYmsHCRP7 1V2xOI01W+DMPL1Opk2E03LEk4mWRdBgAdkLXIX28ZE2qifSJ1Yql8wzvFmaMsrS p3gwzkccSXvMDDnJEz300uJc06kiDyUuXvLolSV/PP9BfWG8wF5rOryRZ4WZ0E1U qH4UCG98SU0nXAXwue1ZyOb/KLzlDBHCb2MGUCPpejepCR+2l46ooGSJW/HKnkVj vDJPUXvSoEOCLKKYZcXeUs+wVNouBaI= X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-12.4 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 gxFyhPvYIbtj; Wed, 4 Oct 2023 14:41:11 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 808C220B3670; Wed, 4 Oct 2023 14:41:11 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 7191620D6AE9; Wed, 4 Oct 2023 14:41:11 +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 21/22] Walk the cfg in topological order, not depth-first Date: Wed, 4 Oct 2023 21:39:21 +0900 Message-Id: <20231004123921.634024-22-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: 1778829535605886524 X-GMAIL-MSGID: 1778829535605886524 Depth first order is insufficient to process expressions in the right order when there are setjmps in optimized builds. This would create complex paths from the root past conditions and into the middle of boolean expressions. Traversing the graph in topological order restores the expectation that expressions will be processed top-down. --- gcc/testsuite/gcc.misc-tests/gcov-23.c | 26 ++++++++++++++++++++++++++ gcc/tree-profile.cc | 1 + 2 files changed, 27 insertions(+) diff --git a/gcc/testsuite/gcc.misc-tests/gcov-23.c b/gcc/testsuite/gcc.misc-tests/gcov-23.c index 856e97f5088..e5b56a5aa44 100644 --- a/gcc/testsuite/gcc.misc-tests/gcov-23.c +++ b/gcc/testsuite/gcc.misc-tests/gcov-23.c @@ -1,5 +1,8 @@ /* { dg-options "-fprofile-conditions -ftest-coverage -O2 -c" } */ +#include +jmp_buf buf; + int id (int); int idp (int *); int err; @@ -120,4 +123,27 @@ mcdc003 (const char *locale) return 1; } +/* Adapted from jxl 0.8.2 lib/extras/dec/apng.cc processing_start (). + This created a graph where depth-first traversal of the CFG would not + process nodes in the wrong order (the extra control inserted from setjmp + created a path of complexes from root to !b without going through !a). + + This only happened under optimization. */ +int +mcdc004 (int a, int b) +{ + a = id (a); + b = id (b); + + if (a || b) /* conditions(0/4) true(0 1) false(0 1) */ + /* conditions(end) */ + return 1; + + if (setjmp (buf)) /* conditions(0/2) true(0) false(0) */ + /* conditions(end) */ + return 1; + + return 0; +} + /* { dg-final { run-gcov conditions { --conditions gcov-23.c } } } */ diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index d1d7265cd1c..8bf280dc018 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -1045,6 +1045,7 @@ find_conditions (struct function *fn) int n = dfs_enumerate_from (entry, 0, yes, dfs.address (), nblocks, exit); dfs.truncate (n); make_index_map (dfs, nblocks, ctx.B1, ctx.index_map); + dfs.sort (cmp_index_map, &ctx.index_map); /* Visit all reachable nodes and collect conditions. DFS order is important so the first node of a boolean expression is visited first