From patchwork Mon Jan 29 13:26:05 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: 193463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp564156dyb; Mon, 29 Jan 2024 05:27:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJtTqFnimvEBbOvdPS6YGpMohd+IOfcfdtryAY/nKuJfCefpcI7Cr925L0BpfIbykVLhjz X-Received: by 2002:a0c:ecc1:0:b0:68c:440f:cb04 with SMTP id o1-20020a0cecc1000000b0068c440fcb04mr3902433qvq.9.1706534826129; Mon, 29 Jan 2024 05:27:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706534826; cv=pass; d=google.com; s=arc-20160816; b=RBIcodeAbEX+8p7hQvwlEowzSXEth/cDwZt3TjGL6SH2S2lHJ/RQg1Fqkptnilsik0 5DQT8fIFCrs7SZZaMCKQUbnrIhwEhe++1CxWzCzq5oS5BhJgdiU1iHO4qkTwkC0okEpt MYYpLvmlUOuhD3HKJq169kA3weCpDbpcxfdmtQjc3dMK4pTcVBwEtlXT1iOGtOrY5VSZ r3N9/RNfX/IU10AcJc0PwH99prK85CcOo8xcbO9gOFtkgx/jF7AgmpY2E2LiFmRZqOhU vNBZxtSVeBOXTEwLxtWxIkmTOhFVM5KtqicnSpzZHAmFmbB04omkk6ltw3YRmchOKbXO GFew== 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=8n4F2s51rdMSLnYNRU690LgfFKTbOsBb5DbLTDTQlug=; fh=K4AS3pFR26BR8zOf4IwrZlUeM0YSSQqO68Rjh5vfBKs=; b=RKAjCpvGRtL5qYxEJZMnrWMIZU0bVleH7yLQbA8yvIAKTviO/bFA9wHlU68AXCCqp+ 9BRs+59/13yvnbD6DOPrwlBANi8h+GPnXm38O4bMJhlpqmcrNV4T2oz9+hdfJrgDjqXa mYeQRUOMS9m6J+VmPhG5+2ZOEn9NYQUy/w8tMR8atJ7Oga+3tei6T/5lZBpr3omYYwOy mi5O5k5qniSzv04z4I8v2iw7bPS8NBEcwFD3bTnfMNAIV/lV8Pzob/Kv7WTR5mAZO6qw +PAus2Nf9Xe1RAVrqPlbZBB7FfvRY8BB9+cWPEcEGsJlXaq4d/v/+w4V9PCZfiY4PTcN KRHg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jCmr4AmZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ge12-20020a05621427cc00b0068c3d9567b3si4971087qvb.336.2024.01.29.05.27.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 05:27:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jCmr4AmZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 C71BB3858438 for ; Mon, 29 Jan 2024 13:27:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 49A1D3858CDA for ; Mon, 29 Jan 2024 13:26:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49A1D3858CDA 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 49A1D3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706534770; cv=none; b=rutJjz7wKv2czrFSx7HUWq1mmCgXwDBCyJ8DsUyhNWgh89+oDww3SGTIhE86QyxgKBAyZFl7YMuZ5Xh6adbdXYSl1K2eDRHds2+tLUJMvrW1hWCMJulPdu6t0eqrRffK7FV+oTrECKrhwCO+f/bLu8qDAozkttF4T4YaZJWnyeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706534770; c=relaxed/simple; bh=HEqfg5vIu+2qANSnRn+v1I0yYVmKqMhokyf/R45EQqE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Mnf/yiBUGq2lj47dBoFop/QYp8l0Kthms6M1iKD7SNBlGM+74kt5NaZxLM49rfVtIaC28OW5f25CRvLODvSPZDzyqbh+ubK5TMqf4RzMGlkIHAF9PCFzKrzwxYsCdhOxXdAbe9hM2+77XNvB7VHI1wFO6WL1m+6sJk95UWLZRGk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6e1214ae9d4so703529a34.3 for ; Mon, 29 Jan 2024 05:26:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706534767; x=1707139567; 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=8n4F2s51rdMSLnYNRU690LgfFKTbOsBb5DbLTDTQlug=; b=jCmr4AmZce51iMWPom8JAhlCEtPqbLq5zrWEuofuqONahKehuVXa6X6Bsdt9YlDRf4 Qa3fcOhZT73JeO4s3EzFYZj/qji5DuEuhYtRirfkvS8Vi8W4CajfjmHOex8eX0f7uep8 9QZ8agXA+sx6/RMAg+NH+hlv3JOSmj9j+ap0XqvhfsY5+McHR6fBxaLfyNtiFIwHEGBA enbf5aZeOT/LkiHLnSwLxvkMGRwlHupnqS3EupnZN4Q+emiVfUYKAMMHjkHsZ/NAGr7S BQ1zTRlU5MLexmay6+NTkXy9ZRK24rvo18xxafMRld6RmnpvluP6aGnGup3NLRMMzX+z 8gUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706534767; x=1707139567; 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=8n4F2s51rdMSLnYNRU690LgfFKTbOsBb5DbLTDTQlug=; b=AUG1baGzECOtNDnxTvweHnDf6VBmNcY58N0JX8i9hDTd+suO/HrSgV1qQHmW5oI/XP qMwVdoFS/KAPB/K+BEdhdesd+OFy7G0mpTZD52BXaoPSajiHOCAp7bdz9R1+oyztrOP8 7i4Hw8FGiUeP91QCudRWPwu/WJakzpdYJHbXFaT3szZtsFQbwh0G2oLB9dWBTduQITlU fMrVrjqZ6K/PXdHktcCkAlSygrzZRb9Y3l16nrbHwCQZTwZcLihMSCmzR6QK+v5gBRX0 Nh8V4uF+fpvcwJC8mEwhcJ0VcFXGS6G6xHRp2hWMyujUPTJmwxDw7MledSbYin9IdE37 xC7A== X-Gm-Message-State: AOJu0Yzr7ykqTn2Yi5D4SGEXhfEK29O5Auluwil6CRzIF4s1d8LXov6g CYti2bPTk48JN4ecAHvK9EqdG4pWH7Yte3xzCxenkue1EPl626P5ZAvG53RP X-Received: by 2002:a05:6358:708:b0:178:63a6:3c96 with SMTP id e8-20020a056358070800b0017863a63c96mr4724881rwj.57.1706534767089; Mon, 29 Jan 2024 05:26:07 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.51]) by smtp.gmail.com with ESMTPSA id o123-20020a62cd81000000b006ddc133f1d3sm6088415pfg.194.2024.01.29.05.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 05:26:06 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 713467401E6; Mon, 29 Jan 2024 05:26:05 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com Subject: [PATCH v3] x86: Save callee-saved registers in noreturn functions for -O0/-Og Date: Mon, 29 Jan 2024 05:26:05 -0800 Message-ID: <20240129132605.497501-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: 1789431462184288042 X-GMAIL-MSGID: 1789431462184288042 Changes in v3: 1. Add the TREE_THIS_VOLATILE check to minimize noreturn attribute lookup. 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. Also add the TREE_THIS_VOLATILE check to minimize noreturn attribute lookup. 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 | 12 +++++++---- gcc/testsuite/gcc.target/i386/pr38534-5.c | 26 +++++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr38534-6.c | 26 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 4 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..8f5ce817630 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -3381,9 +3381,10 @@ 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 + NB: Can't use just TREE_THIS_VOLATILE to check if this is a noreturn function. The local-pure-const pass turns an interrupt function into a noreturn function by setting TREE_THIS_VOLATILE. Normally the local-pure-const pass is run after ix86_set_func_type is called. @@ -3391,8 +3392,11 @@ 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))) + = ((TREE_THIS_VOLATILE (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" } } */