From patchwork Mon Jan 29 21:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 193715 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp852754dyb; Mon, 29 Jan 2024 13:56:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOE60kfzcfs8SGE94TQDJb3XSyCntsdqvnY4fLzz9FxbWIG4fZujJILujRcBYT1O7niNQs X-Received: by 2002:a05:6214:d0f:b0:68c:4167:fc5e with SMTP id 15-20020a0562140d0f00b0068c4167fc5emr5463406qvh.32.1706565368881; Mon, 29 Jan 2024 13:56:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706565368; cv=pass; d=google.com; s=arc-20160816; b=ypiyCi7F4sh+ej/Bb0HYvPln81PDXMnf5vdeL4VRQq1BQwjqEWUMKeBUgAHwpN43RC k6yS56+reUXlthkX31TE5pUNLEoEi28mXzYl4UiMa6Q1hL1GTWFKLQxrh4T8alfBRjNS 4jD+h3vsBrTAlxyu+fY376ub+PLn5opd3b+7HxPcnwkODg7MqN9mySpiNIH9jjZ1xmi9 W4ovKdEKakEKDh312NKGsmHHai9YhN7JCcZn8s0ScxtTneW0fy5+D7j8LfUH1pzWHLJu IUNQ7qsoge2GHrPWJSHwk5+/EV2WEgzVqzBN9sI8LoJ0/OEbJ0BDFYzkD0AnGJZiPoha gneQ== 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=c+23nznv2y8ggUgf6jdiIezRGeu9xfnPTL6ILpuSiX0=; fh=K4AS3pFR26BR8zOf4IwrZlUeM0YSSQqO68Rjh5vfBKs=; b=LW1+i/amXJh6oH2tNG+6L8BUrnkPoPcHDND1kgECBki3sTnnQcF087eTBV2Q+k7I9i pGrxFm1MnP0pPigc5LXHYG12uJnwpxpjL5JlTVfidg0TZlJiRP/Q++61PPW7f5d7FmE9 2njFG7cuMjgvZpesFDjvncrK8DOLC1Kd4laKHkkA6ccbJjtJ93woCkRWFIIHsdqbo0O4 9YMTr35VtsYxACa2EUhSP/W6QwZaeiMKR2M/I9mtgBspB+DYCwCij36060gkLNgW0xoq nhKGAjtuQKRG6Pwml92KjeTzZqR18+ZYDqh9MzJtvtRU9P924jjkYoJ0QyqaLhDlwIg4 u5QQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PqTKwUKK; 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 kl21-20020a056214519500b0068534b052desi8661093qvb.288.2024.01.29.13.56.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 13:56:08 -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=PqTKwUKK; 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 910353858435 for ; Mon, 29 Jan 2024 21:56:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id E0D8B3858437 for ; Mon, 29 Jan 2024 21:55:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0D8B3858437 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 E0D8B3858437 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706565324; cv=none; b=uGEckzldO9tYsT7UF7O0tRHaAOIUzxrLti1O4B0BhJrKV7jfvRSS5vStM7crKGRE902Crql6j2Q+h658qzEk4402WJZ54Id3GA1qtRRqMdSn8rq+ECvuA/D4aRBf08Kh+IBHhjbbcQkfM4hGOm3D8ISQPfWn5QL0XE+BKfIjqnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706565324; c=relaxed/simple; bh=YHph7eB5lPj/cDkBxNsI5j5jD25be52xKAvMtcRqup0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fnwUsGT86nfEyeF3iwqqwlHOqcYuVXQQLdMs8vIVfh3Lg3OeO3Dpf51IZcYZ0ayJoFp8wVTdZjAZbZPQI3KWgJ9mTW3oHbeH1Cw9rJ7J9GDmjRQpFUpL9hhPzQW9bjcNv4UigjLkZphsvEL2ML13VHG9kPG5tJZxo8ThV6tB1KQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d73066880eso26608575ad.3 for ; Mon, 29 Jan 2024 13:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706565320; x=1707170120; 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=c+23nznv2y8ggUgf6jdiIezRGeu9xfnPTL6ILpuSiX0=; b=PqTKwUKKNdowVTTIb/RxvdaSxjusKj/H/kV5E65GaqVyKiNRJ36G2kU/mYdxF3VjlM J4J2/lhCRfwk0Ux003FJ8tGMaR+9r//FMtx2U5IN7ZY94QVcZH7In5iNUIZtvX7RTIZZ ZfOc8MX6heE8EJrl5jevIIgaqe5Evg6UifdIGQAx29QIHCHhOpl6IDG10xCinDEX1Cip DT01v7ehXUmE15NFW9DsDJ6gkhd0W+V3UuNSdxE+9V4Oz6ivjDmLhYm3HaUBHEZaBOf9 0+0zQSAVnVlX3e15IX6LDjPCeVcyQhHnf40Wx4SWwg9dL1tEuHqOcz4Ng3+d0gbctgcp e5Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706565320; x=1707170120; 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=c+23nznv2y8ggUgf6jdiIezRGeu9xfnPTL6ILpuSiX0=; b=CcFCsFAUseFxQbW6EqjFXoFj7ezOz3LJRHuvXcepQtZHy4CgRo7mB3BCY3yO+IVC2T PrgUheOEoTl4b8XjqUQBPiVR6SW94yKjPx58Z+VdsH6789+bEqrCuZcYmLGJWcqMKcYd IdMfCJ9/RH5ZU+H0fkYBBNUTswzZdt7iUul5KxA+5ZCVc+1btiz/QaNOQj29/knQ+Plk n6pJr+aoGkdhZeQKYauUq4GHPQDjxC/zfVnwBJLya0rFBq1+dDUpRwveJk9c9qNZpICY jSb2Jo1Ap89Pm0JZ+ztWhJDjw5D3MMraQIKLQFWzTSOJAMv1vwQ7nUAJ8mF5R3w5kNdo mu2w== X-Gm-Message-State: AOJu0Yz8I8IMqz2eyUw2r9iPY/7npA1mQpsdRScoKaTdyMRU/vzLYkqM 5LnRYGEif4zPSrcxTJYSzhJYN14DVOi5bXYWbRJ/nH+X2G/vo/WbEmD/WGgT X-Received: by 2002:a17:903:644:b0:1d8:a697:b995 with SMTP id kh4-20020a170903064400b001d8a697b995mr5455384plb.27.1706565320539; Mon, 29 Jan 2024 13:55:20 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.51]) by smtp.gmail.com with ESMTPSA id jh12-20020a170903328c00b001d8e6f59890sm2051804plb.46.2024.01.29.13.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 13:55:20 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id D1A7E7402F3; Mon, 29 Jan 2024 13:55:18 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com Subject: [PATCH v3] x86: Generate REG_CFA_UNDEFINED for unsaved callee-saved registers Date: Mon, 29 Jan 2024 13:55:18 -0800 Message-ID: <20240129215518.605038-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3023.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789441186072550200 X-GMAIL-MSGID: 1789463488420822601 Changes in v3: 1. Fix a typo in REG_CFA_UNDEFINED note comment. 2. Replace assemble with compile in tests and remove -save-temps since ".cfi_undefined regno" is generated now. Changes in v2: 1. Add REG_CFA_UNDEFINED notes to a frame-related instruction in prologue. 2. Add comments for add_cfi_undefined. --- Attach REG_CFA_UNDEFINED notes for unsaved callee-saved registers which have been used in the function to a frame-related instruction in prologue. gcc/ PR target/38534 * dwarf2cfi.cc (add_cfi_undefined): New. (dwarf2out_frame_debug_cfa_undefined): Likewise. (dwarf2out_frame_debug): Handle REG_CFA_UNDEFINED. * reg-notes.def (REG_CFA_UNDEFINED): New. * config/i386/i386.cc (ix86_expand_prologue): Attach REG_CFA_UNDEFINED notes for unsaved callee-saved registers which have been used in the function to a frame-related instruction in prologue. gcc/testsuite/ PR target/38534 * gcc.target/i386/no-callee-saved-19.c: New test. * gcc.target/i386/no-callee-saved-20.c: Likewise. * gcc.target/i386/pr38534-7.c: Likewise. * gcc.target/i386/pr38534-8.c: Likewise. --- gcc/config/i386/i386.cc | 29 ++++++++++ gcc/dwarf2cfi.cc | 58 +++++++++++++++++++ gcc/reg-notes.def | 4 ++ .../gcc.target/i386/no-callee-saved-19.c | 17 ++++++ .../gcc.target/i386/no-callee-saved-20.c | 12 ++++ gcc/testsuite/gcc.target/i386/pr38534-7.c | 18 ++++++ gcc/testsuite/gcc.target/i386/pr38534-8.c | 13 +++++ 7 files changed, 151 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-19.c create mode 100644 gcc/testsuite/gcc.target/i386/no-callee-saved-20.c create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-7.c create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-8.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index b3e7c74846e..4b7026f3ab4 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -9304,6 +9304,35 @@ ix86_expand_prologue (void) combined with prologue modifications. */ if (TARGET_SEH) emit_insn (gen_prologue_use (stack_pointer_rtx)); + + if (cfun->machine->call_saved_registers + != TYPE_NO_CALLEE_SAVED_REGISTERS) + return; + + /* Attach REG_CFA_UNDEFINED notes for unsaved callee-saved registers + which have been used in the function to a frame-related instruction + in prologue. */ + + insn = nullptr; + rtx_insn *next; + for (next = get_insns (); next; next = NEXT_INSN (next)) + { + if (!RTX_FRAME_RELATED_P (next)) + continue; + insn = next; + } + + if (!insn) + return; + + for (int i = 0; i < FIRST_PSEUDO_REGISTER; i++) + if (df_regs_ever_live_p (i) + && !fixed_regs[i] + && !call_used_regs[i] + && !STACK_REGNO_P (i) + && !MMX_REGNO_P (i)) + add_reg_note (insn, REG_CFA_UNDEFINED, + gen_rtx_REG (word_mode, i)); } /* Emit code to restore REG using a POP or POPP insn. */ diff --git a/gcc/dwarf2cfi.cc b/gcc/dwarf2cfi.cc index 1231b5bb5f0..9ba0ac07ee7 100644 --- a/gcc/dwarf2cfi.cc +++ b/gcc/dwarf2cfi.cc @@ -517,6 +517,20 @@ add_cfi_restore (unsigned reg) add_cfi (cfi); } +/* Add DW_CFA_undefined either to the current insn stream or to a vector, + or both. */ + +static void +add_cfi_undefined (unsigned reg) +{ + dw_cfi_ref cfi = new_cfi (); + + cfi->dw_cfi_opc = DW_CFA_undefined; + cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; + + add_cfi (cfi); +} + /* Perform ROW->REG_SAVE[COLUMN] = CFI. CFI may be null, indicating that the register column is no longer saved. */ @@ -1532,6 +1546,37 @@ dwarf2out_frame_debug_cfa_restore (rtx reg, bool emit_cfi) } } +/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_UNDEFINED + note. */ + +static void +dwarf2out_frame_debug_cfa_undefined (rtx reg) +{ + gcc_assert (REG_P (reg)); + + rtx span = targetm.dwarf_register_span (reg); + if (!span) + { + unsigned int regno = dwf_regno (reg); + add_cfi_undefined (regno); + } + else + { + /* We have a PARALLEL describing where the contents of REG live. + Restore the register for each piece of the PARALLEL. */ + gcc_assert (GET_CODE (span) == PARALLEL); + + const int par_len = XVECLEN (span, 0); + for (int par_index = 0; par_index < par_len; par_index++) + { + reg = XVECEXP (span, 0, par_index); + gcc_assert (REG_P (reg)); + unsigned int regno = dwf_regno (reg); + add_cfi_undefined (regno); + } + } +} + /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE. ??? Perhaps we should note in the CIE where windows are saved (instead @@ -2326,6 +2371,19 @@ dwarf2out_frame_debug (rtx_insn *insn) handled_one = true; break; + case REG_CFA_UNDEFINED: + n = XEXP (note, 0); + if (n == nullptr) + { + n = PATTERN (insn); + if (GET_CODE (n) == PARALLEL) + n = XVECEXP (n, 0, 0); + n = XEXP (n, 0); + } + dwarf2out_frame_debug_cfa_undefined (n); + handled_one = true; + break; + case REG_CFA_SET_VDRAP: n = XEXP (note, 0); if (REG_P (n)) diff --git a/gcc/reg-notes.def b/gcc/reg-notes.def index 5b878fb2a1c..5bd73c5fdcf 100644 --- a/gcc/reg-notes.def +++ b/gcc/reg-notes.def @@ -152,6 +152,10 @@ REG_CFA_NOTE (CFA_EXPRESSION) the given register. */ REG_CFA_NOTE (CFA_VAL_EXPRESSION) +/* Attached to insns that are RTX_FRAME_RELATED_P, to specify a register + with undefined value. */ +REG_CFA_NOTE (CFA_UNDEFINED) + /* Attached to insns that are RTX_FRAME_RELATED_P, with the information that this is a restore operation, i.e. will result in DW_CFA_restore or the like. Either the attached rtx, or the destination of the insn's diff --git a/gcc/testsuite/gcc.target/i386/no-callee-saved-19.c b/gcc/testsuite/gcc.target/i386/no-callee-saved-19.c new file mode 100644 index 00000000000..9b3de73d04d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-19.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target *-*-linux* *-*-gnu* } } */ +/* { dg-options "-march=tigerlake -O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move" } */ + +#include "no-callee-saved-1.c" + +/* { dg-final { scan-assembler-not "push" } } */ +/* { dg-final { scan-assembler-not "pop" } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 3" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 6" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 12" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 13" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 14" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 15" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 3" 1 { target ia32 } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 5" 1 { target ia32 } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 6" 1 { target ia32 } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 7" 1 { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/no-callee-saved-20.c b/gcc/testsuite/gcc.target/i386/no-callee-saved-20.c new file mode 100644 index 00000000000..fc94778824a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-20.c @@ -0,0 +1,12 @@ +/* { dg-do compile { target cfi } } */ +/* { dg-options "-march=tigerlake -O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move" } */ + +__attribute__ ((no_callee_saved_registers)) +void +foo (void) +{ +} + +/* { dg-final { scan-assembler-not "push" } } */ +/* { dg-final { scan-assembler-not "pop" } } */ +/* { dg-final { scan-assembler-not ".cfi_undefined" } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr38534-7.c b/gcc/testsuite/gcc.target/i386/pr38534-7.c new file mode 100644 index 00000000000..e6406bc4e71 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr38534-7.c @@ -0,0 +1,18 @@ +/* { dg-do compile { target *-*-linux* *-*-gnu* } } */ +/* { dg-options "-march=tigerlake -O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move" } */ + +#include "pr38534-1.c" + +/* { dg-final { scan-assembler-not "push" } } */ +/* { dg-final { scan-assembler-not "pop" } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 3" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 6" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 12" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 13" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 14" 1 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 15" 1 { target lp64 } } } */ +/* { dg-final { scan-assembler-not ".cfi_undefined 15" { target x32 } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 3" 1 { target ia32 } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 5" 1 { target ia32 } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 6" 1 { target ia32 } } } */ +/* { dg-final { scan-assembler-times ".cfi_undefined 7" 1 { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr38534-8.c b/gcc/testsuite/gcc.target/i386/pr38534-8.c new file mode 100644 index 00000000000..020c1512db1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr38534-8.c @@ -0,0 +1,13 @@ +/* { dg-do compile { target cfi } } */ +/* { dg-options "-march=tigerlake -O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move" } */ + +void +__attribute__((noreturn)) +no_return_to_caller (void) +{ + while (1); +} + +/* { dg-final { scan-assembler-not "push" } } */ +/* { dg-final { scan-assembler-not "pop" } } */ +/* { dg-final { scan-assembler-not ".cfi_undefined" } } */