From patchwork Sat Jan 27 15:04:42 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: 193019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp529857dyb; Sat, 27 Jan 2024 07:05:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEa063tSaX8vAxe++Iq/Vb+5Xy1BXMoGp2ClDrhBWJzXkNswIaNqJtEjNVo9tvh57T2Seby X-Received: by 2002:a05:6214:b91:b0:68c:3b03:ee99 with SMTP id fe17-20020a0562140b9100b0068c3b03ee99mr1170331qvb.12.1706367924826; Sat, 27 Jan 2024 07:05:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706367924; cv=pass; d=google.com; s=arc-20160816; b=PtW+dWqdD3KwlYGNgFdtHoPtscEdDA3GbPxz+LOwZ9cTyBnC2mFX7fZ70KgW1Q3TMV N7s/mfnU19UTgiJD5tpXimpdAO9Vt7De3o5oswSzuN/qdjnffI7n+n0XJ5cyBH2VqDZ7 MjVOQ/VG9C25efdaG6k0Y08uCfKiuYVDI/r57TLpNDq9gFS0KFXp3CzYS+peIpqsVvh3 tKEebNTaN32Hs6bJHeaAuiBmnryoasoIOrx4qPViozTxT7etDLmj8Zm2QZkvs3B5n7PK 9zIkbumnL6+hO3K98Qtz8ERPR42uT5Vq/Va1YLPr7M1CXCohhoMQoeuJS775vT7pPLSs VYGQ== 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=jxHjDw2nQwpKrCq9VMx9aZNeAHgOJDYPLT0BAGTADI0=; fh=K4AS3pFR26BR8zOf4IwrZlUeM0YSSQqO68Rjh5vfBKs=; b=F7SOa8me51dy3cMJGKAwCNGq8ja1jM5ZVQGYpySZIAU8vucYEBw1m3Nw/h84q0EuHu Yq6YU+tfjjlecVr+8LoAp0WfG3dDokYeFPKmPB+x5ctAC3VTPC4JHBL+tdbt1//RDB6r IL2hMlBua8HMwtyLjhgIGOPlye7pDfE2xT6zcrkyWMgBpsoMegQlzlmG5Hp2GmTvVLiB YHWg//Db+xA73fzldUFDwhwqmBkmDACo8f0eWXmnSMN5rx/otjogXVHAZCYtStMfW+/J BgXwlZoyz6MlYVgQQqwSssedMQPY89eJ8CoMA/sGvWaHqpEcqCj22AAhUHm4XJGRA+t7 DGGA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=edW6+x++; 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 fq2-20020a056214258200b00680bb9364f6si3657004qvb.84.2024.01.27.07.05.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 07:05:24 -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=edW6+x++; 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 8818C3858281 for ; Sat, 27 Jan 2024 15:05:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 94A4F3858D28 for ; Sat, 27 Jan 2024 15:04:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94A4F3858D28 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 94A4F3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706367887; cv=none; b=BR89g+J8FYI6yqUNwBLxgdPdy1WWoDTHNKkfbc0YHjcCfNdmkGxXs77P25uTaA9o3Ocav8DIRztWSNnYp0swAj1DnM9/QlSpH6A1+1+zl/ePA+jq1zRFtGyQ6WxuFnT5FZ9qkbSK9DUpwCEojzK/apV2MKcqLHpNd4cyjy1dInQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706367887; c=relaxed/simple; bh=aANA38D9xJX7P5vpzv6/mR4bIXWo3LB4BXcOTNwwWCM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RzKt5JGrX9+jxT4SZtX7IV7nJ05teEeDzfIPQutDID0vwpMjoxzjT77yd+456XcBnm2NmttqrdkdJx6qJw6tCuHkQcbpdm+rzjhn/O0+oCuSVqo0gUJ3kcufi4ngDCDwDnvFDgMWcX/K4iHEtINYZz3cEBmWRLqP9H0lwTN/mU0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-290fb65531eso815579a91.2 for ; Sat, 27 Jan 2024 07:04:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706367884; x=1706972684; 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=jxHjDw2nQwpKrCq9VMx9aZNeAHgOJDYPLT0BAGTADI0=; b=edW6+x++/Y01HmHQfegvHJd/fxnGnFZhOG5kVVx8SQ2+f9g+rVD8hM031B4U4xPXHk SSHATJyuJcg8xf55tz5EFlSTDR07iufB7VQ/0xbR7VzZhFKRNCUAvHAW0eMpjV3T1Opv gRzmI6Nz/Vqi6P/+1ZQ/nWZKsRtz+L2g/nqZ4WqIeZQINL4/5kDukE8KUpGn0o7qcdME m7GIW0igBBNGoxKkxnyk7IpYU/hdnii9y3XuFuyNM15BbrRhOC2WS/n8BmrvQ3qbcWGC kWjZVbyx/U28HB68XxNECvacwd4Tg8+rTCJkucIikusLJwtYTAq1+HJlHuvb+eKufiug miYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706367884; x=1706972684; 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=jxHjDw2nQwpKrCq9VMx9aZNeAHgOJDYPLT0BAGTADI0=; b=k09R3tYeTif2qaOOjszDw+zX3qbSq5gmvcRt8NOYVBtJjaGlvw7B+i90WgwTBoAHwp ijnQlj2mwa+ZFHo+CAY+bbaWmVBFREOPQtNW35DWyWQGTUjsNYRFTzidmTtpK9Zaj8JW r9LcTAsR+z3MAYi+ke666DemHKIC+/ggBRa8DAQ1ANYOupLjHZ6iId7YLyooYaVS1w5E tO05lJx/HI9+vaYxMkk0EIpJUY+XLu4I/t/y9JkaGGolHmdOpnQpmiZqI/f77l8kRCkn dJXicKkVEROGi+97Xlhay3WKiqL+5bVXGmWkcuQk4EzW4AFh+YKWHZG6/c/arkzJ93rX o4uw== X-Gm-Message-State: AOJu0YyN+VxQJWGK3c8fwHme9f39pdES91kUG5I6QjQESKYsgBEw+4VN ocLWReolk/uOd3/9P31Oe1FuEB99n44qvBrHKvMCuVNNlGOt7KiCymAUPOL0 X-Received: by 2002:a17:90a:ca94:b0:290:e9af:339f with SMTP id y20-20020a17090aca9400b00290e9af339fmr731642pjt.93.1706367884025; Sat, 27 Jan 2024 07:04:44 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.51]) by smtp.gmail.com with ESMTPSA id md14-20020a17090b23ce00b00290239db63bsm5137251pjb.35.2024.01.27.07.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 07:04:43 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 3BC66740067; Sat, 27 Jan 2024 07:04:42 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com Subject: [PATCH v2] x86: Save callee-saved registers in noreturn functions for -O0/-Og Date: Sat, 27 Jan 2024 07:04:42 -0800 Message-ID: <20240127150442.357898-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: 1789251917337101218 X-GMAIL-MSGID: 1789256453340981482 Changes in v2: 1. Lookup noreturn attribute first. 2. Use __attribute__((noreturn, optimize("-Og"))) in pr38534-6.c. ---- Save callee-saved registers in noreturn functions for -O0/-Og so that debugger can restore callee-saved registers in caller's frame. gcc/ PR target/38534 * config/i386/i386-options.cc (ix86_set_func_type): Save callee-saved registers in noreturn functions for -O0/-Og. gcc/testsuite/ PR target/38534 * gcc.target/i386/pr38534-5.c: New file. * gcc.target/i386/pr38534-6.c: Likewise. --- gcc/config/i386/i386-options.cc | 9 +++++--- gcc/testsuite/gcc.target/i386/pr38534-5.c | 26 +++++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr38534-6.c | 26 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-5.c create mode 100644 gcc/testsuite/gcc.target/i386/pr38534-6.c diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index 473f5359fc9..a647b1bdf5c 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -3381,7 +3381,8 @@ static void ix86_set_func_type (tree fndecl) { /* No need to save and restore callee-saved registers for a noreturn - function with nothrow or compiled with -fno-exceptions. + function with nothrow or compiled with -fno-exceptions unless when + compiling with -O0 or -Og. NB: Don't use TREE_THIS_VOLATILE to check if this is a noreturn function. The local-pure-const pass turns an interrupt function @@ -3391,8 +3392,10 @@ ix86_set_func_type (tree fndecl) function is marked as noreturn in the IR output, which leads the incompatible attribute error in LTO1. */ bool has_no_callee_saved_registers - = (((TREE_NOTHROW (fndecl) || !flag_exceptions) - && lookup_attribute ("noreturn", DECL_ATTRIBUTES (fndecl))) + = ((lookup_attribute ("noreturn", DECL_ATTRIBUTES (fndecl)) + && optimize + && !optimize_debug + && (TREE_NOTHROW (fndecl) || !flag_exceptions)) || lookup_attribute ("no_callee_saved_registers", TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))); diff --git a/gcc/testsuite/gcc.target/i386/pr38534-5.c b/gcc/testsuite/gcc.target/i386/pr38534-5.c new file mode 100644 index 00000000000..91c0c0f8c59 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr38534-5.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O0 -mtune-ctrl=^prologue_using_move,^epilogue_using_move" } */ + +#define ARRAY_SIZE 256 + +extern int array[ARRAY_SIZE][ARRAY_SIZE][ARRAY_SIZE]; +extern int value (int, int, int) +#ifndef __x86_64__ +__attribute__ ((regparm(3))) +#endif +; + +void +__attribute__((noreturn)) +no_return_to_caller (void) +{ + unsigned i, j, k; + for (i = ARRAY_SIZE; i > 0; --i) + for (j = ARRAY_SIZE; j > 0; --j) + for (k = ARRAY_SIZE; k > 0; --k) + array[i - 1][j - 1][k - 1] = value (i, j, k); + while (1); +} + +/* { dg-final { scan-assembler "push" } } */ +/* { dg-final { scan-assembler-not "pop" } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr38534-6.c b/gcc/testsuite/gcc.target/i386/pr38534-6.c new file mode 100644 index 00000000000..cf1463a9c66 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr38534-6.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move" } */ + +#define ARRAY_SIZE 256 + +extern int array[ARRAY_SIZE][ARRAY_SIZE][ARRAY_SIZE]; +extern int value (int, int, int) +#ifndef __x86_64__ +__attribute__ ((regparm(3))) +#endif +; + +void +__attribute__((noreturn, optimize("-Og"))) +no_return_to_caller (void) +{ + unsigned i, j, k; + for (i = ARRAY_SIZE; i > 0; --i) + for (j = ARRAY_SIZE; j > 0; --j) + for (k = ARRAY_SIZE; k > 0; --k) + array[i - 1][j - 1][k - 1] = value (i, j, k); + while (1); +} + +/* { dg-final { scan-assembler "push" } } */ +/* { dg-final { scan-assembler-not "pop" } } */