From patchwork Tue Sep 10 03:40:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1982916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=WRiPuIiB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4X2qHh6C1fz1y1v for ; Tue, 10 Sep 2024 13:41:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4B373857C4F for ; Tue, 10 Sep 2024 03:41:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id 7D8463858D39 for ; Tue, 10 Sep 2024 03:40:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D8463858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7D8463858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725939654; cv=none; b=evbpDAIBJ70S/eTaI6C30Hh9n8CB7bJvEwUV/B0AWEvYLIvLRHp2+V1ERV7mfznPz8nYQjSubMgbGhucj67251gJFvGJ0NhsdEohM1B66jYxZYqCjIFIWI+hP+hY3ayvFXCTD7nTJaaPX+mC1Jt9lkJFGcs4CWU0tSK5sm2CUN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725939654; c=relaxed/simple; bh=KRKWpeujqENhDluoE/GJ5/pjMqYSK6tB0BEGqHH9ggs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fvw/XjTy/AFTsUB3DvyFClXuBrV8k3aMApdHzh+CsjGyvRf/GvSLiACnAQAcDnEB14CjjtIMh42VQO6Z1dmPuvUisXHaRo9+WkEsuzZ/20kFZZFMM7CxsIMUou2NwsGuwYJ6OkEcjNzq6xDl6f4j+4qV+rIMi10Mc4zHwCo7ppA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 489DRQB8023788 for ; Tue, 10 Sep 2024 03:40:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=HHnudZcukNxYZCIgET10mv GXFNActFQszNs3/g09U5w=; b=WRiPuIiBvDL1Alnptxo6lk8elPIKOnAyshp8S+ /ps7RjMRxzPZS87gOfwLTOdScd1EAIpYpp+D3HqATZhXF72ZMG7d+rTUVpYDnKrE WR8HD/+3QjOrDD2FWz56+xtQohaiR1ydBut6kmlD3zEKOq2u9jfCDXa7ubT+yPXs sa9u6pkXNfH8zVYKi0i3FlmZJ3GdlHfQZHrxxHWhjXDgJZsLQHOe/i8E/Mo1GEuq J7nZhFddr8jDdCi3y5qb806T2NBKy7zv0nT1JO56IcVOuM61AZnkKX6NPtWlrg01 rhVjYmIw1ncztYzTFZL5afwpsK6KXHbka0/OY3xc8JuvmrrQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41gy6p4m05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Sep 2024 03:40:50 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 48A3eosY025695 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Sep 2024 03:40:50 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 9 Sep 2024 20:40:49 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/2] phiopt: Use gimple_phi_result rather than PHI_RESULT [PR116643] Date: Mon, 9 Sep 2024 20:40:35 -0700 Message-ID: <20240910034036.1984338-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 9MHXQfwIpUNnRaEhXMAcFpdCkbhsJ9Br X-Proofpoint-GUID: 9MHXQfwIpUNnRaEhXMAcFpdCkbhsJ9Br X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 phishscore=0 impostorscore=0 suspectscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409100025 X-Spam-Status: No, score=-13.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, SPF_NONE, TXREP 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.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 This converts the uses of PHI_RESULT in phiopt to be gimple_phi_result instead. Since there was already a mismatch of uses here, it would be good to use prefered one (gimple_phi_result) instead. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/116643 gcc/ChangeLog: * tree-ssa-phiopt.cc (replace_phi_edge_with_variable): s/PHI_RESULT/gimple_phi_result/. (factor_out_conditional_operation): Likewise. (minmax_replacement): Likewise. (spaceship_replacement): Likewise. (cond_store_replacement): Likewise. (cond_if_else_store_replacement_1): Likewise. Signed-off-by: Andrew Pinski --- gcc/tree-ssa-phiopt.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 06ec5875722..bd8ede06a98 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -97,7 +97,7 @@ replace_phi_edge_with_variable (basic_block cond_block, { basic_block bb = gimple_bb (phi); gimple_stmt_iterator gsi; - tree phi_result = PHI_RESULT (phi); + tree phi_result = gimple_phi_result (phi); bool deleteboth = false; /* Duplicate range info if they are the only things setting the target PHI. @@ -373,7 +373,7 @@ factor_out_conditional_operation (edge e0, edge e1, gphi *phi, return NULL; /* Create a new PHI stmt. */ - result = PHI_RESULT (phi); + result = gimple_phi_result (phi); temp = make_ssa_name (TREE_TYPE (new_arg0), NULL); gimple_match_op new_op = arg0_op; @@ -1684,7 +1684,7 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ tree smaller, larger, arg_true, arg_false; gimple_stmt_iterator gsi, gsi_from; - tree type = TREE_TYPE (PHI_RESULT (phi)); + tree type = TREE_TYPE (gimple_phi_result (phi)); gcond *cond = as_a (*gsi_last_bb (cond_bb)); enum tree_code cmp = gimple_cond_code (cond); @@ -2022,7 +2022,7 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ /* Emit the statement to compute min/max. */ location_t locus = gimple_location (last_nondebug_stmt (cond_bb)); gimple_seq stmts = NULL; - tree phi_result = PHI_RESULT (phi); + tree phi_result = gimple_phi_result (phi); result = gimple_build (&stmts, locus, minmax, TREE_TYPE (phi_result), arg0, arg1); result = gimple_build (&stmts, locus, ass_code, TREE_TYPE (phi_result), @@ -2224,7 +2224,7 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ /* Emit the statement to compute min/max. */ gimple_seq stmts = NULL; - tree phi_result = PHI_RESULT (phi); + tree phi_result = gimple_phi_result (phi); /* When we can't use a MIN/MAX_EXPR still make sure the expression stays in a form to be recognized by ISA that map to IEEE x > y ? x : y @@ -2298,7 +2298,7 @@ spaceship_replacement (basic_block cond_bb, basic_block middle_bb, edge e0, edge e1, gphi *phi, tree arg0, tree arg1) { - tree phires = PHI_RESULT (phi); + tree phires = gimple_phi_result (phi); if (!INTEGRAL_TYPE_P (TREE_TYPE (phires)) || TYPE_UNSIGNED (TREE_TYPE (phires)) || !tree_fits_shwi_p (arg0) @@ -3399,7 +3399,7 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb, add_phi_arg (newphi, rhs, e0, locus); add_phi_arg (newphi, name, e1, locus); - new_stmt = gimple_build_assign (lhs, PHI_RESULT (newphi)); + new_stmt = gimple_build_assign (lhs, gimple_phi_result (newphi)); /* 4) Insert that PHI node. */ gsi = gsi_after_labels (join_bb); @@ -3481,7 +3481,7 @@ cond_if_else_store_replacement_1 (basic_block then_bb, basic_block else_bb, add_phi_arg (newphi, then_rhs, EDGE_SUCC (then_bb, 0), then_locus); add_phi_arg (newphi, else_rhs, EDGE_SUCC (else_bb, 0), else_locus); - new_stmt = gimple_build_assign (lhs, PHI_RESULT (newphi)); + new_stmt = gimple_build_assign (lhs, gimple_phi_result (newphi)); /* 3) Insert that PHI node. */ gsi = gsi_after_labels (join_bb); From patchwork Tue Sep 10 03:40:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1982917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=Mz/fN/fH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4X2qHh5hVfz1y1C for ; Tue, 10 Sep 2024 13:41:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D49AE3858C50 for ; Tue, 10 Sep 2024 03:41:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id 819AF3858C98 for ; Tue, 10 Sep 2024 03:40:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 819AF3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 819AF3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725939655; cv=none; b=rIqSs6OYBNNqLGGQ4ewd/nFGsNpVjVKG0kg/Ine2lSwvJlHTKYEQpaW/A/FyvN32ssU5nm9nuE+YbhIyk+ER5mUW27f0BaFMWDcrcp/UsstAo7XL2SlIuRkH/3dsKqwXHBn2at1eKJbLkrJ2V+Rs3QqeG+BG6zKbG1HRGhRG8S0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725939655; c=relaxed/simple; bh=39aYras6+QKeMNbNpzWqzu7oY/75GcqtefH8ON6HeN0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=g8MFDcBzLuyoeTDSivC7FRQfbsy0wG5YVOyacDkt38h89z77oNm6hKFnLjSo0VvXmNGi9c8ICgoXmnEA3ycPosthmTTe0Ac6fRi63LspLJqObGEPpFlD0VZjLusx44fcnzo9FzyEolQOVVhiGnbjtfOci8f9HocFH+kP/rojI8U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 489IeaPF030468 for ; Tue, 10 Sep 2024 03:40:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= EfkaQaQtVdMegVbfmFIS5mZPmmiloFPQPn3Hfmsjxms=; b=Mz/fN/fHLICOOVxi SwSU7Y3BPDYG8Oq87DbScPEkdmthmbp1bZdorhQYdCmEFmOVsdBkH7p+xtIkKbDu cr9LEu+5ODespnlVEWpY/BIrHrjfyaGnbvoD+aildZ/gtwztcgL4RYydOKjvREhW 6ZgLnML5eSJOCDTFahvKONOLcorqMql0ZtczuFDy8JglIBdWV7bAhO5ZPU3LTmBH w62qNeT9g/96qgChwcTkF0D1J+n4JAPzIYgNuxJYIqExa/5AAr9G7UMK7LxX/JFJ 3LNjRX8oRzZ22GEBwzaxq1NsZQPn3M5tX0IrHa6zh3XDl+xDcU0SFnhoPojSEnjR xvdiRQ== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41j6gmrwph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Sep 2024 03:40:51 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 48A3eo6S025699 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Sep 2024 03:40:50 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 9 Sep 2024 20:40:50 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/2] phiopt: Move the common code between pass_phiopt and pass_cselim into a seperate function Date: Mon, 9 Sep 2024 20:40:36 -0700 Message-ID: <20240910034036.1984338-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910034036.1984338-1-quic_apinski@quicinc.com> References: <20240910034036.1984338-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: YOJnmg9x3o8JLVDnqThCvjve1LEfXuxi X-Proofpoint-GUID: YOJnmg9x3o8JLVDnqThCvjve1LEfXuxi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 clxscore=1015 phishscore=0 mlxlogscore=749 lowpriorityscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409100025 X-Spam-Status: No, score=-13.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, SPF_NONE, TXREP 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.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 When r14-303-gb9fedabe381cce was done, it was missed that some of the common parts could be done in a template and a lambda could be used. This patch implements that. This new function can be used later on to implement a simple ifcvt pass. gcc/ChangeLog: * tree-ssa-phiopt.cc (execute_over_cond_phis): New template function, moved the common parts from pass_phiopt::execute/pass_cselim::execute. (pass_phiopt::execute): Move the functon specific parts of the loop into an lamdba. (pass_cselim::execute): Likewise. Signed-off-by: Andrew Pinski --- gcc/tree-ssa-phiopt.cc | 253 ++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 153 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index bd8ede06a98..5710bc32e61 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -3933,6 +3933,83 @@ gate_hoist_loads (void) && HAVE_conditional_move); } +template +static void +execute_over_cond_phis (func_type func) +{ + unsigned n, i; + basic_block *bb_order; + basic_block bb; + /* Search every basic block for COND_EXPR we may be able to optimize. + + We walk the blocks in order that guarantees that a block with + a single predecessor is processed before the predecessor. + This ensures that we collapse inner ifs before visiting the + outer ones, and also that we do not try to visit a removed + block. */ + bb_order = single_pred_before_succ_order (); + n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; + + for (i = 0; i < n; i++) + { + basic_block bb1, bb2; + edge e1, e2; + bool diamond_p = false; + + bb = bb_order[i]; + + /* Check to see if the last statement is a GIMPLE_COND. */ + gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); + if (!cond_stmt) + continue; + + e1 = EDGE_SUCC (bb, 0); + bb1 = e1->dest; + e2 = EDGE_SUCC (bb, 1); + bb2 = e2->dest; + + /* We cannot do the optimization on abnormal edges. */ + if ((e1->flags & EDGE_ABNORMAL) != 0 + || (e2->flags & EDGE_ABNORMAL) != 0) + continue; + + /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ + if (EDGE_COUNT (bb1->succs) == 0 + || EDGE_COUNT (bb2->succs) == 0) + continue; + + /* Find the bb which is the fall through to the other. */ + if (EDGE_SUCC (bb1, 0)->dest == bb2) + ; + else if (EDGE_SUCC (bb2, 0)->dest == bb1) + { + std::swap (bb1, bb2); + std::swap (e1, e2); + } + else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest + && single_succ_p (bb2)) + { + diamond_p = true; + e2 = EDGE_SUCC (bb2, 0); + /* Make sure bb2 is just a fall through. */ + if ((e2->flags & EDGE_FALLTHRU) == 0) + continue; + } + else + continue; + + e1 = EDGE_SUCC (bb1, 0); + + /* Make sure that bb1 is just a fall through. */ + if (!single_succ_p (bb1) + || (e1->flags & EDGE_FALLTHRU) == 0) + continue; + + func (bb, bb1, bb2, e1, e2, diamond_p, cond_stmt); + } + free (bb_order); +} + /* This pass tries to replaces an if-then-else block with an assignment. We have different kinds of transformations. Some of these transformations are also performed by the ifcvt @@ -4156,88 +4233,22 @@ unsigned int pass_phiopt::execute (function *) { bool do_hoist_loads = !early_p ? gate_hoist_loads () : false; - basic_block bb; - basic_block *bb_order; - unsigned n, i; bool cfgchanged = false; calculate_dominance_info (CDI_DOMINATORS); mark_ssa_maybe_undefs (); - /* Search every basic block for COND_EXPR we may be able to optimize. - - We walk the blocks in order that guarantees that a block with - a single predecessor is processed before the predecessor. - This ensures that we collapse inner ifs before visiting the - outer ones, and also that we do not try to visit a removed - block. */ - bb_order = single_pred_before_succ_order (); - n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; - - for (i = 0; i < n; i++) + auto phiopt_exec = [&] (basic_block bb, basic_block bb1, + basic_block bb2, edge e1, edge e2, + bool diamond_p, gcond *cond_stmt) { - gphi *phi; - basic_block bb1, bb2; - edge e1, e2; - tree arg0, arg1; - bool diamond_p = false; - - bb = bb_order[i]; - - /* Check to see if the last statement is a GIMPLE_COND. */ - gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); - if (!cond_stmt) - continue; - - e1 = EDGE_SUCC (bb, 0); - bb1 = e1->dest; - e2 = EDGE_SUCC (bb, 1); - bb2 = e2->dest; - - /* We cannot do the optimization on abnormal edges. */ - if ((e1->flags & EDGE_ABNORMAL) != 0 - || (e2->flags & EDGE_ABNORMAL) != 0) - continue; - - /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ - if (EDGE_COUNT (bb1->succs) == 0 - || EDGE_COUNT (bb2->succs) == 0) - continue; - - /* Find the bb which is the fall through to the other. */ - if (EDGE_SUCC (bb1, 0)->dest == bb2) - ; - else if (EDGE_SUCC (bb2, 0)->dest == bb1) - { - std::swap (bb1, bb2); - std::swap (e1, e2); - } - else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest - && single_succ_p (bb2)) - { - diamond_p = true; - e2 = EDGE_SUCC (bb2, 0); - /* Make sure bb2 is just a fall through. */ - if ((e2->flags & EDGE_FALLTHRU) == 0) - continue; - } - else - continue; - - e1 = EDGE_SUCC (bb1, 0); - - /* Make sure that bb1 is just a fall through. */ - if (!single_succ_p (bb1) - || (e1->flags & EDGE_FALLTHRU) == 0) - continue; - if (diamond_p) { basic_block bb3 = e1->dest; if (!single_pred_p (bb1) || !single_pred_p (bb2)) - continue; + return; if (do_hoist_loads && !FLOAT_TYPE_P (TREE_TYPE (gimple_cond_lhs (cond_stmt))) @@ -4262,9 +4273,9 @@ pass_phiopt::execute (function *) if (!early_p && !diamond_p) for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) { - phi = as_a (gsi_stmt (gsi)); - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + gphi *phi = as_a (gsi_stmt (gsi)); + tree arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + tree arg1 = gimple_phi_arg_def (phi, e2->dest_idx); if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1) == 2) { candorest = false; @@ -4274,14 +4285,14 @@ pass_phiopt::execute (function *) } if (!candorest) - continue; + return; - phi = single_non_singleton_phi_for_edges (phis, e1, e2); + gphi *phi = single_non_singleton_phi_for_edges (phis, e1, e2); if (!phi) - continue; + return; - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + tree arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + tree arg1 = gimple_phi_arg_def (phi, e2->dest_idx); /* Something is wrong if we cannot find the arguments in the PHI node. */ @@ -4323,9 +4334,9 @@ pass_phiopt::execute (function *) && !diamond_p && spaceship_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) cfgchanged = true; - } + }; - free (bb_order); + execute_over_cond_phis (phiopt_exec); if (cfgchanged) return TODO_cleanup_cfg; @@ -4412,9 +4423,6 @@ make_pass_cselim (gcc::context *ctxt) unsigned int pass_cselim::execute (function *) { - basic_block bb; - basic_block *bb_order; - unsigned n, i; bool cfgchanged = false; hash_set *nontrap = 0; unsigned todo = 0; @@ -4430,71 +4438,10 @@ pass_cselim::execute (function *) /* Calculate the set of non-trapping memory accesses. */ nontrap = get_non_trapping (); - /* Search every basic block for COND_EXPR we may be able to optimize. - - We walk the blocks in order that guarantees that a block with - a single predecessor is processed before the predecessor. - This ensures that we collapse inner ifs before visiting the - outer ones, and also that we do not try to visit a removed - block. */ - bb_order = single_pred_before_succ_order (); - n = n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; - - for (i = 0; i < n; i++) + auto cselim_exec = [&] (basic_block bb, basic_block bb1, + basic_block bb2, edge e1, edge e2, + bool diamond_p, gcond *) { - basic_block bb1, bb2; - edge e1, e2; - bool diamond_p = false; - - bb = bb_order[i]; - - /* Check to see if the last statement is a GIMPLE_COND. */ - gcond *cond_stmt = safe_dyn_cast (*gsi_last_bb (bb)); - if (!cond_stmt) - continue; - - e1 = EDGE_SUCC (bb, 0); - bb1 = e1->dest; - e2 = EDGE_SUCC (bb, 1); - bb2 = e2->dest; - - /* We cannot do the optimization on abnormal edges. */ - if ((e1->flags & EDGE_ABNORMAL) != 0 - || (e2->flags & EDGE_ABNORMAL) != 0) - continue; - - /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ - if (EDGE_COUNT (bb1->succs) == 0 - || EDGE_COUNT (bb2->succs) == 0) - continue; - - /* Find the bb which is the fall through to the other. */ - if (EDGE_SUCC (bb1, 0)->dest == bb2) - ; - else if (EDGE_SUCC (bb2, 0)->dest == bb1) - { - std::swap (bb1, bb2); - std::swap (e1, e2); - } - else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest - && single_succ_p (bb2)) - { - diamond_p = true; - e2 = EDGE_SUCC (bb2, 0); - /* Make sure bb2 is just a fall through. */ - if ((e2->flags & EDGE_FALLTHRU) == 0) - continue; - } - else - continue; - - e1 = EDGE_SUCC (bb1, 0); - - /* Make sure that bb1 is just a fall through. */ - if (!single_succ_p (bb1) - || (e1->flags & EDGE_FALLTHRU) == 0) - continue; - if (diamond_p) { basic_block bb3 = e1->dest; @@ -4504,28 +4451,28 @@ pass_cselim::execute (function *) if always since we are sinking rather than hoisting. */ if (EDGE_COUNT (bb3->preds) != 2) - continue; + return; if (cond_if_else_store_replacement (bb1, bb2, bb3)) cfgchanged = true; - continue; + return; } /* Also make sure that bb1 only have one predecessor and that it is bb. */ if (!single_pred_p (bb1) || single_pred (bb1) != bb) - continue; + return; /* bb1 is the middle block, bb2 the join block, bb the split block, e1 the fallthrough edge from bb1 to bb2. We can't do the optimization if the join block has more than two predecessors. */ if (EDGE_COUNT (bb2->preds) > 2) - continue; + return; if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) cfgchanged = true; - } + }; - free (bb_order); + execute_over_cond_phis (cselim_exec); delete nontrap; /* If the CFG has changed, we should cleanup the CFG. */