From patchwork Tue Jul 2 02:51:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1954992 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=dsFIgwio; 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 4WCnYS06YFz1xpc for ; Tue, 2 Jul 2024 12:54:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 73FE9388204A for ; Tue, 2 Jul 2024 02:53:59 +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.16]) by sourceware.org (Postfix) with ESMTPS id 0E8393858CDA for ; Tue, 2 Jul 2024 02:53:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E8393858CDA 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 0E8393858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719888819; cv=none; b=YKdIJ9s5yYDRfwfCWokzSzX5BhcCeyAj0hQ+lEA5fWT2xc+5Ez+rDnn1B1mBClAGGRp8weh/aD8xViJzEjXx3fF8Br6M2enmfHn+oNO3beyn3RzvAq/kE8uXJ8qBO0SDUgru9PIFsOyEJAIvPQnRI4KE/MUxhza43P0sW3PRHUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719888819; c=relaxed/simple; bh=T5JB/Jjt2jrYikFX/Zo5l0jIfj0m2Dr7mUItV3Xrfso=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=T4wS4M+ARUbnXd2sOm8Y+ui2KxzPy0mnf/vZynz24ohRKQrNLTxjLp4ADJ41009ShrOzAxohbvKbfWis7+tLoHWFYSOq2ZT6CC7pYkDAMmcITW5JR5aoaSgwYpWMbQzTrX9jkQ/E4ApgtezGjS1k7VXpU+7UzwsORzpOsfv4lNs= 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=1719888817; x=1751424817; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=T5JB/Jjt2jrYikFX/Zo5l0jIfj0m2Dr7mUItV3Xrfso=; b=dsFIgwio5r7qA5h6TV5o6m97DFSclaAIodK7DZbnHjpseU4iI4oXWp6+ 4qutETQJhHOio+VgJRsq3/0+MWLHQ3hHGqULPStOd3DiedxnqEozEGkc+ CZnMGj5GiAdSxK5O2iTSfwyR+D9tgUzVYY10QeTOix/F85XzK7mngg9Ur IPo63wy4e4hDUB7gQSd8QJSTARkEJMHyyJTTO70T7C53eCcnzaUhVMZHo 4+dtBgF0zIoHa7JNwvnPXbDMm63TYPLayBO+R6yOlI+YPWUsyXiNWEq9g GP0k1yuZ0iKjh8zBkiODzbmZZMj/0kDYOf22Xk8Uha4DolW1VazxWpEVq g==; X-CSE-ConnectionGUID: 5VjnJh4kSx6qXN0ezZl//g== X-CSE-MsgGUID: aTSB/7SySXCsGNhZZ4THFg== X-IronPort-AV: E=McAfee;i="6700,10204,11120"; a="12349949" X-IronPort-AV: E=Sophos;i="6.09,177,1716274800"; d="scan'208";a="12349949" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2024 19:53:36 -0700 X-CSE-ConnectionGUID: 0YRrQ2CrSN6bBwBL30Ei5Q== X-CSE-MsgGUID: 83QAIB9XRm+10O+y+nfMJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,177,1716274800"; d="scan'208";a="76907052" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmviesa001.fm.intel.com with ESMTP; 01 Jul 2024 19:53:34 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 9083D100569C; Tue, 2 Jul 2024 10:53:33 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] x86: Update branch hint for Redwood Cove. Date: Tue, 2 Jul 2024 10:51:33 +0800 Message-Id: <20240702025133.2737549-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 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: "H.J. Lu" According to Intel® 64 and IA-32 Architectures Optimization Reference Manual[1], Branch Hint is updated for Redwood Cove. --------cut from [1]------------------------- Starting with the Redwood Cove microarchitecture, if the predictor has no stored information about a branch, the branch has the Intel® SSE2 branch taken hint (i.e., instruction prefix 3EH), When the codec decodes the branch, it flips the branch’s prediction from not-taken to taken. It then flushes the pipeline in front of it and steers this pipeline to fetch the taken path of the branch. --------cut end ----------------------------- For -mtune-ctrl=branch_prediction_hints, always generate branch hint for conditional branches, this tune is disabled by default. [1] https://www.intel.com/content/www/us/en/content-details/821612/intel-64-and-ia-32-architectures-optimization-reference-manual-volume-1.html Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ready push to trunk. gcc/ * config/i386/i386.cc (ix86_print_operand): Always generate branch hint for conditional branches. --- gcc/config/i386/i386.cc | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 1f71ed04be6..9992b9d6186 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -14050,25 +14050,11 @@ ix86_print_operand (FILE *file, rtx x, int code) int pred_val = profile_probability::from_reg_br_prob_note (XINT (x, 0)).to_reg_br_prob_base (); - if (pred_val < REG_BR_PROB_BASE * 45 / 100 - || pred_val > REG_BR_PROB_BASE * 55 / 100) - { - bool taken = pred_val > REG_BR_PROB_BASE / 2; - bool cputaken - = final_forward_branch_p (current_output_insn) == 0; - - /* Emit hints only in the case default branch prediction - heuristics would fail. */ - if (taken != cputaken) - { - /* We use 3e (DS) prefix for taken branches and - 2e (CS) prefix for not taken branches. */ - if (taken) - fputs ("ds ; ", file); - else - fputs ("cs ; ", file); - } - } + bool taken = pred_val > REG_BR_PROB_BASE / 2; + /* We use 3e (DS) prefix for taken branches and + 2e (CS) prefix for not taken branches. */ + if (taken) + fputs ("ds ; ", file); } return; }