From patchwork Tue Jul 7 21:44:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 138692 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7917E4BA23DB for ; Tue, 7 Jul 2026 21:46:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7917E4BA23DB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=RltBh49k X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 7275E4BA2E1C for ; Tue, 7 Jul 2026 21:45:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7275E4BA2E1C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7275E4BA2E1C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783460709; cv=none; b=V+RE1wyMcZHI7DerSytKRAzTeODMHYhGFiZlFWr01Ga8iN8T4fkKGZZJVZayc1I9Wk3LyPJKfsy5HgdaOwzDKO6nlVHGqRmPNxl0e2Vq71V66uqX3TTnnvB9s++dqK922wMmynKnQBQgII4JglAllDQByxQoWLvuUVO99tS+zLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783460709; c=relaxed/simple; bh=WqqmXmwa1Ft04Rbl6D42P7VD/0z/xBOxOdmqy+harX0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l12vZueQymSIPLNRWIesHjSgJXqUNDsKAY6zRq+w7jGQ1PFhHj7LJNJM6UGQOtrS/KDQaK/KJ+Cr5wf/KMraP2+tcOETthKIfF9LJI0zvK0avbDip3j5KiILwK3JKzxVWbEw+f9qCiDM2WUZtaFRLwe6WpJ4zFcvuk4b08ojf7k= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=RltBh49k DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7275E4BA2E1C Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-845f2909cd4so1706b3a.1 for ; Tue, 07 Jul 2026 14:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783460708; x=1784065508; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AQ0o5vaUuAVB+6R0/XlXDVeLLa01ARxSh4d3h+DPAv4=; b=RltBh49kyc/PEOU3fRy/ZyWWLrOLFu5dw+Sg2SJGjBC+3ZzjaiJRDx5ajFRztoRtwk zyXavBpMNNm3Mn0uo6BVes/xYgTDPO6X8ftcyVFtZ7tvllcfuYatYOcdfvU2peKc1UHC 3zZdTMttA4hmmqJIWZLUvgYVNXG+VJ/oNL81Gz2tc6I1BGAMQDeKv4hty8Nc6ovUqykp YpAgFDQaa/OrGqV1CwHPtk8cVK7lXzR+nX3wVIUwR5JedxkQKjD29uB9rc9U9wTC/C2f Zwz5IlPrP/YbHCU9Fy5rXkSikxyckOXvxZlcKg3dRs+63m+De3SBvtSOUpGadkncy+3F AA1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783460708; x=1784065508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AQ0o5vaUuAVB+6R0/XlXDVeLLa01ARxSh4d3h+DPAv4=; b=hUUVGN+CRpsLl4plsaW56vjFfArhy4i7sMp+tkUf58PIy2BgWye+Rvz0NMkC0cBfoj LaQBr+1X5lsxSLHla5P7V4xY92mc/o/+zgqiYzH6Lqs5xgyYYjYByjScZbynJh9Cd0QW B8FcPvP4IHM9zLlYNIlD3P5tahBKW+Ro1QETyGVC0bCV97toAcdKrGVlZwk67jL8KTut 9brZ+94J2dCdIIDgEpyntmik2r0q2NOTaSDd5+l2kBleovmu9zdVPZNZ+M+JGGbQ+ojK XVYNB89N+MVm0ICZy+75ffBrgp3UvVWb9deW8J083Xmu5SmYOsTH9uDdiukzzZw9td8a Iv+w== X-Gm-Message-State: AOJu0Yzzl4ranw+3CY9hOCVFEOFzJPCMnzyMAXzi/k56UexFnJLhZULw XRNKESD6VOQYl0en1KihnLQbn6J6HljFfhYnWD5PM+QUu0oKdPa1U3W/FnfgSmxge3M= X-Gm-Gg: AfdE7cld/wI7vQ0l51xtPmLO6zC98BTulYxRexXGxBY/mh4l7x8r94k6GmHi8/zkFbv wx7CKP0hsjd6T8Ea0ksQXGSHfrQH8MwQ0wNwSer5F+tDiotWZE6Hx9v+2MG3fGuP3fw8/gWHYC5 ZcKZ+L62mcjfR2YF7NzRqyhJb0uSjt5yv5qz9U7PyfTMn4pTWVkqHRLD1jVElzHeaJ3wQbuwRjR 54xdS7W3J/uRDWs5IS7XB0QuM4DZc4y3CFFtcrUaC1F8IrWhrs3j2bAC3JOkpP5pMnpV9gj8kGq byXMkaQs20+S+oxFMxQnVOKaVFClp1wU26FgIQrsgNOrG8iBtv4yRfdtcSsiQJp0BS6D2a6AKmf Zf38H2NV3qYJ+uEa+3w6qc2f5FkRF0xfBJ5qB0YAM4hKZxWlKe+6Dy//ZRocbAO6lI9f96Mlc4Z F+VzdJ3hZv42XnojqII8wsxZaNuXwd9jJJzxvSCjkbw5z1Eit6GYeSmyNwqg== X-Received: by 2002:a05:6a21:6e46:b0:39b:d937:8020 with SMTP id adf61e73a8af0-3c08eed0254mr7446767637.42.1783460708371; Tue, 07 Jul 2026 14:45:08 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.56.176.93]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13b6596681fsm13585003c88.8.2026.07.07.14.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 14:45:07 -0700 (PDT) Received: from gnu-tgl-3.localdomain (localhost [127.0.0.1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 66640C1D9A; Wed, 08 Jul 2026 05:45:04 +0800 (CST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: rdsandiford@googlemail.com, ubizjak@gmail.com, hongtao.liu@intel.com Subject: [PATCH v4 2/4] i386: Avoid reading call_used_regs Date: Wed, 8 Jul 2026 05:44:55 +0800 Message-ID: <20260707214457.1628003-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260707214457.1628003-1-hjl.tools@gmail.com> References: <20260707214457.1628003-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3009.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, RCVD_IN_XBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org From: Richard Sandiford call_used_regs is a legacy interface that targets use to tell init_reg_sets_1 about the default (system) ABI. In x86 terms, that means the ABI associated with ix86_abi. Targets can continue to read call_used_regs directly if they don't have multiple ABIs. But now that x86 does, it's better to be explicit about which ABI is being queried. This is currently a nop but becomes important with the upcoming function_abi patch. As the comment in ix86_emit_tls_call says: /* TLS_GD and TLS_LD_BASE instructions are normal functions which clobber caller-saved registers. [...] So that function really is querying the system ABI. Similarly, x86_order_regs_for_local_alloc is called when initialising a target, rather than once per function, so it too should query the system ABI. ix86_save_reg and x86_64_select_profile_regnum ask about the current function's ABI, which is crtl->abi. gcc/ * config/i386/i386-features.cc: Include function-abi.h. (ix86_emit_tls_call): Use default_function_abi instead of call_used_regs. * config/i386/i386.cc (x86_order_regs_for_local_alloc): Likewise. (ix86_save_reg, x86_64_select_profile_regnum): Use crtl->abi instead of call_used_regs. --- gcc/config/i386/i386-features.cc | 3 ++- gcc/config/i386/i386.cc | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index 633bee18731..164db2538a6 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -91,6 +91,7 @@ along with GCC; see the file COPYING3. If not see #include "debug.h" #include "dwarf2out.h" #include "cfgcleanup.h" +#include "function-abi.h" #include "i386-builtins.h" #include "i386-features.h" #include "i386-expand.h" @@ -4350,7 +4351,7 @@ ix86_emit_tls_call (rtx tls_set, x86_cse_kind kind, basic_block bb, instructions. */ if (kind != X86_CSE_TLSDESC) for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) - if (call_used_regs[i] + if (default_function_abi.clobbers_full_reg_p (i) && !fixed_regs[i] && bitmap_bit_p (in, i)) bitmap_set_bit (live_caller_saved_regs, i); diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index d8a4df3a668..acb8d2db99f 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -6883,7 +6883,8 @@ ix86_save_reg (unsigned int regno, bool maybe_eh_return, bool ignore_outlined) } return (df_regs_ever_live_p (regno) - && !call_used_or_fixed_reg_p (regno) + && !fixed_regs[regno] + && !crtl->abi->clobbers_full_reg_p (regno) && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed)); } @@ -23549,13 +23550,13 @@ x86_order_regs_for_local_alloc (void) /* First allocate the local general purpose registers. */ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) - if (GENERAL_REGNO_P (i) && call_used_or_fixed_reg_p (i)) - reg_alloc_order [pos++] = i; + if (GENERAL_REGNO_P (i) && default_function_abi.clobbers_full_reg_p (i)) + reg_alloc_order [pos++] = i; /* Global general purpose registers. */ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) - if (GENERAL_REGNO_P (i) && !call_used_or_fixed_reg_p (i)) - reg_alloc_order [pos++] = i; + if (GENERAL_REGNO_P (i) && !default_function_abi.clobbers_full_reg_p (i)) + reg_alloc_order [pos++] = i; /* x87 registers come first in case we are doing FP math using them. */ @@ -24017,7 +24018,7 @@ x86_64_select_profile_regnum (bool r11_ok ATTRIBUTE_UNUSED) #endif && TEST_HARD_REG_BIT (accessible_reg_set, i) && (ix86_save_reg (i, true, true) - || (call_used_regs[i] + || (crtl->abi->clobbers_full_reg_p (i) && !fixed_regs[i] && !REGNO_REG_SET_P (reg_live, i)))) return i;