From patchwork Sun May 5 18:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1931590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KEeavk/4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VXXm20T17z1xnS for ; Mon, 6 May 2024 04:15:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7CEF385B50B for ; Sun, 5 May 2024 18:15:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by sourceware.org (Postfix) with ESMTPS id 1C1E23858D28 for ; Sun, 5 May 2024 18:15:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C1E23858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1C1E23858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714932929; cv=none; b=LBGz5ezX7aHX5Vt5tpG9LYSA81CQjFe4k+JE/d5TCho1qhfAFMVVSXWVSv6KOw+NsyLLYaW0y+sdOrtBk0YjbXjzZ+KWoe7kvCMR4Dw1h3IO2iKI0yQn0BaKCEt/In1QBVtCnw/LmFwvl6zRrkIKSEh/rzF57T3FKCwDy+jiaTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714932929; c=relaxed/simple; bh=wCCSEEet2oPiCbaSeWucj7kBpVN7FnMyZBQ5zpzGxmk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Z48KyKStXwXnVmzlfACzNSrI0qkRJcL2B9HczDQFT3MZ8PROCdrOVJtuoRckRdqtd5Z96Yuh/eja7zhQi2M/cIUwgggnPzqhccnLWa57tqhMsH8COm1Q037yN14phMESbj5vE5955d/XHMjlcowqca8DMhwtVSO2T2ULB6pI8Fg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714932927; x=1746468927; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wCCSEEet2oPiCbaSeWucj7kBpVN7FnMyZBQ5zpzGxmk=; b=KEeavk/4Mu45i9WlDkcvQmc3rQWpvt483kQWRU5Lyzm6NeZ+D5F2TK4C O8JwXafncyv1DFdXHG0iwZRxtJNzRQ1gY1zE6QkvDddbJhUE/cOw37vIe pL+rCB6tVbu23TOW6vAJXBWa71TvUPYl4ZV0Rhju4JupCqFGWmcE4fdoI MKjSy9miuAj95r7q8cNpw4fPHiUTeXjguP+8H0QCDu0XmnSBQ6uXmSuCK 8FzCWmamCcklHe0rLf/Gs7lvwPfucLomMIYNdgElYiNsX3ckoEjsxz9Pq l8NjWErw80ma0HCxai2smwqE648zqkEgxCzv2FAalDHyNFJ8kZkAzG8jN g==; X-CSE-ConnectionGUID: MJIGwv7dT1ORRP8FT2AupA== X-CSE-MsgGUID: aqFuj4z8TWyU1gssSepHew== X-IronPort-AV: E=McAfee;i="6600,9927,11064"; a="21356316" X-IronPort-AV: E=Sophos;i="6.07,256,1708416000"; d="scan'208";a="21356316" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2024 11:15:26 -0700 X-CSE-ConnectionGUID: +W/frTD3TEy6zTvpU750lQ== X-CSE-MsgGUID: 9tI2NG1lRIGoqqN/zkXLIA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,256,1708416000"; d="scan'208";a="28457578" Received: from tassilo.jf.intel.com ([10.54.38.190]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2024 11:15:25 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: nathan@acm.org, josmyers@redhat.com, richard.sandiford@arm.com, jason@redhat.com, Andi Kleen Subject: [PATCH v5 1/5] Improve must tail in RTL backend Date: Sun, 5 May 2024 11:14:54 -0700 Message-ID: <20240505181458.2903045-1-ak@linux.intel.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLACK 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+incoming=patchwork.ozlabs.org@gcc.gnu.org - Give error messages for all causes of non sibling call generation - Don't override choices of other non sibling call checks with must tail. This causes ICEs. The must tail attribute now only overrides flag_optimize_sibling_calls locally. - Error out when tree-tailcall failed to mark a must-tail call sibcall. In this case it doesn't know the true reason and only gives a vague message (this could be improved, but it's already useful without that) tree-tailcall usually fails without optimization, so must adjust the existing must-tail plugin test to specify -O2. PR83324 gcc/ChangeLog: * calls.cc (expand_call): Fix mustcall implementation. gcc/testsuite/ChangeLog: * gcc.dg/plugin/must-tail-call-1.c: Adjust. --- gcc/calls.cc | 30 ++++++++++++------- .../gcc.dg/plugin/must-tail-call-1.c | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gcc/calls.cc b/gcc/calls.cc index 21d78f9779fe..a6b8ee44cc29 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -2650,7 +2650,9 @@ expand_call (tree exp, rtx target, int ignore) /* The type of the function being called. */ tree fntype; bool try_tail_call = CALL_EXPR_TAILCALL (exp); - bool must_tail_call = CALL_EXPR_MUST_TAIL_CALL (exp); + /* tree-tailcall decided not to do tail calls. Error for the musttail case. */ + if (!try_tail_call) + maybe_complain_about_tail_call (exp, "other reasons"); int pass; /* Register in which non-BLKmode value will be returned, @@ -3022,10 +3024,22 @@ expand_call (tree exp, rtx target, int ignore) pushed these optimizations into -O2. Don't try if we're already expanding a call, as that means we're an argument. Don't try if there's cleanups, as we know there's code to follow the call. */ - if (currently_expanding_call++ != 0 - || (!flag_optimize_sibling_calls && !CALL_FROM_THUNK_P (exp)) - || args_size.var - || dbg_cnt (tail_call) == false) + if (currently_expanding_call++ != 0) + { + maybe_complain_about_tail_call (exp, "inside another call"); + try_tail_call = 0; + } + if (!flag_optimize_sibling_calls + && !CALL_FROM_THUNK_P (exp) + && !CALL_EXPR_MUST_TAIL_CALL (exp)) + try_tail_call = 0; + if (args_size.var) + { + /* ??? correct message? */ + maybe_complain_about_tail_call (exp, "stack space needed"); + try_tail_call = 0; + } + if (dbg_cnt (tail_call) == false) try_tail_call = 0; /* Workaround buggy C/C++ wrappers around Fortran routines with @@ -3046,15 +3060,11 @@ expand_call (tree exp, rtx target, int ignore) if (MEM_P (*iter)) { try_tail_call = 0; + maybe_complain_about_tail_call (exp, "hidden string length argument"); break; } } - /* If the user has marked the function as requiring tail-call - optimization, attempt it. */ - if (must_tail_call) - try_tail_call = 1; - /* Rest of purposes for tail call optimizations to fail. */ if (try_tail_call) try_tail_call = can_implement_as_sibling_call_p (exp, diff --git a/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c b/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c index 3a6d4cceaba7..44af361e2925 100644 --- a/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c +++ b/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c @@ -1,4 +1,5 @@ /* { dg-do compile { target tail_call } } */ +/* { dg-options "-O2" } */ /* { dg-options "-fdelayed-branch" { target sparc*-*-* } } */ extern void abort (void);