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: 1891779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=edW6+x++; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TMdCS0byhz23fD for ; Sun, 28 Jan 2024 02:05:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 59E9E385843E for ; Sat, 27 Jan 2024 15:05:04 +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-Google-Smtp-Source: AGHT+IEeTN/DXZisKgU29K/aadM+zr3E6xVfu/6ob4GLpX6fNug392ZLpG51PTm9YwecEGec3vI0Gg== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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" } } */