From patchwork Thu Sep 19 04:10:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1987175 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=kUgQIV5R; 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 4X8MYF65Spz1y27 for ; Thu, 19 Sep 2024 14:12:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C9A2D385DC1B for ; Thu, 19 Sep 2024 04:12: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 [198.175.65.15]) by sourceware.org (Postfix) with ESMTPS id C36EF3858280 for ; Thu, 19 Sep 2024 04:11:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C36EF3858280 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 C36EF3858280 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726719106; cv=none; b=utDs2Pqy88db1joEir6S/YBz88QMeLJw77amY0oaI77cA+SIdYU03M3cRiSDq+OtgdFQpwxNpCiMqStpUvADgzjkImJ40FeBcMaeouSxzcHEHfE5K76DgWzBvAvW62FheEJACynHd/gWTqPeiprekwvtdOK2blP4wylRCTbKaSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726719106; c=relaxed/simple; bh=dp1XLIOhMu91CwZf6MjwLDPTpgM6sKyQU8KARuAjWq8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rs8IAFHX5zACnTqW8XiXQKpuvebSjNK+cp5GCsfeNCBnqZSFqjKpXmbkTaEGukmfOoiXiI0Dt9J16OPWbe2xkSFmdxjtA8gCvOmXKhOY4pLbTsMQE3N2RmMcc613CR7qo4DqKxRA3jikY7UrDe+2aRcIrtOAsajkn5JghKIgA2Q= 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=1726719105; x=1758255105; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=dp1XLIOhMu91CwZf6MjwLDPTpgM6sKyQU8KARuAjWq8=; b=kUgQIV5RnY1ZavjabWkLm6ju18JE8XEsXSFQBjj05RTIChLFAPqYalhs 8wcjlR6/EHOeZOksXGoqw/ePnqyCvniFcFPBS4eLW2vcW2vWipcKowOZA 4wtYnP3x01V5CuNvjPONPkMN0tqC1wZofzCQIT3th6KVu5O/mM3Ze5n90 KDPYfV59UWsa1wJffYKzY01nhSadoOJxi3HiMpYx/AmowRhJemBF7UcNr 2Upto9oRvUMfpLX5ywpTzTH4ZbP6wL7BV006PXifr6DlS278V1TtgmdEe 8441wvpiSY6wyWEb7eKhKSqzEzpVpEngIUuwiSy9msky+Q84NcvrG/Yqg A==; X-CSE-ConnectionGUID: 1p+nXz1FT+uNT7kGfQpvqg== X-CSE-MsgGUID: snswptg6Ra+cIxPSt8rBtw== X-IronPort-AV: E=McAfee;i="6700,10204,11199"; a="29401668" X-IronPort-AV: E=Sophos;i="6.10,240,1719903600"; d="scan'208";a="29401668" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2024 21:11:43 -0700 X-CSE-ConnectionGUID: CQTcw1puTiq4b7372nN20w== X-CSE-MsgGUID: CCUznkZRT7CnuNYFzpTuvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,240,1719903600"; d="scan'208";a="74576015" Received: from panli.sh.intel.com ([10.239.154.73]) by orviesa005.jf.intel.com with ESMTP; 18 Sep 2024 21:11:41 -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 v5 1/4] Match: Add interface match_cond_with_binary_phi for true/false arg Date: Thu, 19 Sep 2024 12:10:38 +0800 Message-ID: <20240919041038.3796202-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, 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 When matching the cond with 2 args phi node, we need to figure out which arg of phi node comes from the true edge of cond block, as well as the false edge. This patch would like to add interface to perform the action and return the true and false arg in TREE type. 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: * gimple-match-head.cc (match_cond_with_binary_phi): Add new func impl to match binary phi for true and false arg. Signed-off-by: Pan Li --- gcc/gimple-match-head.cc | 120 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc index 924d3f1e710..b63b66e9485 100644 --- a/gcc/gimple-match-head.cc +++ b/gcc/gimple-match-head.cc @@ -375,3 +375,123 @@ gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, bool &wascmp, tree (*va return true; return false; } + +/* + * Return the relevant gcond * of the given phi, as well as the true + * and false TREE args of the phi. Or return nullptr. + * + * If matched the gcond *, the output argument TREE true_arg and false_arg + * will be updated to the relevant args of phi. + * + * If failed to match, nullptr gcond * will be returned, as well as the output + * arguments will be set to NULL_TREE. + */ + +static inline gcond * +match_cond_with_binary_phi (gphi *phi, tree *true_arg, tree *false_arg) +{ + *true_arg = *false_arg = NULL_TREE; + + if (gimple_phi_num_args (phi) != 2) + return nullptr; + + basic_block pred_b0 = EDGE_PRED (gimple_bb (phi), 0)->src; + basic_block pred_b1 = EDGE_PRED (gimple_bb (phi), 1)->src; + edge edge_for_pred_0 = nullptr; + + if (EDGE_COUNT (pred_b0->succs) == 2 + && EDGE_COUNT (pred_b1->succs) == 1 + && EDGE_COUNT (pred_b1->preds) == 1 + && pred_b0 == EDGE_PRED (gimple_bb (phi), 0)->src) + /* + * +------+ + * | b0: | + * | def | +-----+ + * | ... | | b1: | + * | cond |------>| def | + * +------+ | ... | + * | +-----+ + * # | + * | | + * v | + * +-----+ | + * | b2: | | + * | def |<----------+ + * +-----+ + * #: edge_for_pred_0. + */ + edge_for_pred_0 = EDGE_PRED (gimple_bb (phi), 0); + else if (EDGE_COUNT (pred_b1->succs) == 2 + && EDGE_COUNT (pred_b0->succs) == 1 + && EDGE_COUNT (pred_b0->preds) == 1 + && pred_b1 == EDGE_PRED (pred_b0, 0)->src) + /* + * +------+ + * | b1: | + * +-----+ | def | + * | b0: | | ... | + * | def |<---#---| cond | + * | ... | +------+ + * +-----+ | + * | | + * | | + * | | + * v | + * +-----+ | + * | b2: | | + * | def |<----------+ + * +-----+ + * #: edge_for_pred_0. + */ + edge_for_pred_0 = EDGE_PRED (pred_b0, 0); + else if (EDGE_COUNT (pred_b0->succs) == 1 + && EDGE_COUNT (pred_b1->succs) == 1 + && EDGE_COUNT (pred_b0->preds) == 1 + && EDGE_COUNT (pred_b1->preds) == 1 + && EDGE_COUNT (EDGE_PRED (pred_b0, 0)->src->succs) == 2 + && EDGE_PRED (pred_b0, 0)->src == EDGE_PRED (pred_b1, 0)->src) + /* +------+ + * | b0: | + * | ... | +-----+ + * | cond |------>| b2: | + * +------+ | ... | + * | +-----+ + * # | + * | | + * v | + * +-----+ | + * | b1: | | + * | ... | | + * +-----+ | + * | | + * | | + * v | + * +-----+ | + * | b3: |<----------+ + * | ... | + * +-----+ + * #: edge_for_pred_0. + */ + edge_for_pred_0 = EDGE_PRED (pred_b0, 0); + + if (!edge_for_pred_0) + return nullptr; + + gcond *cond = safe_dyn_cast (*gsi_last_bb (edge_for_pred_0->src)); + + if (!cond) + return nullptr; + + if (edge_for_pred_0->flags & EDGE_TRUE_VALUE) + { + *true_arg = gimple_phi_arg_def (phi, 0); + *false_arg = gimple_phi_arg_def (phi, 1); + } + else /* Aka edge_for_pred_0->flags & EDGE_FALSE_VALUE */ + { + *false_arg = gimple_phi_arg_def (phi, 0); + *true_arg = gimple_phi_arg_def (phi, 1); + } + + return cond; +}