From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=woven-planet.global Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=woven-planet.global Received: by mail-pf1-x431.google.com with SMTP id y8so1232078pfp.13 for ; Wed, 05 Oct 2022 05:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=woven-planet.global; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W9v/g5RcSN+BGfzyVsexfPSX3I3BolHfVT6yL227E+Q=; b=FghW+d1NRO7Oi2x94zJgeDSCRqZDV78eHO129kfLqGBC4BVn0/X3acgIsc3FcNYorE DWvQbD4MggdSdqq3aS5vXfLMQMKTUQltSgjG8L5tO2KownK10Wcr31YlQsAC8q6uU/g3 FoPDtHt3vr5qhtcUZf08EN4yURItzts8UQgys= 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-Google-Smtp-Source: AMsMyM4nVQTBVSis+XG/iAE/DptLnWl5t0t3NEr/NzBguo/IAWyI0h74PyTfCwtC+zbD3apB60YW8A== 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) From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= To: gcc-patches@gcc.gnu.org Cc: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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); -- 2.30.2