From patchwork Thu Aug 6 13:28:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 1341719 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=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=kwRAXSSh; 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 4BMq7f0JS4z9sPC for ; Thu, 6 Aug 2020 23:28:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6BC33860C39; Thu, 6 Aug 2020 13:28:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6BC33860C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596720507; bh=SIT6/91j5QSB3XB/pGzAg/DgWuzsD2BPGW9uQaSp61M=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kwRAXSSh8nlnA2tTtn7fziTtS47lAmn6foQCuQ3w0v0F7jjJ8oufeRBFYGA09yFtR QTXON1fparhkWA5wEkRJTHqchaRdCXIprtrdKknXj46wUWEoZNUMANP/tYKX0gUOIh p2ZmASPX7nizq1yzRgNecsR/SL5rhFVieANoLVKU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by sourceware.org (Postfix) with ESMTPS id 21B9A3857C6C for ; Thu, 6 Aug 2020 13:28:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 21B9A3857C6C Received: by mail-pf1-x442.google.com with SMTP id z188so17104926pfc.6 for ; Thu, 06 Aug 2020 06:28:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=SIT6/91j5QSB3XB/pGzAg/DgWuzsD2BPGW9uQaSp61M=; b=Ff6jRHG8LkRndWQvbXPSPJ0abou2h1GsBiSS3FTOJawYNpfQXfdhBo82NLG9QH6NHN QoH0mq0LROg6ynVsQxjlhttrRSqlDXXnVRv8/4niqq4doR9oXFPkusdP3U/m1DPG4R8b FuFvZ43mGENyNDyzbWD9RmQUNAUt4xk9Ukb3MdBmkNay6XxOWKDQF2fw6UscIIY8AE5s 63TA+uPCZYv83Ur4ynuKmubw+vp9KYft4CFjTuqcUV5yJ3KQTe42rqfMGS7ibyNaf2Bj NV3Xz6xxZLbbKX0k8bLPp8v0VWBFHjatZpyX9L33TDHJl0yETEFzFH5Lz19oG7S1Fr+v vlEA== X-Gm-Message-State: AOAM530gPDA7STEDAAvNaKCqkOLF8Btcjl3B8WulIlSJ5UeKHSFbJl3i K0aZDapMi2Kkl0rzvsB1hE23abEOg1I= X-Google-Smtp-Source: ABdhPJxEj93MZL1hk+aR3HxL8/GY11B1hUQcbeeOk/OG74sDqIGK8C50R6N9XQlhZShuNWGVoxxCTw== X-Received: by 2002:a65:484c:: with SMTP id i12mr7670805pgs.145.1596720503694; Thu, 06 Aug 2020 06:28:23 -0700 (PDT) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id l67sm7396105pga.41.2020.08.06.06.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 06:28:22 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id E5DCF880EE; Thu, 6 Aug 2020 22:58:18 +0930 (ACST) Date: Thu, 6 Aug 2020 22:58:18 +0930 To: gcc-patches@gcc.gnu.org Subject: [RS6000] PR96493, powerpc local call linkage failure Message-ID: <20200806132818.GF15695@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, 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: , X-Patchwork-Original-From: Alan Modra via Gcc-patches From: Alan Modra Reply-To: Alan Modra Cc: Segher Boessenkool Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This corrects current_file_function_operand, an operand predicate used to determine whether a symbol_ref is safe to use with the local_call patterns. Calls between pcrel and non-pcrel code need to go via linker stubs. In the case of non-pcrel code to pcrel the stub saves r2 but there needs to be a nop after the branch for the r2 restore. So the local_call patterns can't be used there. For pcrel code to non-pcrel the local_call patterns could still be used, but I thought it better to not use them since the call isn't direct. Code generated by the corresponding call_nonlocal_aix for pcrel is identical anyway. Incidentally, without the TREE_CODE () == FUNCTION_DECL test, gcc.c-torture/compile/pr37433.c and pr37433-1.c ICE. Also, if you make the test more strict by disallowing an op without a SYMBOL_REF_DECL then a bunch of go and split-stack tests fail. That's because a prologue call to __morestack can't have a following nop. (__morestack calls its caller at a fixed offset from the __morestack call!) Bootstrapped and regression tested powerpc64le-linux. OK to apply? Should I rename current_file_function_operand to something more meaningful before committing? direct_local_call_operand perhaps? gcc/ PR target/96493 * config/rs6000/predicates.md (current_file_function_operand): Don't accept functions that differ in r2 usage. gcc/testsuite/ * gcc.target/powerpc/pr96493.c: New file. diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index afb7c02f129..2709e46f7e5 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -1051,7 +1051,12 @@ && !((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && (SYMBOL_REF_EXTERNAL_P (op) - || SYMBOL_REF_WEAK (op)))"))) + || SYMBOL_REF_WEAK (op))) + && !(DEFAULT_ABI == ABI_ELFv2 + && SYMBOL_REF_DECL (op) != NULL + && TREE_CODE (SYMBOL_REF_DECL (op)) == FUNCTION_DECL + && (rs6000_fndecl_pcrel_p (SYMBOL_REF_DECL (op)) + != rs6000_pcrel_p (cfun)))"))) ;; Return 1 if this operand is a valid input for a move insn. (define_predicate "input_operand" diff --git a/gcc/testsuite/gcc.target/powerpc/pr96493.c b/gcc/testsuite/gcc.target/powerpc/pr96493.c new file mode 100644 index 00000000000..3ee0fc9fe45 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr96493.c @@ -0,0 +1,28 @@ +/* { dg-do run } */ +/* { dg-options "-mdejagnu-cpu=powerpc64 -O2" } */ +/* { dg-require-effective-target powerpc_elfv2 } */ + +/* Test local calls between pcrel and non-pcrel code. + + Despite the cpu=power10 option, the code generated here should just + be plain powerpc64, even the necessary linker stubs. */ + +int one = 1; + +int __attribute__ ((target("cpu=power8"),noclone,noinline)) +p8_func (int x) +{ + return x - one; +} + +int __attribute__ ((target("cpu=power10"),noclone,noinline)) +p10_func (int x) +{ + return p8_func (x); +} + +int +main (void) +{ + return p10_func (1); +}