From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 68B183858C20 for ; Wed, 24 Jan 2024 19:31:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68B183858C20 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 68B183858C20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706124713; cv=none; b=Vb9ElUTGnmK6iloCwj9xgQtnu0SqyPklAqImcFE8XgyKHjonHgRzPTAjDfoj2yF3UmGfzk5rFQSb98OkNBk8esVwFE+xHLkCR6EPj/hVYSh48NIfaxWDLHK2t+FlT+P7dsEWTNEYc/i4h8hFdEaGdt5RACXJ1FvXw3P54chxNzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706124713; c=relaxed/simple; bh=6gu7FOKHdLCFrcIlsO2VIdvK7EIHzHG7Q2copvMq/YA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=A3VdrsYBLPj2m44KUL9lr0E5XJYXTrWiwZi5wdL/cnN0/Ht0W5ac9VwOLkz3paCnbfgccJrwrfObeJLLgBJ2k3mr9Oim39Qip7MzgjOBmhQfKJM5fiwHIiClU2dEc27XpEuZYX4H7z/m1zECnAOG3Ld6kd1Y3TjpR2SHTmGageQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mgamail.intel.com ([192.55.52.88]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSiyT-0007ZG-Mb for gcc-patches@gnu.org; Wed, 24 Jan 2024 14:31:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706124709; x=1737660709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6gu7FOKHdLCFrcIlsO2VIdvK7EIHzHG7Q2copvMq/YA=; b=Suhu6QNGkkKkSux5nESLtWzLARAQhueVqVaG5eivzpNz897L+2kPano5 YtCWePjUTzQgdynSRvXsW1MMYggp3E7wzQ7N11kEWyEFb9uDEPr1vnzM5 Mj84U6VZ3Ad+VnzCqWaPtskUEfm5PVl+Tcn+1kPFvVokBkE1/vjmp8Ck9 8ksQb8W2WzA0RvK1B4B/9jGM6FmZUU/996sz9iEpjvONjCP/j6Vl7YYT4 BqZhA5Iy9PqFxAcrgx2OTGrf5C7Xzyj/Ah13toOwzPMcfmsnhEJCjzMJI AWrO8i5urNuzZvB+3WIduUxIxrsf+NoeucLy7xYS7aUF0zOmC14tdKZKq w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="433111203" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="433111203" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 11:31:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="856810878" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="856810878" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 11:31:42 -0800 From: Andi Kleen To: gcc-patches@gnu.org Cc: Andi Kleen Subject: [PATCH v2 1/5] Improve must tail in RTL backend Date: Wed, 24 Jan 2024 11:30:41 -0800 Message-ID: <20240124193134.622934-2-ak@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124193134.622934-1-ak@linux.intel.com> References: <20240124193134.622934-1-ak@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: none client-ip=192.55.52.88; envelope-from=ak@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -57 X-Spam_score: -5.8 X-Spam_bar: ----- X-Spam_report: (-5.8 / 5.0 requ) BAYES_00=-1.9,DKIMWL_WL_HIGH=-1.5,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_EF=-0.1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_MSPIKE_H3=0.001,RCVD_IN_MSPIKE_WL=0.001,SPF_HELO_NONE=0.001,SPF_NONE=0.001,T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_NONE,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 List-Id: - 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. --- gcc/calls.cc | 31 +++++++++++++------ .../gcc.dg/plugin/must-tail-call-1.c | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/gcc/calls.cc b/gcc/calls.cc index 01f447347437..3115807b7788 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, "cannot tail-call: other reasons"); int pass; /* Register in which non-BLKmode value will be returned, @@ -3021,10 +3023,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, "cannot tail-call: 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, "cannot tail-call: 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 @@ -3045,15 +3059,12 @@ expand_call (tree exp, rtx target, int ignore) if (MEM_P (*iter)) { try_tail_call = 0; + maybe_complain_about_tail_call (exp, + "cannot tail-call: 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); -- 2.43.0