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: 1843328 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (4096-bit key; secure) header.d=kolabnow.com header.i=@kolabnow.com header.a=rsa-sha256 header.s=dkim20160331 header.b=xS6hqH7V; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S0vXt24vZz1yng for ; Wed, 4 Oct 2023 23:45:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9F6D3830B73 for ; Wed, 4 Oct 2023 12:44:53 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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