From patchwork Mon Jan 15 05:54:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 188028 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1519992dyc; Sun, 14 Jan 2024 21:55:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIzklPnFSASgrifZE4Ym8yUAV9Jm6xzbcEwC2fujYFtu5TBzhxggYjbDVQuSaYgEag6mjD X-Received: by 2002:a05:622a:4cf:b0:429:9349:9869 with SMTP id q15-20020a05622a04cf00b0042993499869mr7538578qtx.27.1705298135497; Sun, 14 Jan 2024 21:55:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705298135; cv=pass; d=google.com; s=arc-20160816; b=va6+dY4RvRM0qqDVbbP3cUynAXMHqb0fxZKwsT++AbtVQfL1UY5hAogYabzL2hG77B Ttnz+z/XcLZiXC1/SXWSG2R/V9n3yB4evdejoA6BbbEADZsxdpXGy1W+ZHDWZkJEha8b q1rbsAPFMlKhO5ioKHS81ItWP46tqTEWY1q1N/ntUgRVz8LZi7xNwdx6WkVrMa0YcvD0 zFvRtfLot1RSAfMI9jQTl8DCIH6NTfNRvLNkCg3dPeccGIjFloIyO00Ydtpq7vylX1FG YN7+5jVUwmhQBpfAorEpLf9QFtIpBr8hESS6F+7SuaihI/mfVCrcdTYcmZgxl3AR6Qf+ ++1A== 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:to:from:arc-filter :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=HF1ISD1+qE96xZZWPHeggflQgqYeBDomLAwlkeahDrg=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=bH+oShwWS6RsudvXEEy7OThMdwTAhxIAU3dLxyHj5wZwPbhw6upQTmeDne5evW7gRf tqlQzTayz0GmISG7uwvvXddCCJeO/xRH2FYyHsHu6tpA6ta2JZeMQhkxwJyJLGQjHiXn 4VBppyS/Mw6hriL/hVBpKwGv4GOjUJKiklhyX83aLQLdCwUJ8TjfDdbZgOffdrBBaOkl BpCsywUySXmt6s7cTZ05btyJy1tDwhqgOfj7dtLAU4n1ltI5qxrnwINa3F9jamy9ZrkR w9oL/RC+trjfvsp2y9lzyuYmSOnI/1L7JcOaxbZCj2XGZkezSgcEELPVRm0gkR5qa8CM bxeg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CRrY+3og; 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=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y20-20020ac85f54000000b004290d54ea4fsi7548973qta.715.2024.01.14.21.55.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 21:55:35 -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=@gcc.gnu.org header.s=default header.b=CRrY+3og; 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=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D1D43858C5E for ; Mon, 15 Jan 2024 05:55:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D1D43858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705298135; bh=HF1ISD1+qE96xZZWPHeggflQgqYeBDomLAwlkeahDrg=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=CRrY+3og+0IyhZfJmRXONVYFGbK7qpImFcRSrXAa/gQFx04z5Gl7aiCPkPjSC8eth MASfWAdmXZTRUXcTUxXgQBeaTw+g/KhSP+1u55zMwwZZ+nzNj3zN2GeVuTz7okioUI ofOhxSSZCRH+vt59JH5vL7h4NBPLbB2v0tWOxR2A= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by sourceware.org (Postfix) with ESMTPS id 3F5343858D1E for ; Mon, 15 Jan 2024 05:54:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F5343858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3F5343858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705298073; cv=none; b=vHxpCb74OxcXV4T9k7dHZMz+8KZGh/bw/M0ISQy8oNGDGnhnVhQdYNxjRYz9ti3ctIz1Rz5B/HygmLXSqobtsmzZXeeTsMtGMMCLwYQpWFAIrBwC6CWSfwQkZKCKTYGuZjd2tpNx7YqOm/YIgW8S6NfgBQQ3i+V8rEQlu5PerB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705298073; c=relaxed/simple; bh=I2mf1oOdW6lQAinH2eQSW0Rp4JXLzQ3PbssUfeRfHnw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=k8tv93WurIOfuLDHnedbH2B4gJHruSrSQ4xn3X7Npk3zbdJhvD8pDDGDG4vgW+nzUj0ZyXGERuANXo05tHZaQWxw90ahl4MXOiiXabbZkUzjRD8aJQvd/pxB2vhEWo+P5a6BHNwvBlAwB/snXQ8D62GShS/qYRENL4QlvYf7aE0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6d9af1f52bcso4078448b3a.3 for ; Sun, 14 Jan 2024 21:54:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705298069; x=1705902869; 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=HF1ISD1+qE96xZZWPHeggflQgqYeBDomLAwlkeahDrg=; b=Zeyay62zC6URhe8AiiUgv3uDJN+sff5hwicsh3LCNVTlJyJ8zl/aduEHg5g2WIAkMd uriTyE5bBmTg+XepYIc8yzqNVp1M2s8C0wBYfAqe4tFdOmdxQF3cDYjAzaXfaMktSeJb +mHUFI7CrgJ7MSp+gOb2+Z3wMKVOc//oKtaHMwI8vlSxnKbUPrwofuMCJCqPhqTT5Rgf UcVdCV/3h1t0I7wx9za+236GglKJ2Pun6HqazwgFWGR4cxAZ91AFCfcWJudxzMGSZksA f3SpJcrjEjpDFLBiOLbxkJMZG3qFmjNu9s2BNZy1sxU+yYz+7JBIgZqAVbJtmDl+hVPD 9tNw== X-Gm-Message-State: AOJu0Yw6fQwYpyWiugpjn+NEmZPilJQSchqsqXwq70l/r90sOBFnm+05 d9a4uEBWOw89Rd3aTyxBsfZoVh9y5T79qA== X-Received: by 2002:a05:6a00:174e:b0:6da:b46f:9e37 with SMTP id j14-20020a056a00174e00b006dab46f9e37mr2546913pfc.55.1705298068929; Sun, 14 Jan 2024 21:54:28 -0800 (PST) Received: from localhost.localdomain ([149.248.38.156]) by smtp.gmail.com with ESMTPSA id fn9-20020a056a002fc900b006d9ae6fe867sm6863207pfb.110.2024.01.14.21.54.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 21:54:28 -0800 (PST) From: YunQiang Su To: gcc-patches@gcc.gnu.org Subject: [PATCH] MIPS: avoid $gp store if global_pointer is not $gp Date: Mon, 15 Jan 2024 13:54:20 +0800 Message-Id: <20240115055420.2427723-1-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: 1788134697297955001 X-GMAIL-MSGID: 1788134697297955001 $GP is used for expanding GOT load, and in the afterward passes, we will try to use a temporary register instead. If sucess, we have no need to store and reload $gp. The example of failure is that the function calls a preemtive function. We shouldn't use $GP for any other purpose in the code we generate. If a user's inline asm code clobbers $GP, it's their duty to save and restore $GP. gcc * config/mips/mips.cc (mips_compute_frame_info): If another register is used as global_pointer, mark $GP live false. gcc/testsuite * gcc.target/mips/mips.exp (mips_option_groups): Add -mxgot/-mno-xgot options. * gcc.target/mips/xgot-n32-avoid-gp.c: New test. * gcc.target/mips/xgot-n32-need-gp.c: New test. --- gcc/config/mips/mips.cc | 2 ++ gcc/testsuite/gcc.target/mips/mips.exp | 1 + gcc/testsuite/gcc.target/mips/xgot-n32-avoid-gp.c | 11 +++++++++++ gcc/testsuite/gcc.target/mips/xgot-n32-need-gp.c | 11 +++++++++++ 4 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.target/mips/xgot-n32-avoid-gp.c create mode 100644 gcc/testsuite/gcc.target/mips/xgot-n32-need-gp.c diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index e752019b5e2..30e99811ff6 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -11353,6 +11353,8 @@ mips_compute_frame_info (void) in, which is why the global_pointer field is initialised here and not earlier. */ cfun->machine->global_pointer = mips_global_pointer (); + if (cfun->machine->global_pointer != GLOBAL_POINTER_REGNUM) + df_set_regs_ever_live (GLOBAL_POINTER_REGNUM, false); offset = frame->args_size + frame->cprestore_size; diff --git a/gcc/testsuite/gcc.target/mips/mips.exp b/gcc/testsuite/gcc.target/mips/mips.exp index 9f8d533cfa5..e028bc93b40 100644 --- a/gcc/testsuite/gcc.target/mips/mips.exp +++ b/gcc/testsuite/gcc.target/mips/mips.exp @@ -266,6 +266,7 @@ set mips_option_groups { stack-protector "-fstack-protector" stdlib "REQUIRES_STDLIB" unaligned-access "-m(no-|)unaligned-access" + xgot "-m(no-|)xgot" } for { set option 0 } { $option < 32 } { incr option } { diff --git a/gcc/testsuite/gcc.target/mips/xgot-n32-avoid-gp.c b/gcc/testsuite/gcc.target/mips/xgot-n32-avoid-gp.c new file mode 100644 index 00000000000..3f52fc5a765 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/xgot-n32-avoid-gp.c @@ -0,0 +1,11 @@ +/* Check if we skip store and load gp if there is no stub function call. */ +/* { dg-options "-mips64r2 -mxgot -mabi=n32 -fPIC" } */ + +extern int a; +int +foo () +{ + return a; +} +/* { dg-final { scan-assembler-not "\tsd\t\\\$28," } } */ +/* { dg-final { scan-assembler-not "\tld\t\\\$28," } } */ diff --git a/gcc/testsuite/gcc.target/mips/xgot-n32-need-gp.c b/gcc/testsuite/gcc.target/mips/xgot-n32-need-gp.c new file mode 100644 index 00000000000..631409cb7fe --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/xgot-n32-need-gp.c @@ -0,0 +1,11 @@ +/* We cannot skip store and load gp if there is stub function call. */ +/* { dg-options "-mips64r2 -mxgot -mabi=n32 -fPIC" } */ + +extern int f(); +int +foo () +{ + return f(); +} +/* { dg-final { scan-assembler "\tsd\t\\\$28," } } */ +/* { dg-final { scan-assembler "\tld\t\\\$28," } } */