From patchwork Sun Sep 1 04:06:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1979368 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=e8hJ5cUL; 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 4WxJHM5FGyz1yZs for ; Sun, 1 Sep 2024 14:06:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E04E385842C for ; Sun, 1 Sep 2024 04:06:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id BCAF43858D34 for ; Sun, 1 Sep 2024 04:06:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCAF43858D34 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 BCAF43858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725163593; cv=none; b=j6R0ySrefotQXbuK+CHMhWqizzwJt9Zm2n/uVZptHZFxhI29mpCWcVuJZzN8uWRQTN5dF198/hD3uVSvE5eLhi5JizOGGkoMADFeRFjfGDxhG5SA4KvsRAuijLXzWElX9AvsBGWuyu8Bz7mnjJXK/MnfBzDeAuZnamte6jGMVRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725163593; c=relaxed/simple; bh=QqCHvDXYJjFjnWlvoon/3FD9XlrHXqUG/ilGDkskPVo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tAgpE97+fdA1I7voVxQKS2PearTkOxJ0sLJLtK54kwIwNcU9DNq8Eq982NJzR7LKTSF2RCezrNlarJat56Q4wWNUrJ2N4FQZ0d7PlMozGbeDAI5ba3fAEB+/hRykX0s8c9nBuT3oOgmR0pgndiPXOdv03VrD70Z1el4jUUul6pE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4813e2iW010247 for ; Sun, 1 Sep 2024 04:06:30 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=J8U2440rY7X9u1qjqYewsF sdsVYxoUuoQVgS9JXnlGo=; b=e8hJ5cULDT3UAaPI02UrVqTDAMjc76HYoMeKwf r6Dh83IIGtbQMeHXwfRSeVEB1NB3TLVQgRxnuBqLOLPnkk6FC/6aOXe+3QgdtRVb otDtLy0BK/NRi8V/XRhv3BLYvW3ZQtUkoFHnBdelpTy1CRblai9dAprDyher2WXK gD19RZhUDLvT95AuaVkERAUvz50XLeQ7E0+n2WPmPJFfh0hlMEy5cwzEfp407oVK +vy1x/8I2CUc4GS+zlAU5I04hsLIXoun6U9vuQqjvBeus8jV4v94oftpxRCyFcyN Mq4Bn2V1AqQLLR56ZrF4FIpaGNSsRtB4G/vcXchMPc430e0w== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41buj6susj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 01 Sep 2024 04:06:29 +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 48146SM3003206 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 1 Sep 2024 04:06:28 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; Sat, 31 Aug 2024 21:06:28 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] slsr: Use simple_dce_from_worklist in SLSR [PR116554] Date: Sat, 31 Aug 2024 21:06:18 -0700 Message-ID: <20240901040618.1308809-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: 6Gryry9Nskh_LChpBkWUvUemkOSiyyu_ X-Proofpoint-GUID: 6Gryry9Nskh_LChpBkWUvUemkOSiyyu_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-31_04,2024-08-30_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 mlxlogscore=579 impostorscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2409010032 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, T_SCC_BODY_TEXT_LINE 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 While working on a phiopt patch, it was noticed that SLSR would leave around some unused ssa names. Let's add simple_dce_from_worklist usage to SLSR to remove the dead statements. This should give a small improvemnent for passes afterwards. Boostrapped and tested on x86_64. gcc/ChangeLog: PR tree-optimization/116554 * gimple-ssa-strength-reduction.cc: Include tree-ssa-dce.h. (replace_mult_candidate): Add sdce_worklist argument, mark the rhs1/rhs2 for maybe dceing. (replace_unconditional_candidate): Add sdce_worklist argument, Update call to replace_mult_candidate. (replace_conditional_candidate): Add sdce_worklist argument, update call to replace_mult_candidate. (replace_uncond_cands_and_profitable_phis): Add sdce_worklist argument, update call to replace_conditional_candidate, replace_unconditional_candidate, and replace_uncond_cands_and_profitable_phis. (replace_one_candidate): Add sdce_worklist argument, mark the orig_rhs1/orig_rhs2 for maybe dceing. (replace_profitable_candidates): Add sdce_worklist argument, update call to replace_one_candidate and replace_profitable_candidates. (analyze_candidates_and_replace): Call simple_dce_from_worklist and update calls to replace_profitable_candidates, and replace_uncond_cands_and_profitable_phis. Signed-off-by: Andrew Pinski --- gcc/gimple-ssa-strength-reduction.cc | 59 +++++++++++++++++++--------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/gcc/gimple-ssa-strength-reduction.cc b/gcc/gimple-ssa-strength-reduction.cc index 1cb3625c7eb..39cd9339c77 100644 --- a/gcc/gimple-ssa-strength-reduction.cc +++ b/gcc/gimple-ssa-strength-reduction.cc @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-affine.h" #include "tree-eh.h" #include "builtins.h" +#include "tree-ssa-dce.h" /* Information about a strength reduction candidate. Each statement in the candidate table represents an expression of one of the @@ -2126,7 +2127,8 @@ cand_already_replaced (slsr_cand_t c) replace_conditional_candidate. */ static void -replace_mult_candidate (slsr_cand_t c, tree basis_name, offset_int bump) +replace_mult_candidate (slsr_cand_t c, tree basis_name, offset_int bump, + auto_bitmap &sdce_worklist) { tree target_type = TREE_TYPE (gimple_assign_lhs (c->cand_stmt)); enum tree_code cand_code = gimple_assign_rhs_code (c->cand_stmt); @@ -2193,6 +2195,11 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, offset_int bump) if (cand_code != NEGATE_EXPR) { rhs1 = gimple_assign_rhs1 (c->cand_stmt); rhs2 = gimple_assign_rhs2 (c->cand_stmt); + /* Mark the 2 original rhs for maybe DCEing. */ + if (TREE_CODE (rhs1) == SSA_NAME) + bitmap_set_bit (sdce_worklist, SSA_NAME_VERSION (rhs1)); + if (TREE_CODE (rhs2) == SSA_NAME) + bitmap_set_bit (sdce_worklist, SSA_NAME_VERSION (rhs2)); } if (cand_code != NEGATE_EXPR && ((operand_equal_p (rhs1, basis_name, 0) @@ -2237,7 +2244,7 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, offset_int bump) folded value ((i - i') * S) is referred to here as the "bump." */ static void -replace_unconditional_candidate (slsr_cand_t c) +replace_unconditional_candidate (slsr_cand_t c, auto_bitmap &sdce_worklist) { slsr_cand_t basis; @@ -2247,7 +2254,8 @@ replace_unconditional_candidate (slsr_cand_t c) basis = lookup_cand (c->basis); offset_int bump = cand_increment (c) * wi::to_offset (c->stride); - replace_mult_candidate (c, gimple_assign_lhs (basis->cand_stmt), bump); + replace_mult_candidate (c, gimple_assign_lhs (basis->cand_stmt), bump, + sdce_worklist); } /* Return the index in the increment vector of the given INCREMENT, @@ -2507,7 +2515,8 @@ create_phi_basis (slsr_cand_t c, gimple *from_phi, tree basis_name, basis. */ static void -replace_conditional_candidate (slsr_cand_t c) +replace_conditional_candidate (slsr_cand_t c, auto_bitmap &sdce_worklist) + { tree basis_name, name; slsr_cand_t basis; @@ -2527,7 +2536,7 @@ replace_conditional_candidate (slsr_cand_t c) /* Replace C with an add of the new basis phi and a constant. */ offset_int bump = c->index * wi::to_offset (c->stride); - replace_mult_candidate (c, name, bump); + replace_mult_candidate (c, name, bump, sdce_worklist); } /* Recursive helper function for phi_add_costs. SPREAD is a measure of @@ -2608,7 +2617,8 @@ phi_add_costs (gimple *phi, slsr_cand_t c, int one_add_cost) so, replace the candidate and introduce the compensation code. */ static void -replace_uncond_cands_and_profitable_phis (slsr_cand_t c) +replace_uncond_cands_and_profitable_phis (slsr_cand_t c, + auto_bitmap &sdce_worklist) { if (phi_dependent_cand_p (c)) { @@ -2643,17 +2653,19 @@ replace_uncond_cands_and_profitable_phis (slsr_cand_t c) } if (cost <= COST_NEUTRAL) - replace_conditional_candidate (c); + replace_conditional_candidate (c, sdce_worklist); } } else - replace_unconditional_candidate (c); + replace_unconditional_candidate (c, sdce_worklist); if (c->sibling) - replace_uncond_cands_and_profitable_phis (lookup_cand (c->sibling)); + replace_uncond_cands_and_profitable_phis (lookup_cand (c->sibling), + sdce_worklist); if (c->dependent) - replace_uncond_cands_and_profitable_phis (lookup_cand (c->dependent)); + replace_uncond_cands_and_profitable_phis (lookup_cand (c->dependent), + sdce_worklist); } /* Count the number of candidates in the tree rooted at C that have @@ -3675,7 +3687,8 @@ replace_rhs_if_not_dup (enum tree_code new_code, tree new_rhs1, tree new_rhs2, is the rhs1 to use in creating the add/subtract. */ static void -replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) +replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name, + auto_bitmap &sdce_worklist) { gimple *stmt_to_print = NULL; tree orig_rhs1, orig_rhs2; @@ -3693,6 +3706,12 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) if (!orig_rhs2) return; + /* Mark the 2 original rhs for maybe DCEing. */ + if (TREE_CODE (orig_rhs1) == SSA_NAME) + bitmap_set_bit (sdce_worklist, SSA_NAME_VERSION (orig_rhs1)); + if (TREE_CODE (orig_rhs2) == SSA_NAME) + bitmap_set_bit (sdce_worklist, SSA_NAME_VERSION (orig_rhs2)); + if (dump_file && (dump_flags & TDF_DETAILS)) { fputs ("Replacing: ", dump_file); @@ -3835,7 +3854,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) an increment if such has been shown to be profitable. */ static void -replace_profitable_candidates (slsr_cand_t c) +replace_profitable_candidates (slsr_cand_t c, auto_bitmap &sdce_worklist) { if (!cand_already_replaced (c)) { @@ -3872,23 +3891,23 @@ replace_profitable_candidates (slsr_cand_t c) /* Replace C with an add of the new basis phi and the increment. */ - replace_one_candidate (c, i, name); + replace_one_candidate (c, i, name, sdce_worklist); } } else { slsr_cand_t basis = lookup_cand (c->basis); tree basis_name = gimple_assign_lhs (basis->cand_stmt); - replace_one_candidate (c, i, basis_name); + replace_one_candidate (c, i, basis_name, sdce_worklist); } } } if (c->sibling) - replace_profitable_candidates (lookup_cand (c->sibling)); + replace_profitable_candidates (lookup_cand (c->sibling), sdce_worklist); if (c->dependent) - replace_profitable_candidates (lookup_cand (c->dependent)); + replace_profitable_candidates (lookup_cand (c->dependent), sdce_worklist); } /* Analyze costs of related candidates in the candidate vector, @@ -3899,6 +3918,7 @@ analyze_candidates_and_replace (void) { unsigned i; slsr_cand_t c; + auto_bitmap simple_dce_worklist; /* Each candidate that has a null basis and a non-null dependent is the root of a tree of related statements. @@ -3932,7 +3952,8 @@ analyze_candidates_and_replace (void) compensation code it requires is offset by the strength reduction savings. */ else if (TREE_CODE (c->stride) == INTEGER_CST) - replace_uncond_cands_and_profitable_phis (first_dep); + replace_uncond_cands_and_profitable_phis (first_dep, + simple_dce_worklist); /* When the stride is an SSA name, it may still be profitable to replace some or all of the dependent candidates, depending @@ -3969,7 +3990,7 @@ analyze_candidates_and_replace (void) dump_incr_vec (); /* Perform the replacements. */ - replace_profitable_candidates (first_dep); + replace_profitable_candidates (first_dep, simple_dce_worklist); free (incr_vec); } } @@ -3977,6 +3998,8 @@ analyze_candidates_and_replace (void) /* For conditional candidates, we may have uncommitted insertions on edges to clean up. */ gsi_commit_edge_inserts (); + + simple_dce_from_worklist (simple_dce_worklist); } namespace {