From patchwork Mon Jan 29 20:00:51 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: 193691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp800628dyb; Mon, 29 Jan 2024 12:01:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcGzCF0TwEifitGcljSM8HqPEFhO+of0beumjoc4sVB364dlMup+q2i9MrbdYyMRvthZC2 X-Received: by 2002:a05:622a:1805:b0:42a:a2f7:1de9 with SMTP id t5-20020a05622a180500b0042aa2f71de9mr3575451qtc.119.1706558495837; Mon, 29 Jan 2024 12:01:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706558495; cv=pass; d=google.com; s=arc-20160816; b=nwmY0HCOfMiDeWeEjFnTizUXpCoX2/7c5HBabSiRkniMbcSo6jLtHoRfnb2lJDp37D QeRfGOoLQHBW2ZUH9dArxCXMySQKWP0ljoDG0ULJTpUAeeJ3KPTyjYQhWgdg7K0tA8Ba S1A3arkBO9YqahAt3HlS+ImdY7LV17Ygx4Ip9E1ZRd/wmqsi1LzbrQuTBBPYPSvvEddD 6/2x6iayhXcWR9vybgcZ6TL0eeF+m/EKCb+WcxgIvBMOEr/vROs7zg+YuC2uFB6gV9jP +IkkO7gIuTpkPAJazSN653p5zhKltUzquqc97hPQ722L8q6fRiFuM6YdKF3InhjuPX2l EHJg== 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=FZOIokXzjpngrmqwOyhUg05HTWtBvzei2jOUfSLMzLg=; fh=K4AS3pFR26BR8zOf4IwrZlUeM0YSSQqO68Rjh5vfBKs=; b=KbJETgBucaPZ4I5gXy8fDgyuNyzpWyTfUosUa5VenfkgN6bZXJFddIFRzb0vNMMTCU y+b1CZGyGd99Xx6X4G1H4S2S2owxcNprd6E6sBSp1I5dk4vZRCYH5nAHVOoz6drJFDDF 8naXVRrpiKmzO8rJkfiUyjILOcek6MxHc4dNRcn6W289cuJ2pPMiB7iP/1ZWKuqoq3qO JgZO3HdM4PqQKVcUbeTBcOYVD457YWXV0IjNj14lq6ZeC94A/xiNZyeedjRO4vyfRHBR UTR+NpKffsZVlbpcNVKQ7g9SKmOi83NWOVBMlu24q8oBCiRzs+GPt0eU9cCULfpxnyG5 fLdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mhaIr0p+; 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 x15-20020a05620a0b4f00b00783ab114827si8007488qkg.391.2024.01.29.12.01.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 12:01:35 -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=mhaIr0p+; 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 82EC83858298 for ; Mon, 29 Jan 2024 20:01:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id E83D83858D1E for ; Mon, 29 Jan 2024 20:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E83D83858D1E 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 E83D83858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1034 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706558458; cv=none; b=A3ZThWx0NjISBwItv/oONYZDQWZjJ06GZJ0tMpi2OPBXiz8bFRueMNszkrEgSVt2mjek+p7fqT8aT0PrGAKnpLq+LC1M0txBuW86YMgFqrUMGkAjq/4+wmiZ5rBSHEs0QfcFd9/VdUvTvXOssVw3RDAVKWyLiD8IgHzpk5gwmuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706558458; c=relaxed/simple; bh=uQtPpGiq2v6HE8IB07hwuu3Ue9/NEdjkU//i5O30xG8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PDYh/NS94BWnDKVtYrtDIAsE7N2rKI8xODb6L7Pmi0A67Hmd4eFbJuXAqiX8tJmyofGa3+3G8jJDMx73/N52Tb2P3j+r6GsWrvHh+CL7XelHuCMrEJy7XoQ8H4m978TxJze+/DdQXE7pSXoINEgzGUpz9SNbhKFUTzBBSWHPVuk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2909978624eso1670518a91.1 for ; Mon, 29 Jan 2024 12:00:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706558454; x=1707163254; 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=FZOIokXzjpngrmqwOyhUg05HTWtBvzei2jOUfSLMzLg=; b=mhaIr0p+sN/kUCbf3eE3b3H6NypurAJnpGWBrawI/Uvia8rj9dzY+H8oYvSf/aFaGP M6NgDmP8HB8Vgu6eOhrJn/qP7yRYOWOZx654t6z9cFoaTXA1InhLIE6HI8oOSL/ltJBo 1KPAN5glLleZytkn5nbI4jr+696oFArUaMrSH3gerrhyntrZ48/8Qvc/YxWoXVhsVj4p J2Sf7bYqOGaRzGNmEKKwpVpBcWPJ8NTARtM+FM12wgRimmVPA7isrwapok+RRGkB+PwB BctOGM52k/Dyp9YQ+yx5orNIYpd9h9Fkv2WJAjQ/YbWPML4jyBf+3T7kSFPZvn5WbcPn Vv3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706558454; x=1707163254; 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=FZOIokXzjpngrmqwOyhUg05HTWtBvzei2jOUfSLMzLg=; b=l5t2cvdHvJwegQgV+xZrnow8i7U1zQ61CYnkEDVcSXJfoSa+BaCSCvDH3z9rdy7dfx sjnRLYEA+4V+Kp5QAY6MMQqxB21PCDkt+2XVuYdP16Zop6F+xhikPWKW+iZTddMb5cem 6DPW1fguDMLNlVf8WqV0MAi6BCGH5HrW8ZdU+dCZg5cNnDn4PjdN0YkRNsAM9Ay54Xmz Rvs8Ft0m+Ax5YW+yzj4p9/5iHcO2SqJz5rPCOqcjQqS78KSMIWvTtxgim+YVijiL74vf AGVOb1kuOEVn/ZWXEvxV5qkv8xcBrklIkEHBcjsP9sAnDuzsDLyAJesUBSfJjXy+5xng MqQQ== X-Gm-Message-State: AOJu0YymycAEdGOfW/YuKxqX5gErMhdJczmnzjd19nhAnOgsF96ODUnd nZ63j5bdWGLvBP/izm9RyeUVCXru6d+Lbvz17GTtGC/5d8BDnC6zkp0ln+v1 X-Received: by 2002:a17:90a:fb51:b0:28f:eeda:e9ad with SMTP id iq17-20020a17090afb5100b0028feedae9admr4072668pjb.28.1706558452840; Mon, 29 Jan 2024 12:00:52 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.51]) by smtp.gmail.com with ESMTPSA id m13-20020a17090ade0d00b0028ddfb484bfsm8869259pjv.49.2024.01.29.12.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 12:00:52 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 486A47402F3; Mon, 29 Jan 2024 12:00:51 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com Subject: [PATCH v2] x86: Generate REG_CFA_UNDEFINED for unsaved callee-saved registers Date: Mon, 29 Jan 2024 12:00:51 -0800 Message-ID: <20240129200051.573324-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: 1789456281540797112 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..8a78ebb6864 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 specific 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..578a093e0ca --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-19.c @@ -0,0 +1,17 @@ +/* { dg-do assemble { target *-*-linux* *-*-gnu* } } */ +/* { dg-options "-save-temps -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..4a0d399d904 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr38534-7.c @@ -0,0 +1,18 @@ +/* { dg-do assemble { target *-*-linux* *-*-gnu* } } */ +/* { dg-options "-save-temps -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" } } */