From patchwork Wed Oct 27 06:34:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xionghu Luo X-Patchwork-Id: 46691 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05D23385700D for ; Wed, 27 Oct 2021 06:38:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05D23385700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635316712; bh=HbsKIRnamUtt3n0I1EpRHfyWWZRePtwjtm+6J0Ox0dw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vRBkT5VKbj8oISUJe+I9527bKklcUEukrYLTlAGBnE7Pb7R65byoKzP8vN2pIuo49 oX5jzo79Agj6YR0BUpLARMcrGJ6UxkuyK/yJaOmZruSNfcDz4XwjKOUI6e5ppYg8Qp 3I8k1eS5QiWQGnB14bWAAX989OceGsTRkPU5WqUw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 8A18A385780A; Wed, 27 Oct 2021 06:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A18A385780A Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19R5Gvfs006294; Wed, 27 Oct 2021 06:36:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3by0g01pab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Oct 2021 06:36:02 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 19R6LroP030738; Wed, 27 Oct 2021 06:36:02 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3by0g01p9d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Oct 2021 06:36:01 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 19R6STIR012387; Wed, 27 Oct 2021 06:35:59 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 3bx4et3yfd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Oct 2021 06:35:59 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 19R6ZuJv50856232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Oct 2021 06:35:56 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 13A394C066; Wed, 27 Oct 2021 06:35:56 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98B3D4C04A; Wed, 27 Oct 2021 06:35:54 +0000 (GMT) Received: from marlin.aus.stglabs.ibm.com (unknown [9.40.194.84]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 27 Oct 2021 06:35:54 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 2/4] Refactor loop_version Date: Wed, 27 Oct 2021 01:34:46 -0500 Message-Id: <20211027063448.1844771-3-luoxhu@linux.ibm.com> X-Mailer: git-send-email 2.27.0.90.geebb51ba8c In-Reply-To: <20211027063448.1844771-1-luoxhu@linux.ibm.com> References: <20211027063448.1844771-1-luoxhu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6bGaesZo3OUmgH3QF4OLLQDu7uQFRSIH X-Proofpoint-GUID: K4IvvrrQx6FVuZw8l5kPIrUtKH5DXgRA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-27_01,2021-10-26_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 adultscore=0 spamscore=0 mlxscore=0 malwarescore=0 bulkscore=0 clxscore=1015 suspectscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2110270038 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Xionghu Luo via Gcc-patches From: Xionghu Luo Reply-To: Xionghu Luo Cc: rguenther@suse.de, segher@kernel.crashing.org, Xionghu Luo , hubicka@kam.mff.cuni.cz, wschmidt@linux.ibm.com, linkw@gcc.gnu.org, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" loop_version currently does lv_adjust_loop_entry_edge before it loopifys the copy inserted on the header. This patch moves the condition generation later and thus we have four pieces to help understanding of how the adjustment works: 1) duplicating the loop on the entry edge. 2) loopify the duplicated new loop. 3) adjusting the CFG to insert a condition branching to either loop with lv_adjust_loop_entry_edge. 4) From loopify extract the scale_loop_frequencies bits. Also removed some piece of code seems obviously useless which is not completely sure: - redirect_all_edges since it is false and loopify only called once. - extract_cond_bb_edges and lv_flush_pending_stmts (false_edge) as the edge is not redirected actually. gcc/ChangeLog: * cfgloopmanip.c (loop_version): Refactor loopify to loop_version. Move condition generation after loopify. (loopify): Delete. * cfgloopmanip.h (loopify): Delete. --- gcc/cfgloopmanip.c | 113 ++++++++++++--------------------------------- gcc/cfgloopmanip.h | 3 -- 2 files changed, 29 insertions(+), 87 deletions(-) diff --git a/gcc/cfgloopmanip.c b/gcc/cfgloopmanip.c index 82c242dd720..a30ebe1cdb4 100644 --- a/gcc/cfgloopmanip.c +++ b/gcc/cfgloopmanip.c @@ -846,71 +846,6 @@ create_empty_loop_on_edge (edge entry_edge, return loop; } -/* Make area between HEADER_EDGE and LATCH_EDGE a loop by connecting - latch to header and update loop tree and dominators - accordingly. Everything between them plus LATCH_EDGE destination must - be dominated by HEADER_EDGE destination, and back-reachable from - LATCH_EDGE source. HEADER_EDGE is redirected to basic block SWITCH_BB, - FALSE_EDGE of SWITCH_BB to original destination of HEADER_EDGE and - TRUE_EDGE of SWITCH_BB to original destination of LATCH_EDGE. - Returns the newly created loop. Frequencies and counts in the new loop - are scaled by FALSE_SCALE and in the old one by TRUE_SCALE. */ - -class loop * -loopify (edge latch_edge, edge header_edge, - basic_block switch_bb, edge true_edge, edge false_edge, - bool redirect_all_edges, profile_probability true_scale, - profile_probability false_scale) -{ - basic_block succ_bb = latch_edge->dest; - basic_block pred_bb = header_edge->src; - class loop *loop = alloc_loop (); - class loop *outer = loop_outer (succ_bb->loop_father); - profile_count cnt; - - loop->header = header_edge->dest; - loop->latch = latch_edge->src; - - cnt = header_edge->count (); - - /* Redirect edges. */ - loop_redirect_edge (latch_edge, loop->header); - loop_redirect_edge (true_edge, succ_bb); - - /* During loop versioning, one of the switch_bb edge is already properly - set. Do not redirect it again unless redirect_all_edges is true. */ - if (redirect_all_edges) - { - loop_redirect_edge (header_edge, switch_bb); - loop_redirect_edge (false_edge, loop->header); - - /* Update dominators. */ - set_immediate_dominator (CDI_DOMINATORS, switch_bb, pred_bb); - set_immediate_dominator (CDI_DOMINATORS, loop->header, switch_bb); - } - - set_immediate_dominator (CDI_DOMINATORS, succ_bb, switch_bb); - - /* Compute new loop. */ - add_loop (loop, outer); - - /* Add switch_bb to appropriate loop. */ - if (switch_bb->loop_father) - remove_bb_from_loops (switch_bb); - add_bb_to_loop (switch_bb, outer); - - /* Fix counts. */ - if (redirect_all_edges) - { - switch_bb->count = cnt; - } - scale_loop_frequencies (loop, false_scale); - scale_loop_frequencies (succ_bb->loop_father, true_scale); - update_dominators_in_loop (loop); - - return loop; -} - /* Remove the latch edge of a LOOP and update loops to indicate that the LOOP was removed. After this function, original loop latch will have no successor, which caller is expected to fix somehow. @@ -1681,7 +1616,7 @@ loop_version (class loop *loop, bool place_after) { basic_block first_head, second_head; - edge entry, latch_edge, true_edge, false_edge; + edge entry, latch_edge; int irred_flag; class loop *nloop; basic_block cond_bb; @@ -1694,7 +1629,7 @@ loop_version (class loop *loop, /* Note down head of loop as first_head. */ first_head = entry->dest; - /* Duplicate loop. */ + /* 1) Duplicate loop on the entry edge. */ if (!cfg_hook_duplicate_loop_to_header_edge (loop, entry, 1, NULL, NULL, NULL, 0)) { @@ -1702,11 +1637,28 @@ loop_version (class loop *loop, return NULL; } + /* 2) loopify the duplicated new loop. */ + latch_edge = single_succ_edge (get_bb_copy (loop->latch)); + nloop = alloc_loop (); + class loop *outer = loop_outer (latch_edge->dest->loop_father); + edge new_header_edge = single_pred_edge (get_bb_copy (loop->header)); + nloop->header = new_header_edge->dest; + nloop->latch = latch_edge->src; + loop_redirect_edge (latch_edge, nloop->header); + + /* Compute new loop. */ + add_loop (nloop, outer); + copy_loop_info (loop, nloop); + set_loop_copy (loop, nloop); + + /* loopify redirected latch_edge. Update its PENDING_STMTS. */ + lv_flush_pending_stmts (latch_edge); + /* After duplication entry edge now points to new loop head block. Note down new head as second_head. */ second_head = entry->dest; - /* Split loop entry edge and insert new block with cond expr. */ + /* 3) Split loop entry edge and insert new block with cond expr. */ cond_bb = lv_adjust_loop_entry_edge (first_head, second_head, entry, cond_expr, then_prob, else_prob); if (condition_bb) @@ -1718,24 +1670,17 @@ loop_version (class loop *loop, return NULL; } - latch_edge = single_succ_edge (get_bb_copy (loop->latch)); - - extract_cond_bb_edges (cond_bb, &true_edge, &false_edge); - nloop = loopify (latch_edge, - single_pred_edge (get_bb_copy (loop->header)), - cond_bb, true_edge, false_edge, - false /* Do not redirect all edges. */, - then_scale, else_scale); - - copy_loop_info (loop, nloop); - set_loop_copy (loop, nloop); + /* Add cond_bb to appropriate loop. */ + if (cond_bb->loop_father) + remove_bb_from_loops (cond_bb); + add_bb_to_loop (cond_bb, outer); - /* loopify redirected latch_edge. Update its PENDING_STMTS. */ - lv_flush_pending_stmts (latch_edge); + /* 4) Scale the original loop and new loop frequency. */ + scale_loop_frequencies (loop, then_scale); + scale_loop_frequencies (nloop, else_scale); + update_dominators_in_loop (loop); + update_dominators_in_loop (nloop); - /* loopify redirected condition_bb's succ edge. Update its PENDING_STMTS. */ - extract_cond_bb_edges (cond_bb, &true_edge, &false_edge); - lv_flush_pending_stmts (false_edge); /* Adjust irreducible flag. */ if (irred_flag) { diff --git a/gcc/cfgloopmanip.h b/gcc/cfgloopmanip.h index 07d5f925b79..312a3b48d05 100644 --- a/gcc/cfgloopmanip.h +++ b/gcc/cfgloopmanip.h @@ -42,9 +42,6 @@ extern void scale_loop_profile (class loop *, profile_probability, gcov_type); extern edge create_empty_if_region_on_edge (edge, tree); extern class loop *create_empty_loop_on_edge (edge, tree, tree, tree, tree, tree *, tree *, class loop *); -extern class loop *loopify (edge, edge, - basic_block, edge, edge, bool, - profile_probability, profile_probability); extern void unloop (class loop *, bool *, bitmap); extern void copy_loop_info (class loop *loop, class loop *target); extern class loop * duplicate_loop (class loop *, class loop *,