Message ID | 20240120142752.1387725-1-hjl.tools@gmail.com |
---|---|
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1643304dyb; Sat, 20 Jan 2024 06:28:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEprJbHpanNs5dBwGfUycTJ+nnvzA31BeWiUuQAUxWBFfpe7O5APlRUaxFyDp8KOwVEMxDF X-Received: by 2002:a05:6214:5299:b0:686:49cf:e648 with SMTP id kj25-20020a056214529900b0068649cfe648mr240409qvb.79.1705760934377; Sat, 20 Jan 2024 06:28:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705760934; cv=pass; d=google.com; s=arc-20160816; b=JkB1B+rc42zDyMRo3Fx4tLtkn9AFulQMkWKcFIHQ0hcumwVXYDqfS1+nw5P4iAj/Ma GZdk7m7VL2/M5Ary2cVCXxsZG5dwjX/X+vNdmbOh2Xqd/UWygFomXaSX6PqpbYpwGjgX OkQdpGzYlCtXdbGu9UrCYv3+Ql4i1PWxcDEAhxXOG2YxWUedqrPhfMfX+YM92mPfed4/ RuDdVkzBwK3AQWH4g93Nca8YPByd6d2wE5DgAgfUIVic2WbjDUT3JzXkiLgprLEa+v9M L5JIFK192EG+EqtLRiqN/rq87MTzccnryX0EOj9YICtSI3dCAl4x4/uZdPf6Om5ymgKI LJ4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=nLHc7RMXPqEqqmp5K3hUN3EzaJzJxP0/y/ENR/Lqh1E=; fh=DkbU5qKJ1pwscM07d9qZ8pO3cz62HhAUS2BaFSQ0JHM=; b=sz46ySIZvVu4cd/kli3MqnOH2MBJMJT2cQoTnVG/kjMgc7gzpYYOyhdLqyc5j6pYHi H559cKQhnHEAxpQ4PdUyRt+a5ClR8PsZLGAYbjE5Z9sBhbyjZn55WddKgi0hN0z2Mar/ GfYS1iES+TLsKfmhyk1guqaM09QTCXols2LywObWoSL29nqqeHr9FM3YBckLLodiM5e4 p4SKZVCI5wBSU/1rVO8CioqbgP3aRM3ohCv5c41M9s7MuGC1FbLM4mLt7v+5dqTuo4yJ 3ADQGFlBrSwUPoqPVeiNvvCMRurcQkb2ROqx91Hbgzp5AvcjoYCNqAkIjoTIfP3J94VH l7rA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YAGww4Fc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v6-20020a0c9c06000000b0067f60ad441bsi1605540qve.88.2024.01.20.06.28.54 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 06:28:54 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YAGww4Fc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C0F53858284 for <ouuuleilei@gmail.com>; Sat, 20 Jan 2024 14:28:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 79BD33858D39 for <gcc-patches@gcc.gnu.org>; Sat, 20 Jan 2024 14:27:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79BD33858D39 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 79BD33858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705760879; cv=none; b=J8XAj0HqfOVDQZD8awfx8vNyNAIqnpwja4tMT/jgxPDi4zw0xpL4EmACMrt0dXWnwPCH3d5zm/FzCkxpVXvbQ42yk7aVwF1zQPLs77B4+/J5XgMZldv/Snfo/u5799xBLwZ+3Awo9JtvFVgvuhSHIMIfJPoLRhf9Vrx2gpGSUDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705760879; c=relaxed/simple; bh=kWtcMIMxlroOC7J8kqe2sTE9XHgmExnZfhoUmmvOA7g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Uxm27qfVI4+Unnufp8inyFIhvs2UQ453/BvoaKvMk55+j+9paCq0SrXKxi/g/VSAVs71LvPc/x/tz1Yy8YEs2In7cycK/d4FPG/YONQfvUk4nJVlTLk1grE0GSuZ8VuDXuAY+7lm9tOgbfgX+ZQOrxhV8yoNbiNBMWcEoJeK3TQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso1292702a12.3 for <gcc-patches@gcc.gnu.org>; Sat, 20 Jan 2024 06:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705760875; x=1706365675; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nLHc7RMXPqEqqmp5K3hUN3EzaJzJxP0/y/ENR/Lqh1E=; b=YAGww4Fc+8DiUaSuV+wz8hNMvcKcMV1BvrElEorWnC5EbrOxvlWVt+e5CIH8W7AGYJ hdw9QlRx7AXAhHBRzHi5WMLK2BUy3KrUgxtVzZtRbQ1/J+6lmK1uE2fnfFeOcvXMXCbE ZX9ywfB2pIDWjaFkPTiKauCrpIu5gfuqsf7IWufIbiZeNznUXc+TzRF/3savTy4umvHO h7Y7SP4A+e+1+tbH6fUHG95S5JTsE8ooWYiqP11Z1RV+VXMAfvU/O2/+DN6dymn2Faa/ boYom+ND6h3ahigXQRsSrKgC2RrRVCSps3sayj9KTWmT3RkTqLJ3ZGS/TzhOaErnCaDw jSsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705760875; x=1706365675; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nLHc7RMXPqEqqmp5K3hUN3EzaJzJxP0/y/ENR/Lqh1E=; b=dTtWV7kTXrG1en3552H7oxdCILh1S8zKsG738g+nj9s2y/GSDBDkVDHGLXI+TcCUt6 PTQHmMDdoEgXf40JQT7CoML3ULSck0bYFTUhKrBN5sAJIWpY83COcw4Cg/epYdvzfv1s LzKaKbjsSQsXjG4x1v/qQjpbKlIl53qcN2SPylLNRhQ5+J5h8msr2LCGEV3REmUfM8bz +wcuzzMlAuK09G4iiVpnJHInhsrzH1dAmZOgl9QpmsxMAaxvQUqkVr7mHKGENkUVkmcZ oLb6GqDqRjFM8HG4r/MsiDeflm1nuAoczT2iiAj1QegVxdk+Lf2VbcII3DPEHixVnNLi Xa6w== X-Gm-Message-State: AOJu0Ywdw9ABKD+JbxlkHbjaHcqXMQ6fICdNeC8/w6PhJSO2yVSPnQSo zHEcnQkEMGkjmsFemsLctSuNgjHJXsIkmfuiT1WF6JlxdBn8lazDnldEBCZ4 X-Received: by 2002:a17:903:41cf:b0:1d7:3131:4dde with SMTP id u15-20020a17090341cf00b001d731314ddemr1227720ple.116.1705760875052; Sat, 20 Jan 2024 06:27:55 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.168.9]) by smtp.gmail.com with ESMTPSA id u2-20020a17090341c200b001d4593a2e8fsm4612577ple.83.2024.01.20.06.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 06:27:54 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id D23167402E2; Sat, 20 Jan 2024 06:27:52 -0800 (PST) From: "H.J. Lu" <hjl.tools@gmail.com> To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com, hongtao.liu@intel.com, jh@suse.cz Subject: [PATCH 0/2] x86: Don't save callee-saved registers if not needed Date: Sat, 20 Jan 2024 06:27:50 -0800 Message-ID: <20240120142752.1387725-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3018.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788619977331718661 X-GMAIL-MSGID: 1788619977331718661 |
Series |
x86: Don't save callee-saved registers if not needed
|
|
Message
H.J. Lu
Jan. 20, 2024, 2:27 p.m. UTC
In some cases, there are no need to save callee-saved registers: 1. If a noreturn function doesn't throw nor support exceptions, it can skip saving callee-saved registers. 2. When an interrupt handler is implemented by an assembly stub which does: 1. Save all registers. 2. Call a C function. 3. Restore all registers. 4. Return from interrupt. it is completely unnecessary to save and restore any registers in the C function called by the assembly stub, even if they would normally be callee-saved. This patch set adds no_callee_saved_registers function attribute, which is complementary to no_caller_saved_registers function attribute, to classify x86 backend call-saved register handling type with 1. Default call-saved registers. 2. No caller-saved registers with no_caller_saved_registers attribute. 3. No callee-saved registers with no_callee_saved_registers attribute. Functions of no callee-saved registers won't save callee-saved registers. If a noreturn function doesn't throw nor support exceptions, it is classified as the no callee-saved registers type. With these changes, __libc_start_main in glibc 2.39, which is a noreturn function, is changed from __libc_start_main: endbr64 push %r15 push %r14 mov %rcx,%r14 push %r13 push %r12 push %rbp mov %esi,%ebp push %rbx mov %rdx,%rbx sub $0x28,%rsp mov %rdi,(%rsp) mov %fs:0x28,%rax mov %rax,0x18(%rsp) xor %eax,%eax test %r9,%r9 to __libc_start_main: endbr64 sub $0x28,%rsp mov %esi,%ebp mov %rdx,%rbx mov %rcx,%r14 mov %rdi,(%rsp) mov %fs:0x28,%rax mov %rax,0x18(%rsp) xor %eax,%eax test %r9,%r9 In Linux kernel 6.7.0 on x86-64, do_exit is changed from do_exit: endbr64 call <do_exit+0x9> push %r15 push %r14 push %r13 push %r12 mov %rdi,%r12 push %rbp push %rbx mov %gs:0x0,%rbx sub $0x28,%rsp mov %gs:0x28,%rax mov %rax,0x20(%rsp) xor %eax,%eax call *0x0(%rip) # <do_exit+0x39> test $0x2,%ah je <do_exit+0x8d3> to do_exit: endbr64 call <do_exit+0x9> sub $0x28,%rsp mov %rdi,%r12 mov %gs:0x28,%rax mov %rax,0x20(%rsp) xor %eax,%eax mov %gs:0x0,%rbx call *0x0(%rip) # <do_exit+0x2f> test $0x2,%ah je <do_exit+0x8c9> I compared GCC master branch bootstrap and test times on a slow machine with 6.6 Linux kernels compiled with the original GCC 13 and the GCC 13 with the backported patch. The performance data isn't precise since the measurements were done on different days with different GCC sources under different 6.6 kernel versions. GCC master branch build time in seconds: before after improvement 30043.75user 30013.16user 0% 1274.85system 1243.72system 2.4% GCC master branch test time in seconds (new tests added): before after improvement 216035.90user 216547.51user 0 27365.51system 26658.54system 2.6% Backported to GCC 13 to rebuild system glibc and kernel on Fedora 39. Systems perform normally. H.J. Lu (2): x86: Add no_callee_saved_registers function attribute x86: Don't save callee-saved registers in noreturn functions gcc/config/i386/i386-expand.cc | 72 ++++++++++++++++--- gcc/config/i386/i386-options.cc | 61 ++++++++++++---- gcc/config/i386/i386.cc | 70 ++++++++++++++---- gcc/config/i386/i386.h | 20 +++++- gcc/doc/extend.texi | 8 +++ .../gcc.dg/torture/no-callee-saved-run-1a.c | 23 ++++++ .../gcc.dg/torture/no-callee-saved-run-1b.c | 59 +++++++++++++++ .../gcc.target/i386/no-callee-saved-1.c | 30 ++++++++ .../gcc.target/i386/no-callee-saved-10.c | 46 ++++++++++++ .../gcc.target/i386/no-callee-saved-11.c | 11 +++ .../gcc.target/i386/no-callee-saved-12.c | 10 +++ .../gcc.target/i386/no-callee-saved-13.c | 16 +++++ .../gcc.target/i386/no-callee-saved-14.c | 16 +++++ .../gcc.target/i386/no-callee-saved-15.c | 17 +++++ .../gcc.target/i386/no-callee-saved-16.c | 16 +++++ .../gcc.target/i386/no-callee-saved-17.c | 16 +++++ .../gcc.target/i386/no-callee-saved-18.c | 51 +++++++++++++ .../gcc.target/i386/no-callee-saved-2.c | 30 ++++++++ .../gcc.target/i386/no-callee-saved-3.c | 8 +++ .../gcc.target/i386/no-callee-saved-4.c | 8 +++ .../gcc.target/i386/no-callee-saved-5.c | 11 +++ .../gcc.target/i386/no-callee-saved-6.c | 12 ++++ .../gcc.target/i386/no-callee-saved-7.c | 49 +++++++++++++ .../gcc.target/i386/no-callee-saved-8.c | 50 +++++++++++++ .../gcc.target/i386/no-callee-saved-9.c | 49 +++++++++++++ gcc/testsuite/gcc.target/i386/pr38534-1.c | 26 +++++++ gcc/testsuite/gcc.target/i386/pr38534-2.c | 18 +++++ gcc/testsuite/gcc.target/i386/pr38534-3.c | 19 +++++ gcc/testsuite/gcc.target/i386/pr38534-4.c | 18 +++++ .../gcc.target/i386/stack-check-17.c | 19 ++--- 30 files changed, 809 insertions(+), 50 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/no-callee-saved-run-1a.c create mode 100644 gcc/testsuite/gcc.dg/torture/no-callee-saved-run-1b.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-1.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-10.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-11.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-12.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-13.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-14.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-15.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-16.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-17.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-18.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-2.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-3.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-4.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-5.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-6.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-7.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-8.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-9.c create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-4.c