From patchwork Tue Jul 7 07:28:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1324170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=d710qrCk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B1DYm0bcmz9sRR for ; Tue, 7 Jul 2020 17:28:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A3D9385703C; Tue, 7 Jul 2020 07:28:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by sourceware.org (Postfix) with ESMTPS id 526593857C79 for ; Tue, 7 Jul 2020 07:28:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 526593857C79 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kito.cheng@sifive.com Received: by mail-pj1-x1042.google.com with SMTP id cv18so635921pjb.1 for ; Tue, 07 Jul 2020 00:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nRRh4JXt4MLvECE57uelLj/0yFauJpSefZ5fndjonQY=; b=d710qrCkQxlkadP2Rs4A67BNGbRr3Cjk9KwU4bXE20i9SznCIvTeak373hXK2xQt7P BgJ42/CyG4QoKi1IfwCGPd7jR3jr20WLTmrcvqAPRB532LBsQlsv4TXGVclcc3LpxB2R TTj/5lXI9Nx5eRci28XwDg9YWea8HRo4kWL2Q9jQPN+lSJggKo1qHWLoSegkbijgSXew 0emK1K/1xehiOWH9Rn1JOXYgLDHSejlBUfRPrNtwIzOIkNkQ/TM2r6B01gRomgaDv7rh pu8t+66Vurxj6nBRRpMO/PaRHTKdpK+N7NR14DhbCAvoFXQ/d9aNjrhSFtF8/TA3moL9 nwAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=nRRh4JXt4MLvECE57uelLj/0yFauJpSefZ5fndjonQY=; b=fUoBOfibWVohmXJsQUdwMQ7F6DMIOuSYyDFCxkm/7gV8qyy+EV8fmnYjxI4DPGYMmE pn3OE/1MgSXqGb6uwdx94U+Cb44T+Gvu8qh7O8f+xU0MEI0LDztvGJPsIuZp4A1/f8ms sn3UosG21mF8UKoYiQnFh/hD1JS5akH+uyqKmQs9yzRXo4Sp5gcRJEBDDI5Y+Jox0Lu7 bT9VjJ42hXziXwN0LTXqeTLcx/SJHMgqCcihbIzi3fGdQSKUaW9+Dz9nKFtVhBmmGIu2 w53PsYZllwgfTkJD6OYZsm/Hec+zsX/2pd8+ucA5jTg5f2598hqNc7dquqFGGH5KMia2 wnWQ== X-Gm-Message-State: AOAM532KuWX9m620PvaJx4bnKSQ2BbyaMxH4jq0dzEpkiQrSrwfrIwyW GZsiIvmCH3RVWHIXX09I72hA3b1ooUY= X-Google-Smtp-Source: ABdhPJwFdUoCQFtFb+Wpd6NoPdlI4wTiDXhmIuew6rYA3BI1Cj/kjHFKvpFJ3ZlsVvhuehzLT2gHSA== X-Received: by 2002:a17:90a:c305:: with SMTP id g5mr2773777pjt.62.1594106885081; Tue, 07 Jul 2020 00:28:05 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id h15sm1646796pjc.14.2020.07.07.00.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 00:28:04 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com, fakepaper56@gmail.com Subject: [PATCH] RISC-V: Disable remove unneeded save-restore call optimization if there are any arguments on stack. Date: Tue, 7 Jul 2020 15:28:01 +0800 Message-Id: <20200707072801.104843-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kito Cheng Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" - This optimization will adjust stack, but it not check/update other stack pointer use-site, the example is when the arguments put on stack, the offset become wrong after optimization. - However adjust stack frame usage after register allocation could be error prone, so we decide to turn off this optimization for such case. - Ye-Ting Kuo report this issue on github: https://github.com/riscv/riscv-gcc/pull/192 gcc/ChangeLog: * config/riscv/riscv-sr.c (riscv_remove_unneeded_save_restore_calls): Abort if any arguments on stack. gcc/testsuite/ChangeLog * gcc.target/riscv/save-restore-9.c: New. --- gcc/config/riscv/riscv-sr.c | 6 +++++ .../gcc.target/riscv/save-restore-9.c | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-9.c diff --git a/gcc/config/riscv/riscv-sr.c b/gcc/config/riscv/riscv-sr.c index 9af50ef028e3..694f90c1583a 100644 --- a/gcc/config/riscv/riscv-sr.c +++ b/gcc/config/riscv/riscv-sr.c @@ -244,6 +244,12 @@ check_for_no_return_call (rtx_insn *prologue) void riscv_remove_unneeded_save_restore_calls (void) { + /* We'll adjust stack size after this optimization, that require update every + sp use site, which could be unsafe, so we decide to turn off this + optimization if there are any arguments put on stack. */ + if (crtl->args.size != 0) + return; + /* Will point to the first instruction of the function body, after the prologue end note. */ rtx_insn *body = NULL; diff --git a/gcc/testsuite/gcc.target/riscv/save-restore-9.c b/gcc/testsuite/gcc.target/riscv/save-restore-9.c new file mode 100644 index 000000000000..2567daeb376b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/save-restore-9.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -msave-restore" } */ + +int +__attribute__((noinline,noclone)) +foo (int u) +{ + return u + 1; +} + +int +__attribute__((noinline,noclone)) +bar (int a, int b, int c, int d, int e, int f, int g, int h, int u) +{ + return foo (u); +} + +int main() +{ + if (bar (1, 2, 3, 4, 5, 6, 7, 8, 9) != 10) + __builtin_abort(); + return 0; +}