From patchwork Tue Nov 14 14:14:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 164942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1890458vqg; Tue, 14 Nov 2023 06:15:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5bOL2UAeetCK8UNC8Q2sxXv5YTgtypnqGPE4VTabuyCEvceaxs3Ew5etgsErck37aZNvI X-Received: by 2002:ac8:5a96:0:b0:41e:3754:a49c with SMTP id c22-20020ac85a96000000b0041e3754a49cmr2084440qtc.64.1699971328700; Tue, 14 Nov 2023 06:15:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699971328; cv=pass; d=google.com; s=arc-20160816; b=A/1y8jKTPf/4Hx6lL+vKpTmeg9P9BdPqcf+nmzgYucaMiJCdHykSmhsn43zs+bddOa HmSrWsWpy2bVTO1VsvyEyRaqv1TX+FPtCBYcaOK0w+q6dFdgGtJYwDzC+bxsi9Natta+ YqD0IqrDWHkKEE25obv25a5gQ7VihNLsmBxnM1oqLd50hfU/nVfJIQ/Q/UB86f8MDn3I iErSoPyKbxPGVIrKr9zgue2SzJR9cz3fVPSJBJw0HmQDewpmPjew2lklumjuQTUGJu8a Oz4Uja2ZE2gy51qpX/06U3gplLJ0YDFuC3NQXUyBX39oYZsq4tKm451HUK6iL8GrtQaG Gttw== 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=7QzUjlrL3Vr/CPuN0ms7bjq9bflJ3AGxXev1Ntq7J5A=; fh=8T25ejDQszIv0XIV+uHFl0ltUz+jjClOs2mp1gTMpKA=; b=guoOxiqvKYUZAX5ololgUkzf17KEmpyr4OlX+F1d0lKtwdtMqJ7RJ5OCobJEm+S6/y lzYkA3sl5BanZcvTHxD8UF3WlMHvdajTZP34cVkbjbXdkDAvKwN5ik/W1XpOuZynJ9BA c9JJUTsIEke2hyjF9xuoXShsrCoSoIlLkF5rAIv2hO68w5GTQXIPKbSEusmpAXq/95r9 D0Ff8wWavaa2Iscw7GOFUQOH2udjtm2uZYhGJ7H06AI5EuE99JZVV+DNmS+LWz7ARwSx ZEbE1Kcc1TkS7M9QyRKrWaBqN/eoiX6KCALwVyH2vvmWWxbTX0bjIY/tZQgTX7E1bNFN OSYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="Eq/wv773"; 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=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fx12-20020a05622a4acc00b004181b434f3esi6605852qtb.147.2023.11.14.06.15.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 06:15:28 -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=@sifive.com header.s=google header.b="Eq/wv773"; 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=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 761E638582AC for ; Tue, 14 Nov 2023 14:15:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 90B4F3858D28 for ; Tue, 14 Nov 2023 14:15:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90B4F3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 90B4F3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699971306; cv=none; b=oJV+e01mE6Z41jrL+ocfzLO6HGnq6Y49Hkp/faA8CnwaiePxmuTrA5cgb9TdV+n23sN3KtPcMhlYrAByu3ZtFUW0JsLc1dsc2eLma8EAiMUJLb78fZTG7RGdH/KGfm5Nijgqw99KQpy10t2R556U4/f0XrAOHyO1ltg67dhP9vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699971306; c=relaxed/simple; bh=yOqug2MwsHXWs/W0ocPaA8MTMavQ7Smzm8//NjbOnP0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=YeCchnmXRZzQiU7bwmB853yPxbP3SN4TIl2SApH4YKGvWzDJzEgxkTO41fPJOpkGNfiCUct1JSAptPFRjyYjC/NRcspFl92l829YnJPC0HxJGAk0fWYydmKD4GpakTwKhxDVp+EfwoYXkCT/TCBUalETqaYboG4BTfuTX62RL6A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ce3084c2d1so13873315ad.3 for ; Tue, 14 Nov 2023 06:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1699971302; x=1700576102; 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=7QzUjlrL3Vr/CPuN0ms7bjq9bflJ3AGxXev1Ntq7J5A=; b=Eq/wv773pwApGJzUJTteCM0qeXn8Rn1XiD0uQmVesAYQu66MGu3ds9lqeVeT3KdKvi Sd5jU7Wtq+0XyWUb21AHUnfFrLCiMSw93UXQAUz+t5a5eOeyMy33NBynnMAVc1laUpcm QCYSRqqcA1gavU/o9fCk4JQTERRA8V1tozYk7ayB7lsnSgEKueptbpA6iTquoUCz4Jrn STqbmkli0Mh8fqlQ8Uefpe7DrC4GSCovujlNFgHT34FKaeOgdh2phe58rXPyDQKLZaBC eG3Csy95Sw53dls/wD6/B6SYATl8Wti/7gdyFUMlRxwH1m8k6u3TYovIyUfnugkW+JY1 zCwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699971302; x=1700576102; 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=7QzUjlrL3Vr/CPuN0ms7bjq9bflJ3AGxXev1Ntq7J5A=; b=sF7EAiJe6hr+t4sqFhe0qmfISntucpWL2mOsVrLwMdPLtcm649XP3Nubpf8pfa/u8L O3dzE51AX5nQ2TWV3MkHOGpJrDCDRixMf1e8Bf5+xeLUI0rLCOKMtEgD+ruWHMlkSeWv j2RvVfSOD+RZsAmCc0x576fl+WNkyGq+Q4Nw6qy0e6yBtuqqinWxTUv/L6v6N4zxQ0VY 6oN64C8xa5kspwsBzpcsmDz1+ZoTKLgpbCWca6vuSthuxmEJT53BFXuSI//hr0pWWDrj rZiICavTVNNpEj3KMsk38lo+Yq7mJu38+JlqFP7L5ZOvazBj+7YB+tRsIFwKCKmIDoY/ YJVw== X-Gm-Message-State: AOJu0Yw9xVvADdnR6kVjJIa2+flEsRuwWHdykO47TW4sL193bBNZIreP J3tVHEO9cj4ywzd9FuOVE4uHrEjfs11C5G5BIbbQ0uPeDaQiyKCfuz1kX0HpmBNAYzlbcPum5qZ Uw6JPZIKF4peteqWLrXhEgEg0smDB7G45UUE5xmBlWlJMC0/G+8fNnQ1fcG4DFYwL2rO4+GF2sD vDf0M= X-Received: by 2002:a17:903:2308:b0:1ca:29f:4b06 with SMTP id d8-20020a170903230800b001ca029f4b06mr2692262plh.2.1699971302332; Tue, 14 Nov 2023 06:15:02 -0800 (PST) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id x23-20020a170902b41700b001c3f7fd1ef7sm5728791plr.12.2023.11.14.06.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 06:15:01 -0800 (PST) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com Cc: Kito Cheng Subject: [PATCH] RISC-V: Save/restore ra register correctly [PR112478] Date: Tue, 14 Nov 2023 22:14:55 +0800 Message-Id: <20231114141455.24465-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: 1782549136161814116 X-GMAIL-MSGID: 1782549136161814116 We set ra to fixed register now, but we still need to save/restore that at prologue/epilogue if that has used. gcc/ChangeLog: PR target/112478 * config/riscv/riscv.cc (riscv_save_return_addr_reg_p): Check ra is ever lived. gcc/testsuite/gcc/ChangeLog: PR target/112478 * riscv/pr112478.c: New. --- gcc/config/riscv/riscv.cc | 4 ++++ gcc/testsuite/gcc.target/riscv/pr112478.c | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/pr112478.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index ecee7eb4727..f09c4066903 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -5802,6 +5802,10 @@ riscv_save_return_addr_reg_p (void) if (riscv_far_jump_used_p ()) return true; + /* We need to save it if anyone has used that. */ + if (df_regs_ever_live_p (RETURN_ADDR_REGNUM)) + return true; + /* Need not to use ra for leaf when frame pointer is turned off by option whatever the omit-leaf-frame's value. */ if (frame_pointer_needed && crtl->is_leaf diff --git a/gcc/testsuite/gcc.target/riscv/pr112478.c b/gcc/testsuite/gcc.target/riscv/pr112478.c new file mode 100644 index 00000000000..0bbde20b71b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr112478.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-ffat-lto-objects" } */ + +void foo() { + asm volatile("# " : ::"ra"); +} + +/* { dg-final { scan-assembler "s(w|d)\[ \t\]*ra" } } */