From patchwork Wed Oct 5 12:04:02 2022 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: 1728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp564437wrs; Wed, 5 Oct 2022 05:07:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7zlO+mkCu2L5jA1PBn3+U0nZEaSxE+8s5Y2Fu38N3c791otz+IS2sL71di4woqZloy2nQy X-Received: by 2002:a05:6402:370a:b0:456:d006:6948 with SMTP id ek10-20020a056402370a00b00456d0066948mr28548712edb.90.1664971626778; Wed, 05 Oct 2022 05:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664971626; cv=none; d=google.com; s=arc-20160816; b=HQiu3rKBfZiUHGl595rMl0Vy9BdIaj9yatuIj8d3smfv9xr9hS25PcDq/vgzPYX9ZX 2bsSrAmZnFC3QCa8nuirVdg9NziP2YV2JtB2sH0HFiDjg0AhomGjnmerO0f0G13H6cZ/ IKEC+k/BvV6KtVVmLVAARJEq5n7DHTDATaocxM8AggKj2t7bdof5crL6qTeT78biAbIn HvmsaEAgPN/3SWGFHHiBKC1FDSd34EkcekkZHyX7a77nLYH3JFSuOpbq79ORqj0Wj5OR WlSkFDWRFSfmnoopw4bBNjcUls+u3L8xNb83EtB96GWcuxSUWSR3/Da0THlO4Zb2BVPV y7kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=tyHnO8ZYWQUeOW6vVKrpD6Mo7b54EF3nul+BI8Qz9J4=; b=P/AG9Ho8dDMffEeTUWtd5GRzWPPfLeQQiIJATm46D5srtegdak5uG8NFBzjNd2pCcr MvOJxuqb1FFoTJO9y7Hv72DtCiJDXn9FOMHIVXEYm8464yVA249cH1N+lqNTYtvZatA8 uXO0XtsmsFYVqIC8OjqbpBMuq+hGKRiSLQ16I9bDW6aCQBJBFQlh1K2Yv2LQ75nRzqy8 CkuG6bcBd+hvOhwfE40YStLt8GnNk6rogudy9ZMjwuvj3j+nuAxpE0fQNGE9V1MFKT3G TyA4AZ1SVdlQcAaeC1M5ULoSZPWAod7pCQh7OWph1tUuOQcEAWuxy8VKaR+yL4AsbSJy rrRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YYqmrGjG; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cw14-20020a170906478e00b00780dd2b1fb3si13896254ejc.867.2022.10.05.05.07.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 05:07: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=@gcc.gnu.org header.s=default header.b=YYqmrGjG; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C71C23851C24 for ; Wed, 5 Oct 2022 12:05:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C71C23851C24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664971557; bh=tyHnO8ZYWQUeOW6vVKrpD6Mo7b54EF3nul+BI8Qz9J4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YYqmrGjGxacUtdMPYxPgZVO6DXz4d1No7Yo6Odc0uRfGDQd5IS2Z4OFPh8KMk4sgd XUSVMkJfLUmfa98NOiGDx7+LD/S1VplPiI1DvTasX6ZIZgUX9lFYSolgOZkY0cFgyZ g4AbRPHeH/P95rUYM+aoMw8CRf20FTRMXLV21n60= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 53855385742A for ; Wed, 5 Oct 2022 12:04:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 53855385742A Received: by mail-pl1-x631.google.com with SMTP id b2so10320784plc.7 for ; Wed, 05 Oct 2022 05:04:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tyHnO8ZYWQUeOW6vVKrpD6Mo7b54EF3nul+BI8Qz9J4=; b=VXtDypOCLTsXoWGIngBsnFEX8qnhj6v2FN8q3z4brcZudYHjRIpVK4HIPPEGMUZw6L EGGRlyhjGdDQxoTGN0dWJcXAFA9RfjzwNU/sNA5nrTbpEGBxUT4ZzFYzg8BrNcpUX0U4 neaaXToqXkqLV/SLRoeeClP2bpAlINlJun/WHTey2IrhfPyhgon3+bJiEsD1+hjJrN8N ThHZCdg582qvkpM8FvzWXfqeNcch3/zyMt6LrhHwiO/0cfnunXFfbHVGSsp4w6QOQB4u sUwlLl4RBpr8v3DooPhO034mcOppolibCgjXRe+6tZr8ceBhJDcESKBLd0gQK/r8FgkJ /lrQ== X-Gm-Message-State: ACrzQf3DrXfxJUKs1F3ltcxI4HcXnCxAJSbpEuAJpUF7BUO9FRCLtLNG FwvUiRtmmvhPqoA3ZI4ccGs23MiIwnyo8lozG1bPg+qmDi7SB9AfiTcDjKstcBRsnSdIEAQ/ptM Fgs5QHkpDaQhZ3gjP/jaeFxvR1VAc3QCjqcDesvmpRT9bQdLJRiMpdXxlXk3Ue8AzuFJqliDheT ykPhE+x8R3gnJnmiqQr4Q= X-Received: by 2002:a17:90a:1b0a:b0:203:6731:4c98 with SMTP id q10-20020a17090a1b0a00b0020367314c98mr4698325pjq.10.1664971461010; Wed, 05 Oct 2022 05:04:21 -0700 (PDT) Received: from FA21110339.ts.tri-ad.global ([103.175.111.222]) by smtp.gmail.com with ESMTPSA id rm10-20020a17090b3eca00b0020936894e76sm1054084pjb.10.2022.10.05.05.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 05:04:20 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] gcov: test switch/break line counts Date: Wed, 5 Oct 2022 14:04:02 +0200 Message-Id: <20221005120403.68935-2-jorgen.kvalsvik@woven-planet.global> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20221005120403.68935-1-jorgen.kvalsvik@woven-planet.global> References: <20221005120403.68935-1-jorgen.kvalsvik@woven-planet.global> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, TXREP, T_SPF_PERMERROR 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: , X-Patchwork-Original-From: =?utf-8?q?J=C3=B8rgen_Kvalsvik_via_Gcc-patches?= From: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= Reply-To: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= 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?1745849288475042477?= X-GMAIL-MSGID: =?utf-8?q?1745849288475042477?= The coverage support will under some conditions decide to split edges to accurately report coverage. By running the test suite with/without this edge splitting a small diff shows up, addressed by this patch, which should catch future regressions. Removing the edge splitting: diff --git a/gcc/profile.cc b/gcc/profile.cc --- a/gcc/profile.cc +++ b/gcc/profile.cc @@ -1244,19 +1244,7 @@ branch_prob (bool thunk) Don't do that when the locuses match, so if (blah) goto something; is not computed twice. */ - if (last - && gimple_has_location (last) - && !RESERVED_LOCATION_P (e->goto_locus) - && !single_succ_p (bb) - && (LOCATION_FILE (e->goto_locus) - != LOCATION_FILE (gimple_location (last)) - || (LOCATION_LINE (e->goto_locus) - != LOCATION_LINE (gimple_location (last))))) - { - basic_block new_bb = split_edge (e); - edge ne = single_succ_edge (new_bb); - ne->goto_locus = e->goto_locus; - } + if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL)) && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) need_exit_edge = 1; Assuming the .gcov files from make chec-gcc RUNTESTFLAGS=gcov.exp are kept: $ diff -r no-split-edge with-split-edge | grep -C 2 -E "^[<>]\s\s" diff -r sans-split-edge/gcc/gcov-4.c.gcov with-split-edge/gcc/gcov-4.c.gcov 228c228 < -: 224: break; --- > 1: 224: break; 231c231 < -: 227: break; --- > #####: 227: break; 237c237 < -: 233: break; --- > 2: 233: break; gcc/testsuite/ChangeLog: * g++.dg/gcov/gcov-1.C: Add line count check. * gcc.misc-tests/gcov-4.c: Likewise. --- gcc/testsuite/g++.dg/gcov/gcov-1.C | 8 ++++---- gcc/testsuite/gcc.misc-tests/gcov-4.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/g++.dg/gcov/gcov-1.C b/gcc/testsuite/g++.dg/gcov/gcov-1.C index 9018b9a3a73..ee383b480a8 100644 --- a/gcc/testsuite/g++.dg/gcov/gcov-1.C +++ b/gcc/testsuite/g++.dg/gcov/gcov-1.C @@ -257,20 +257,20 @@ test_switch (int i, int j) switch (i) /* count(5) */ /* branch(end) */ { - case 1: + case 1: /* count(1) */ result = do_something (2); /* count(1) */ - break; + break; /* count(1) */ case 2: result = do_something (1024); break; - case 3: + case 3: /* count(3) */ case 4: /* branch(67) */ if (j == 2) /* count(3) */ /* branch(end) */ return do_something (4); /* count(1) */ result = do_something (8); /* count(2) */ - break; + break; /* count(2) */ default: result = do_something (32); /* count(1) */ switch_m++; /* count(1) */ diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c index 9d8ab1c1097..498d299b66b 100644 --- a/gcc/testsuite/gcc.misc-tests/gcov-4.c +++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c @@ -221,7 +221,7 @@ test_switch (int i, int j) { case 1: result = do_something (2); /* count(1) */ - break; + break; /* count(1) */ case 2: result = do_something (1024); break; @@ -230,7 +230,7 @@ test_switch (int i, int j) if (j == 2) /* count(3) */ return do_something (4); /* count(1) */ result = do_something (8); /* count(2) */ - break; + break; /* count(2) */ default: result = do_something (32); /* count(1) */ switch_m++; /* count(1) */ From patchwork Wed Oct 5 12:04:03 2022 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: 1726 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp563906wrs; Wed, 5 Oct 2022 05:06:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4bg8KdAlTP/eM5+WSy0AhBHoqz+3Pl4agee3KJU7OTIDyPcsfnNd8YAs1S9e1QLsHhJfPv X-Received: by 2002:a17:907:6d28:b0:782:32ad:7b64 with SMTP id sa40-20020a1709076d2800b0078232ad7b64mr24852937ejc.23.1664971560900; Wed, 05 Oct 2022 05:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664971560; cv=none; d=google.com; s=arc-20160816; b=m2xfeO4r8YZX/ibNcaGkW9UJO0/dhBzR+3q6FPutdJe9tf1QVgbJ5E3x2cjWIL5Tnz mYjMpNEDR4q92UIyH3lpDkU/7mrWUR+YYFsQAt5hUZIPFKTtjXW6isp5wfUi+AEDATRF THSYT/BWssJPj3rCDLrgfvAj9dtkJ4rHa3QljdbsYHPwNKxrgHy/t7fllAD3PP1LiPPu Z1UEdppLek2fPgfTqatzNNGEQmAOU2Yb1yaHj2s0I26Aa6dL4s8HlaXOpN2H7nUP2uk3 c3cScT7qBhhf9TF0jKk2rO0yVN4HU4O7zMVxiATb5pB0gB5TPn+DnQpSgqlTfOs/o/xE 8cag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=W9v/g5RcSN+BGfzyVsexfPSX3I3BolHfVT6yL227E+Q=; b=IN1tp72ph4Vvf/1V02Fkhf1YtsZ/cZSQhfPg5/f4KQmeKPp8nBWiP64MzaTaRgwOIk d8OVEkCH06GQ9Is1SeiKih2td751i3upUZuoprxO8j2lWzmakCS4PVVwTHwecwGR1vSA +zoHxnbNAO01r13puV4TYL/coJ3T+QxGi+nXbABPKPSVyXcheB4xchWZ+auE9m7UTGhq FSUv8JUqdfKJhi1wDdT6zZw7bAaDWES1fVbSltsj2FEBe40VKPzxrQm6/TJTxrEN/cfE 1Z6qIgnkES6tOWxw5ngadY+dr5L1Q2HDBA5ekPXT2IHTrzvGVj50kUkVXbHI30aEPmsd yM6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JLz2QxsE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id jg5-20020a170907970500b007828ae31468si12022171ejc.698.2022.10.05.05.06.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 05:06:00 -0700 (PDT) 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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JLz2QxsE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FB9D3856246 for ; Wed, 5 Oct 2022 12:05:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FB9D3856246 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664971509; bh=W9v/g5RcSN+BGfzyVsexfPSX3I3BolHfVT6yL227E+Q=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JLz2QxsEBBMow5tSKwBtu0CasF300lILHxnzFiBEgN23kiInDCVm7eKT7ecS69JIu 8Q7spcO4iBWuDFEf6im1Xk0aCDELPbWcESuguI+W3Gxo6yYfxnoEvigc6oAZeiZbda IAWh5NCvod7ZsxQLC+aqFvf70ZqvVzBOs5Wmy+8c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id AAA49385735C for ; Wed, 5 Oct 2022 12:04:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AAA49385735C Received: by mail-pf1-x431.google.com with SMTP id y8so1232078pfp.13 for ; Wed, 05 Oct 2022 05:04:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W9v/g5RcSN+BGfzyVsexfPSX3I3BolHfVT6yL227E+Q=; b=FRk5t2mGLdLmmjPcbMhv1hGxUle6JpX2VM1hrW9QJb8Ja+wkWg21/btPAFadtT+sTi 5jWi197b8tckEKBjoe0KCmAIFTHXuarRMMwvTktAo5f+46qbBP/ht+0ffmTNuVjgitfS GjfaDeTrdr/Hjt6tsNW09eTMIjZMAocnKHnTdTzPmbo1Hz/PcxbbhtnH+4iju0KAqYAY 5BFW6DETUIHsroFjRR4NVxMBVcEW7Ql0tsE84BtSILOVH9XNuZcV66Abz0yhv5pl1HVc yOEenXPJsYKx2yit7IzV7r+qTtfnaD5E06hYweByUL+lkmorKTLV1cBQImcK2o/k+elb j72A== X-Gm-Message-State: ACrzQf2+sTxe6Nwi33QzCmyjN/3O7lt/fndsbWnnkz3zCUwQyAFdr3Mr AtsLFT2N1mcmEDUqL22H/ZwDa05skyLnPv7vMsEF9NJmiK1v+FvcazIVZTUpqWbome+eQeWW0+D hzn8uShXMeOg1PODxmOpOJnR78kvKFgCQmvNCpVoazy+2S9qjyhCZ1JQdtKPmbjYvqfbmAlSik0 IcZx95OHkglO57BUDxDpc= X-Received: by 2002:a62:ce83:0:b0:560:97b5:2d2c with SMTP id y125-20020a62ce83000000b0056097b52d2cmr18241960pfg.61.1664971464308; Wed, 05 Oct 2022 05:04:24 -0700 (PDT) Received: from FA21110339.ts.tri-ad.global ([103.175.111.222]) by smtp.gmail.com with ESMTPSA id rm10-20020a17090b3eca00b0020936894e76sm1054084pjb.10.2022.10.05.05.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 05:04:23 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] Split edge when edge locus and dest don't match Date: Wed, 5 Oct 2022 14:04:03 +0200 Message-Id: <20221005120403.68935-3-jorgen.kvalsvik@woven-planet.global> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20221005120403.68935-1-jorgen.kvalsvik@woven-planet.global> References: <20221005120403.68935-1-jorgen.kvalsvik@woven-planet.global> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, TXREP, T_SPF_PERMERROR 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: , X-Patchwork-Original-From: =?utf-8?q?J=C3=B8rgen_Kvalsvik_via_Gcc-patches?= From: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= Reply-To: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= 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?1745849218985192364?= X-GMAIL-MSGID: =?utf-8?q?1745849218985192364?= Edges with locus are candidates for splitting so that the edge with locus is the only edge out of a basic block, except when the locuses match. The test checks the last (non-debug) statement in a basic block, but this causes an unnecessary split when the edge locus go to a block which coincidentally has an unrelated label. Comparing the first statement of the destination block is the same check but does not get tripped up by labels. An example with source/edge/dest locus when an edge is split: 1 int fn (int a, int b, int c) { 2 int x = 0; 3 if (a && b) { 4 x = a; 5 } else { 6 a_: 7 x = (a - b); 8 } 9 10 return x; 11 } block file line col stmt src t.c 3 10 if (a_3(D) != 0) edge t.c 6 1 dest t.c 6 1 a_: src t.c 3 13 if (b_4(D) != 0) edge t.c 6 1 dst t.c 6 1 a_: With label removed: 1 int fn (int a, int b, int c) { 2 int x = 0; 3 if (a && b) { 4 x = a; 5 } else { 6 // a_: <- label removed 7 x = (a - b); 8 } 9 10 return x; 11 block file line col stmt src t.c 3 10 if (a_3(D) != 0) edge (null) 0 0 dest t.c 6 1 a_: src t.c 3 13 if (b_4(D) != 0) edge (null) 0 0 dst t.c 6 1 a_: and this is extract from gcov-4b.c which *should* split: 205 int 206 test_switch (int i, int j) 207 { 208 int result = 0; 209 210 switch (i) /* branch(80 25) */ 211 /* branch(end) */ 212 { 213 case 1: 214 result = do_something (2); 215 break; 216 case 2: 217 result = do_something (1024); 218 break; 219 case 3: 220 case 4: 221 if (j == 2) /* branch(67) */ 222 /* branch(end) */ 223 return do_something (4); 224 result = do_something (8); 225 break; 226 default: 227 result = do_something (32); 228 switch_m++; 229 break; 230 } 231 return result; 231 } block file line col stmt src 4b.c 214 18 result_18 = do_something (2); edge 4b.c 215 9 dst 4b.c 231 10 _22 = result_3; src 4b.c 217 18 result_16 = do_something (1024); edge 4b.c 218 9 dst 4b.c 231 10 _22 = result_3; src 4b.c 224 18 result_12 = do_something (8); edge 4b.c 225 9 dst 4b.c 231 10 _22 = result_3; Note that the behaviour of comparison is preserved for the (switch) edge splitting case. The former case now fails the check (even though e->goto_locus is no longer a reserved location) because the dest matches the e->locus. gcc/ChangeLog: * profile.cc (branch_prob): Compare edge locus to dest, not src. --- gcc/profile.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gcc/profile.cc b/gcc/profile.cc index 96121d60711..c13a79a84c2 100644 --- a/gcc/profile.cc +++ b/gcc/profile.cc @@ -1208,17 +1208,17 @@ branch_prob (bool thunk) FOR_EACH_EDGE (e, ei, bb->succs) { gimple_stmt_iterator gsi; - gimple *last = NULL; + gimple *dest = NULL; /* It may happen that there are compiler generated statements without a locus at all. Go through the basic block from the last to the first statement looking for a locus. */ - for (gsi = gsi_last_nondebug_bb (bb); + for (gsi = gsi_start_nondebug_bb (bb); !gsi_end_p (gsi); - gsi_prev_nondebug (&gsi)) + gsi_next_nondebug (&gsi)) { - last = gsi_stmt (gsi); - if (!RESERVED_LOCATION_P (gimple_location (last))) + dest = gsi_stmt (gsi); + if (!RESERVED_LOCATION_P (gimple_location (dest))) break; } @@ -1227,14 +1227,14 @@ branch_prob (bool thunk) Don't do that when the locuses match, so if (blah) goto something; is not computed twice. */ - if (last - && gimple_has_location (last) + if (dest + && gimple_has_location (dest) && !RESERVED_LOCATION_P (e->goto_locus) && !single_succ_p (bb) && (LOCATION_FILE (e->goto_locus) - != LOCATION_FILE (gimple_location (last)) + != LOCATION_FILE (gimple_location (dest)) || (LOCATION_LINE (e->goto_locus) - != LOCATION_LINE (gimple_location (last))))) + != LOCATION_LINE (gimple_location (dest))))) { basic_block new_bb = split_edge (e); edge ne = single_succ_edge (new_bb);