From patchwork Fri Jul 26 04:35:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1965181 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=kMzcFlWv; 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 4WVZj44Xp5z1yY9 for ; Fri, 26 Jul 2024 14:36:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA2543858432 for ; Fri, 26 Jul 2024 04:36:54 +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 500923858C33 for ; Fri, 26 Jul 2024 04:36:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 500923858C33 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 500923858C33 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=1721968578; cv=none; b=pKSS2droGhWvHgZ9+mqBj9WR/FnxS9fI66mrTY8CWzGuwFWuYQnkXBAlP65Z6weRUoXbbcAsx/zUpa6b+cthIwwB2F/TogAZdZUGL4vEuV+62D3sc9YnNL9qTwcEKdCYFj9ocs7bvZtSPMLKSY/IIDc22p3N+ur7jjGIzn9+LZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721968578; c=relaxed/simple; bh=xS2mWQknYVNWjbhIivA7GvLbWAsuskcLjXynEZjBCTU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tJ+8HNN6A+cFAnlFz91Mxzx/DS2qz0e5R5OxkoHSsOoluZWp2/ppGJlVZaDRZsPgciGHnjJs+MUZEw6ZqKEtEEI4aOtUMME8RZSADgnnnjpjB2lYyTkcpoYXi+zUUHWKKafQB5UICcPn0RGpzGZUVYXb6I/zp0FDzZKgGqNbggs= 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 46Q11YBr020213 for ; Fri, 26 Jul 2024 04:36:14 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= eD0J6CTM74cttyPOPUvnc7VnyXUsO+5A7jYmJYi+i9c=; b=kMzcFlWv2jBilN3s y691nXvTMvyBoAqxEteA/Tnmdg1tYUhCQtPRpI1k9ISTIPNKgJ6dNrcQb33nh53J MluxAFShTnL/6YAf+NcRk5uhnamr2mE2HBfe1fKvqRwRPvjbEhy5MzD0/AWY0t+q 6ngiGdidqZIK6b4ad9mhBmsj2dOGKrwaOkw31J22OfeJY3i6JJo/YDSc+Q9BFj46 4vqg2EhJGV/k9694Vcnnbq3LmX2Kqv36bEprTESbDnsHv+BtkTTvzN6em9gQ2e9d N5U6NAsArpGFhvqkKF6278BBqsoV0xosBjhcqNK49ssiSm5Vk8qJAIyaQJ7Csz4l ZJOxew== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 40m1s90bry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 26 Jul 2024 04:36:14 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA02.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 46Q4aDpf007359 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 26 Jul 2024 04:36:13 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; Thu, 25 Jul 2024 21:36:12 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/3] isel: Small cleanup of duplicating comparisons Date: Thu, 25 Jul 2024 21:35:59 -0700 Message-ID: <20240726043600.47858-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726043600.47858-1-quic_apinski@quicinc.com> References: <20240726043600.47858-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) 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: ZGl9WLP65eyru3q1fE2YCbbZdz785PfP X-Proofpoint-GUID: ZGl9WLP65eyru3q1fE2YCbbZdz785PfP 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-07-26_01,2024-07-25_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=997 suspectscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 phishscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2407260030 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, 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 is a small cleanup of the duplicating comparison code. There is code generation difference but only for -O0 and -fno-tree-ter (both of which will be fixed in a later patch). The difference is instead of skipping the first use if the comparison uses are only in cond_expr we skip the last use. Also we go through the uses list in the opposite order now too. The cleanups are the following: * Don't call has_single_use as we will do the loop anyways * Change the order of the checks slightly, it is better to check for cond_expr earlier * Use cond_exprs as a stack and pop from it. Skipping the top if the use is only from cond_expr. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * gimple-isel.cc (duplicate_comparison): Rename to ... (maybe_duplicate_comparison): This. Add check for use here rather than in its caller. (pass_gimple_isel::execute): Don't check how many uses the comparison had and call maybe_duplicate_comparison instead of duplicate_comparison. Signed-off-by: Andrew Pinski --- gcc/gimple-isel.cc | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc index 327a78ea408..99bfc937bd5 100644 --- a/gcc/gimple-isel.cc +++ b/gcc/gimple-isel.cc @@ -399,34 +399,46 @@ gimple_expand_vec_cond_expr (struct function *fun, gimple_stmt_iterator *gsi, comparisons so RTL expansion with the help of TER can perform better if conversion. */ static void -duplicate_comparison (gassign *stmt, basic_block bb) +maybe_duplicate_comparison (gassign *stmt, basic_block bb) { imm_use_iterator imm_iter; use_operand_p use_p; auto_vec cond_exprs; - unsigned cnt = 0; tree lhs = gimple_assign_lhs (stmt); + unsigned cnt = 0; + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs) { if (is_gimple_debug (USE_STMT (use_p))) continue; cnt++; + /* Add the use statement if it was a cond_expr. */ if (gimple_bb (USE_STMT (use_p)) == bb && is_gimple_assign (USE_STMT (use_p)) - && gimple_assign_rhs1_ptr (USE_STMT (use_p)) == use_p->use - && gimple_assign_rhs_code (USE_STMT (use_p)) == COND_EXPR) + && gimple_assign_rhs_code (USE_STMT (use_p)) == COND_EXPR + && gimple_assign_rhs1_ptr (USE_STMT (use_p)) == use_p->use) cond_exprs.safe_push (as_a (USE_STMT (use_p))); - } - for (unsigned i = cond_exprs.length () == cnt ? 1 : 0; - i < cond_exprs.length (); ++i) + } + + /* If the comparison has 0 or 1 uses, no reason to do anything. */ + if (cnt <= 1) + return; + + /* If we only use the expression inside cond_exprs in that BB, we don't + need to duplicate for one of them so pop the top. */ + if (cond_exprs.length () == cnt) + cond_exprs.pop(); + + while (!cond_exprs.is_empty()) { + auto old_top = cond_exprs.pop(); gassign *copy = as_a (gimple_copy (stmt)); tree new_def = duplicate_ssa_name (lhs, copy); gimple_assign_set_lhs (copy, new_def); - auto gsi2 = gsi_for_stmt (cond_exprs[i]); + auto gsi2 = gsi_for_stmt (old_top); gsi_insert_before (&gsi2, copy, GSI_SAME_STMT); - gimple_assign_set_rhs1 (cond_exprs[i], new_def); - update_stmt (cond_exprs[i]); + gimple_assign_set_rhs1 (old_top, new_def); + update_stmt (old_top); } } @@ -500,10 +512,8 @@ pass_gimple_isel::execute (struct function *fun) continue; tree_code code = gimple_assign_rhs_code (stmt); - tree lhs = gimple_assign_lhs (stmt); - if (TREE_CODE_CLASS (code) == tcc_comparison - && !has_single_use (lhs)) - duplicate_comparison (stmt, bb); + if (TREE_CODE_CLASS (code) == tcc_comparison) + maybe_duplicate_comparison (stmt, bb); } }