From patchwork Thu Sep 12 22:41:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1984901 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=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Ed9x2fjh; 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 4X4XXL2XNKz1y2H for ; Fri, 13 Sep 2024 08:43:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7DA0D385C6CC for ; Thu, 12 Sep 2024 22:43:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by sourceware.org (Postfix) with ESMTPS id 11F823858432 for ; Thu, 12 Sep 2024 22:42:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11F823858432 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 11F823858432 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726180973; cv=none; b=SC3bp/4LayHTLkFUkET1phOdxrdhfYkDZ36hGwZ3+UmFaEl9HRlVA6ie0W9UWarr64kjcHt+QXOzqj29FvlhYEiEcBvDaDOrw1WqCtT5fYPH4aXhDgXsG6WCul90P+1wxjRw7yoMMWNB1lRTpckbWuNtO0bhvEyaJ3tKTzsKvFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726180973; c=relaxed/simple; bh=YjkTQfGXoVXP1ZOsvDI6K+cC3q3CaCiQpx+2lPQtFR8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=b0geUhf3vpCYi9qbb0VjwGm+2+6V862hNDcZZWPo4f5kSR2eRtjuuUfUY5vW3Z08KfkzWnwPrEtE28NYWsH58yiy2nNqrqXlzNlnRuDV1/VVTtt79ZRrcCf/oWG3WyLNzd7n+QGjrVnIPTZ7SV/UwxJeh/xN9qU69i1btCdhOfc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726180971; x=1757716971; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YjkTQfGXoVXP1ZOsvDI6K+cC3q3CaCiQpx+2lPQtFR8=; b=Ed9x2fjh0OWMcsWjKcodrby9W1lKnvuC26KnO3v2SpvpPGBv73TE1H9/ ZhD3SZE2Kn25ogSC94X1T/6apLLoEtU9a4s7DbDsxrlAvWOAgQNClRey+ LPfdCSUpLrToDyEbEpXQp/t96ihRIaEvP1ttpYDAUo3b2rahr0zX5ve7X C0wcSl1P/Az8s3flrNopVRRAwLUyIkdf1QMNcEflFkmAnOiiAJkDkCsPI kEVvje755Q4fqYeX51/uwotzJWMYVXVpIycLpRlvvklF4gP8BmTZ5iW6m rkF00Y1fHnC2nRNo1056VyakDb/3vrij+cZNny1zqW0tLqg3cyUSfW/2g A==; X-CSE-ConnectionGUID: fgMFpnN9Ty+4t7Ype6Ep8Q== X-CSE-MsgGUID: vnaOMQPLT6ug1fEZjcI/sw== X-IronPort-AV: E=McAfee;i="6700,10204,11193"; a="50482949" X-IronPort-AV: E=Sophos;i="6.10,224,1719903600"; d="scan'208";a="50482949" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2024 15:42:50 -0700 X-CSE-ConnectionGUID: Q4X00IfNQ4+hW2pgPbQtlA== X-CSE-MsgGUID: 5FkuGGP/R2GSgq+UqhcRuQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,224,1719903600"; d="scan'208";a="72853857" Received: from panli.sh.intel.com ([10.239.154.73]) by orviesa004.jf.intel.com with ESMTP; 12 Sep 2024 15:42:47 -0700 From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Tamar.Christina@arm.com, juzhe.zhong@rivai.ai, kito.cheng@gmail.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v4 2/4] Genmatch: Refine the gen_phi_on_cond by match_cond_with_binary_phi Date: Fri, 13 Sep 2024 06:41:52 +0800 Message-ID: <20240912224152.802287-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, 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 From: Pan Li This patch would like to leverage the match_cond_with_binary_phi to match the phi on cond, and get the true/false arg if matched. This helps a lot to simplify the implementation of gen_phi_on_cond. Before this patch: basic_block _b1 = gimple_bb (_a1); if (gimple_phi_num_args (_a1) == 2) { basic_block _pb_0_1 = EDGE_PRED (_b1, 0)->src; basic_block _pb_1_1 = EDGE_PRED (_b1, 1)->src; basic_block _db_1 = safe_dyn_cast (*gsi_last_bb (_pb_0_1)) ? _pb_0_1 : _pb_1_1; basic_block _other_db_1 = safe_dyn_cast (*gsi_last_bb (_pb_0_1)) ? _pb_1_1 : _pb_0_1; gcond *_ct_1 = safe_dyn_cast (*gsi_last_bb (_db_1)); if (_ct_1 && EDGE_COUNT (_other_db_1->preds) == 1 && EDGE_COUNT (_other_db_1->succs) == 1 && EDGE_PRED (_other_db_1, 0)->src == _db_1) { tree _cond_lhs_1 = gimple_cond_lhs (_ct_1); tree _cond_rhs_1 = gimple_cond_rhs (_ct_1); tree _p0 = build2 (gimple_cond_code (_ct_1), boolean_type_node, _cond_lhs_1, _cond_rhs_1); bool _arg_0_is_true_1 = gimple_phi_arg_edge (_a1, 0)->flags & EDGE_TRUE_VALUE; tree _p1 = gimple_phi_arg_def (_a1, _arg_0_is_true_1 ? 0 : 1); tree _p2 = gimple_phi_arg_def (_a1, _arg_0_is_true_1 ? 1 : 0); ... After this patch: basic_block _b1 = gimple_bb (_a1); tree _p1, _p2; gcond *_cond_1 = match_cond_with_binary_phi (_a1, &_p1, &_p2); if (_cond_1 && _p1 && _p2) { tree _cond_lhs_1 = gimple_cond_lhs (_cond_1); tree _cond_rhs_1 = gimple_cond_rhs (_cond_1); tree _p0 = build2 (gimple_cond_code (_cond_1), boolean_type_node, _cond_lhs_1, _cond_rhs_1); ... The below test suites are passed for this patch. * The rv64gcv fully regression test. * The x86 bootstrap test. * The x86 fully regression test. gcc/ChangeLog: * genmatch.cc (dt_operand::gen_phi_on_cond): Leverage the match_cond_with_binary_phi API to get cond gimple, true and false TREE arg. Signed-off-by: Pan Li --- gcc/genmatch.cc | 67 +++++++++++-------------------------------------- 1 file changed, 15 insertions(+), 52 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index a56bd90cb2c..e3d2ecc6266 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -3516,79 +3516,42 @@ dt_operand::gen (FILE *f, int indent, bool gimple, int depth) void dt_operand::gen_phi_on_cond (FILE *f, int indent, int depth) { - fprintf_indent (f, indent, - "basic_block _b%d = gimple_bb (_a%d);\n", depth, depth); - - fprintf_indent (f, indent, "if (gimple_phi_num_args (_a%d) == 2)\n", depth); + char opname_0[20]; + char opname_1[20]; + char opname_2[20]; - indent += 2; - fprintf_indent (f, indent, "{\n"); - indent += 2; + gen_opname (opname_0, 0); + gen_opname (opname_1, 1); + gen_opname (opname_2, 2); fprintf_indent (f, indent, - "basic_block _pb_0_%d = EDGE_PRED (_b%d, 0)->src;\n", depth, depth); - fprintf_indent (f, indent, - "basic_block _pb_1_%d = EDGE_PRED (_b%d, 1)->src;\n", depth, depth); - fprintf_indent (f, indent, - "basic_block _db_%d = safe_dyn_cast (*gsi_last_bb (_pb_0_%d)) ? " - "_pb_0_%d : _pb_1_%d;\n", depth, depth, depth, depth); + "basic_block _b%d = gimple_bb (_a%d);\n", depth, depth); + fprintf_indent (f, indent, "tree %s, %s;\n", opname_1, opname_2); fprintf_indent (f, indent, - "basic_block _other_db_%d = safe_dyn_cast " - "(*gsi_last_bb (_pb_0_%d)) ? _pb_1_%d : _pb_0_%d;\n", - depth, depth, depth, depth); + "gcond *_cond_%d = match_cond_with_binary_phi (_a%d, &%s, &%s);\n", + depth, depth, opname_1, opname_2); - fprintf_indent (f, indent, - "gcond *_ct_%d = safe_dyn_cast (*gsi_last_bb (_db_%d));\n", - depth, depth); - fprintf_indent (f, indent, "if (_ct_%d" - " && EDGE_COUNT (_other_db_%d->preds) == 1\n", depth, depth); - fprintf_indent (f, indent, - " && EDGE_COUNT (_other_db_%d->succs) == 1\n", depth); - fprintf_indent (f, indent, - " && EDGE_PRED (_other_db_%d, 0)->src == _db_%d)\n", depth, depth); + fprintf_indent (f, indent, "if (_cond_%d && %s && %s)\n", + depth, opname_1, opname_2); indent += 2; fprintf_indent (f, indent, "{\n"); indent += 2; fprintf_indent (f, indent, - "tree _cond_lhs_%d = gimple_cond_lhs (_ct_%d);\n", depth, depth); + "tree _cond_lhs_%d = gimple_cond_lhs (_cond_%d);\n", depth, depth); fprintf_indent (f, indent, - "tree _cond_rhs_%d = gimple_cond_rhs (_ct_%d);\n", depth, depth); - - char opname_0[20]; - char opname_1[20]; - char opname_2[20]; - gen_opname (opname_0, 0); - + "tree _cond_rhs_%d = gimple_cond_rhs (_cond_%d);\n", depth, depth); fprintf_indent (f, indent, - "tree %s = build2 (gimple_cond_code (_ct_%d), " + "tree %s = build2 (gimple_cond_code (_cond_%d), " "boolean_type_node, _cond_lhs_%d, _cond_rhs_%d);\n", opname_0, depth, depth, depth); - fprintf_indent (f, indent, - "bool _arg_0_is_true_%d = gimple_phi_arg_edge (_a%d, 0)->flags" - " & EDGE_TRUE_VALUE;\n", depth, depth); - - gen_opname (opname_1, 1); - fprintf_indent (f, indent, - "tree %s = gimple_phi_arg_def (_a%d, _arg_0_is_true_%d ? 0 : 1);\n", - opname_1, depth, depth); - - gen_opname (opname_2, 2); - fprintf_indent (f, indent, - "tree %s = gimple_phi_arg_def (_a%d, _arg_0_is_true_%d ? 1 : 0);\n", - opname_2, depth, depth); - gen_kids (f, indent, true, depth); indent -= 2; fprintf_indent (f, indent, "}\n"); indent -= 2; - - indent -= 2; - fprintf_indent (f, indent, "}\n"); - indent -= 2; } /* Emit a logging call to the debug file to the file F, with the INDENT from