From patchwork Mon Jul 8 16:55:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1958056 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=cPGWvcNM; 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 4WHr5x1y0qz1xpP for ; Tue, 9 Jul 2024 03:02:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E0193864816 for ; Mon, 8 Jul 2024 17:02:43 +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.11]) by sourceware.org (Postfix) with ESMTPS id 1FA60385C6D2 for ; Mon, 8 Jul 2024 17:00:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FA60385C6D2 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 1FA60385C6D2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720458051; cv=none; b=Sd0N59hHBPDdwwyDtllaQWgcJG00PoYComXSddktzyXGJIn+cS0kX1/Cra6Covi2jxKa7OnnNwliMkB52VqZP6XM32TA5Nxoh0XLOkhweJ6E4AR4FQrMfC3Z7q3Il4UmjiJZiZnZK166Hj6j3ll3TQlB/p4Lm7QZxe3+9pMQbrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720458051; c=relaxed/simple; bh=E1YIWS6tT9/dkiL3kVwo8TIwtDjiyXCn5kgTQMJpiek=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TTisUoH4IOlp9ddqCKX27XEEjELGCmK3nwkn/0vyKDeRWZ1ORH7eRuSxZLj5Fl9Hd1OVRD6gmV4n/E2VpqhwhQ4301Xlp4tv9kzzBy1q+RMOrUD/k0SN+wL/v9o6pTD3F2IWTdnuO5djFelUUzBTT35phryx9eFl5eHLmndvc5c= 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=1720458050; x=1751994050; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E1YIWS6tT9/dkiL3kVwo8TIwtDjiyXCn5kgTQMJpiek=; b=cPGWvcNMWtNAPFgHwuwLYzYGj+CsLwQkjZCKdT00v6YpeZpWO0IRNqUE g9h4YP9VsuICJto4IJ7Acao6fFUgJHRlWQR780sBjHl18G+USV7IH5iOn JSTaNvq0Z+/6989omLDe983yJV+5/NikwljWdYPTbhnHuNSaYo/5nHtLe nzNJ6OR7jBkvRKoEamje0azRAWgxvGJnn6TPr2nTPDMIAfnOl2WA5LgHQ yfnpP/IVBCAbW6BTeZWlom4556KigvKm2jfoZ4o5IDvcgPlfhRFRahbd1 i2fzNEaCU/0/CSU7E+Md8W0NUn7TEnR/iIzhXjctoDmBH6G51BH9dqjvQ A==; X-CSE-ConnectionGUID: YZllFWWWSYKAmAO14ZSqVg== X-CSE-MsgGUID: pxmQJEKLTM+z2KZI0MXPVw== X-IronPort-AV: E=McAfee;i="6700,10204,11127"; a="28279669" X-IronPort-AV: E=Sophos;i="6.09,192,1716274800"; d="scan'208";a="28279669" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2024 10:00:37 -0700 X-CSE-ConnectionGUID: hpO4Xz2/ToqS0nUInHHAhg== X-CSE-MsgGUID: Xq92J16uSQOKLcEk57AhQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,192,1716274800"; d="scan'208";a="47486293" Received: from tassilo.jf.intel.com ([10.54.38.190]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2024 10:00:37 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, josmyers@redhat.com, polacek@redhat.com, jakub@redhat.com, Andi Kleen Subject: [PATCH v9 01/10] Improve must tail in RTL backend Date: Mon, 8 Jul 2024 09:55:53 -0700 Message-ID: <20240708170031.1621184-2-ak@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240708170031.1621184-1-ak@linux.intel.com> References: <20240708170031.1621184-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 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 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 - When giving error messages clear the musttail flag to avoid ICEs - 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. PR83324 gcc/ChangeLog: * calls.cc (maybe_complain_about_tail_call): Clear must tail flag on error. (expand_call): Give error messages for all musttail failures. --- gcc/calls.cc | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/gcc/calls.cc b/gcc/calls.cc index 21d78f9779fe..883eb9971257 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -1249,6 +1249,7 @@ maybe_complain_about_tail_call (tree call_expr, const char *reason) return; error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); + CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0; } /* Fill in ARGS_SIZE and ARGS array based on the parameters found in @@ -2650,7 +2651,13 @@ 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, + unfortunately we don't know the reason so it's fairly vague. + When tree-tailcall reported an error it already cleared the flag, + so this shouldn't really happen unless the + the musttail pass gave up walking before finding the call. */ + 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 +3029,21 @@ 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) + { + maybe_complain_about_tail_call (exp, "variable size arguments"); + try_tail_call = 0; + } + if (dbg_cnt (tail_call) == false) try_tail_call = 0; /* Workaround buggy C/C++ wrappers around Fortran routines with @@ -3046,13 +3064,15 @@ 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 passed on stack"); break; } } /* If the user has marked the function as requiring tail-call optimization, attempt it. */ - if (must_tail_call) + if (CALL_EXPR_MUST_TAIL_CALL (exp)) try_tail_call = 1; /* Rest of purposes for tail call optimizations to fail. */