From patchwork Sat Jan 27 13:52:34 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: 1891765 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=aFaAw1l9; 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 4TMbcH0fxbz23gB for ; Sun, 28 Jan 2024 00:53:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74C87385841D for ; Sat, 27 Jan 2024 13:52:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id AE2503858D28 for ; Sat, 27 Jan 2024 13:52:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE2503858D28 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 AE2503858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::731 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706363560; cv=none; b=YRwwgIPAdb+fv0Mt8OqSd0U9+EKGLjDH72h6MrFjnOdE9Vut4UeQKjRSJGwlzNLZnLQDm8YvbL3t6yXJ/uaFivdntGfNxYMI3keJuBXHsBBFHaT23tS6XXsMKgB2L/4q8EmArs6b4yTOA6yTOlCLnQ+Uyl3iBNYn0bfQaSUObBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706363560; c=relaxed/simple; bh=S+70KynRsmPbpaSfg3aBJ7qSCVzGXWdYGMT9z1xz4S0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=i0r2pENXR3A/M+stk02OMuRRC4pzFsPzDGzeTRpG77owRLt4GWWct9r2N+BJgyQcadMRsDuewKibEl5xHl7wGixBJqrgd5O/qDIGANFr7N4JSjBsrmDWwp2EoFOgAGYIn9W6kSRVf4lU/1z5Hf5r1AnaF0+wStptS7yAUtYRVqY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-783da8920e5so91443785a.1 for ; Sat, 27 Jan 2024 05:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706363557; x=1706968357; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=xbof/+Jh/YiGoMq/0cPkiki0ZEYXrmq5Zk1xM/4fV/c=; b=aFaAw1l9G57GtBMLU3ixP/2tPyIVZlKuDJWTnrzIGLyP5h0x4toBuHt4imQcIWGNyK mn3GVeBsujjK0RkeP6keIPY5d42ctgqrOKRE4Uhk3lTvJ0vWPVTF47TGxqM9y+OVT+ka 3AmSWozPQzY3KIYHqNVBb4Je3xJNCoLocULh42AD1NG72LsQmJ1bdsDxViczVPFatCKR RU7mXAe6xbAIDodPkMNLv5EUmcfQmXR+4LDzFtM5uaPGHC6uzoF/Ub7ea3dM9pZB5/TF wZvXFAMNAcWacV7XLVjQhfngFT9IHL1zSnJMNP/yAHpe60m2dPKs0rQIiPXahJTeDaO+ KFqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706363557; x=1706968357; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xbof/+Jh/YiGoMq/0cPkiki0ZEYXrmq5Zk1xM/4fV/c=; b=CKAWYygwEa8ET3Fnomh2H8P37WyxI4WYn8oLnL/LdkfVuGoVQwzCHc6Fit4gDiloLX 2JleNXHu5gB1du5WMjiblnlnVd1VminXJ7MGG90TS0YxWMiA3UrrEQLfJvKWEFE+zELd SUpmNSeuWQRXdJ1phfAbKbhSVTbrI7MA3H63rJwaMHQfT3elUN9kbqAZ2sRKdYXlirbq ek685RSsUTuvBONSvAcZSm23zn4oPjSsY6rM/530kW7NoHnBI5JTMWNvNiQ1cAXzFwfm xYOs081siPbY5HOIdyLh31/DzPkKYWY4r/J78R/PLxNMq9xLX2JpiR6fjWssQUYkjLu6 PRfg== X-Gm-Message-State: AOJu0Yzui1JzgisVhNa7zmeyeK3vUGp6On33KpdL4BQAWA5jxnByfsVK T1ppZ2dwaax/77BtUnX3vUqErYMRyikoBrCxEC/pa3PAT8MwKOhJSzj88I35 X-Google-Smtp-Source: AGHT+IFlZ02gjS6SquWxh3sj1Q4Mlyf0kQX3nOepgnxGx1vw5XrvHcWN7tUrva/OJl708kQY5AsZhA== X-Received: by 2002:ae9:f30c:0:b0:783:c85b:c86 with SMTP id p12-20020ae9f30c000000b00783c85b0c86mr1422113qkg.154.1706363556943; Sat, 27 Jan 2024 05:52:36 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.51]) by smtp.gmail.com with ESMTPSA id sm5-20020a17090b2e4500b0028ffea988a2sm2985414pjb.37.2024.01.27.05.52.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 05:52:36 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 002D3740067 for ; Sat, 27 Jan 2024 05:52:34 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: [PATCH] x86: Save callee-saved registers in noreturn functions for -O0/-Og Date: Sat, 27 Jan 2024 05:52:34 -0800 Message-ID: <20240127135234.354114-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 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 | 7 ++++-- gcc/testsuite/gcc.target/i386/pr38534-5.c | 26 +++++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr38534-6.c | 26 +++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 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..5ff5560df7a 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,7 +3392,9 @@ 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) + = ((optimize + && !optimize_debug + && (TREE_NOTHROW (fndecl) || !flag_exceptions) && lookup_attribute ("noreturn", DECL_ATTRIBUTES (fndecl))) || 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..756e1ec81f5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr38534-6.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -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" } } */