From patchwork Wed Jan 31 02:17:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 194437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1626071dyb; Tue, 30 Jan 2024 18:19:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFmpRBgHTgDFYHusZnRY+hqlNTrbkEmvUQpQuYG63rnEo3/vk97mVbcBSNmnkX8q8qKdFe X-Received: by 2002:a05:622a:1749:b0:42b:e44f:2032 with SMTP id l9-20020a05622a174900b0042be44f2032mr503542qtk.3.1706667582175; Tue, 30 Jan 2024 18:19:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667582; cv=pass; d=google.com; s=arc-20160816; b=UMiR8NRMR4jEQ7QWt2muoP/6er9mNIkknkYTKlkLr48h7b0HBpSS/fyYweY8M0nEHw vDDQi/PBEHVHS8bVraJPqzAuKIQVbjK3DatHO8oLTb6LvuxXcFVrrUJ4fCy8j4o8AV1D 8wxPZWXE5hB4+7Ve7lAaHM8vk6u8xi4wsU8YPBJNdfzA1HeiE7E15cqg6rIkK61uNXKA fHF7pgrcyUJqMLEtgL+1Sl0ran+Au/6XiKP3T+AxJ2PJQ5ssGZAuuwXVgnaINqr6zwCq KXjFthe7pBZf+lldaAQI8l7APYp7w9m2178Zips3oWpVx3shpLWSFOFfNYE5nNErLQn2 rGzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=oaY+o/zuIHS3wyu0316+c2EgVeX6m0uD5l9K58aBCjk=; fh=ub4Aq2OhlMJoNKivzGR3ET+LTyw5zYDGsqMhDfbEk4w=; b=wsFiCf4y79D7G/lWG342Z8JCX1Lh2vdMybJv7KTQ0rxWO4T5kdBHhpgyyn4p/diOMg ntj9IXzubUbcPG0ULneXeKlk9WX4c9veCLfZmJLgSOuRx+AqMXuNBqq0ktMZlfZoB5Du rZcddOfBljqxEj7gT3RiXRWzgoZvFvISRNekxit2oW12qgm4wejqUWFeJr3hchaXBje0 gGKXUU5S5lnJdKzmrN8GrjT+jHTD6vHqEsMsn7ojKz5/nV2Y4LP4R88qz7HS9kLO34Q/ fk/b5RsCI/siZfLYIf8bOBnZOsOdSdEEfKtM0LT6g33J/Li5YBXJtZCAxPDqWvo1Qdqb QYQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FIRge+Q6; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCXCFzs2WYlFhCuemrgsz2qbf307a0LOrEjee3uyDGvsY20S8sH2EHePR9m0K1nI9ONmr1jdTCOYYVkVkX1MQNcsAkrdfg== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h17-20020a05622a171100b0042be5cbccdasi621704qtk.308.2024.01.30.18.19.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:19:42 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FIRge+Q6; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4F253858020 for ; Wed, 31 Jan 2024 02:19:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id A891F3858407 for ; Wed, 31 Jan 2024 02:18:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A891F3858407 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 A891F3858407 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=1706667518; cv=none; b=I4bDDGXdWw0NoZ2qS7sdZjO3FdXmiMtkwjK67HQZtSmLuVEqp3HuIlhhGKuyilrcONjsU5ppT3VawHtT+ndDrw/gDsWbuDViDxwEVV7KJlQ66zzDn7qR2WfHGp9067d68RDO/nyu4/ozyWdLSFnaccn4VNiAMfrtEoKsDz+xEmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706667518; c=relaxed/simple; bh=6gu7FOKHdLCFrcIlsO2VIdvK7EIHzHG7Q2copvMq/YA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZItGGDxzeMkvJIWXRuNSw2AdrOJqy0nkejgpYc8JRalSHUIarr5BL2vkjQWy78STCnDiD36UWxPtHlAeElXf8PSJs+pC8hNs+zCnNpEY4pV6wBdIqHYn+v9W4fMd8F1OwbhW7oO0Ye2kSZ84fnqzOQxs3OvUrIdH/GZABC/VqqM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mgamail.intel.com ([198.175.65.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV0BO-0002Tg-0L for gcc-patches@gnu.org; Tue, 30 Jan 2024 21:18:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706667515; x=1738203515; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6gu7FOKHdLCFrcIlsO2VIdvK7EIHzHG7Q2copvMq/YA=; b=FIRge+Q64uhQO0vmrEICX0VS8n3c6lAY4dcWFiVWL76GvfzjMRQdc3j1 23MNT5ZPkT1bhW2y/x131xqpaYwbEuklT8yzsdypSMp/8SDSTclXZiRsg iDbZFum3MNN0XrFTAOcz+CS7aadms5s8UQAAPa+SLDigNbh5ZP/6uq4pE 82f5NAUad1ZwQW6nE/U7alNdVvwb5SqiST4p6r1bPYwWwjnN0QQIHYSpw wVmRYRgbR+UjtBz1Vwf6x+4NwF7Vo6QtT2FlKBz4SoQzZm6acYvGXXRWb 5AtIySv9I3XmM9LA8BH/bLegrXRFttifogrnGEIG2Rdcnxgzk4fMR+PfE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="10561930" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="10561930" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 18:18:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="737946816" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="737946816" Received: from tassilo.jf.intel.com ([10.54.38.190]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 18:18:15 -0800 From: Andi Kleen To: gcc-patches@gnu.org Cc: Andi Kleen Subject: [PATCH v3 1/5] Improve must tail in RTL backend Date: Tue, 30 Jan 2024 18:17:14 -0800 Message-ID: <20240131021808.151575-2-ak@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021808.151575-1-ak@linux.intel.com> References: <20240131021808.151575-1-ak@linux.intel.com> MIME-Version: 1.0 Received-SPF: none client-ip=198.175.65.13; envelope-from=ak@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, 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=-12.1 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 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570666933553133 X-GMAIL-MSGID: 1789570666933553133 - 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);