From patchwork Fri May 18 08:49:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 136256 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp963866lji; Fri, 18 May 2018 01:50:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpbNRDTecHxhswmKnOjtV7c9nhInmDUnV7cqvKI5c9EHVuFfjJ+KqYNn0rLqEeKvA9eIpTd X-Received: by 2002:a17:902:8f94:: with SMTP id z20-v6mr8703164plo.391.1526633446396; Fri, 18 May 2018 01:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526633446; cv=none; d=google.com; s=arc-20160816; b=W31zIdG5g4eBd7NUroBIAJ8tsT1bqoxPh8Gh4mqnw3c4h2w6/LspnlDkEOqB9nDQSB XxTK50xHdxzJmKn7rEcKiQBvlh34R1GP7dpeJLX0ilWxE87CPLZ8aM023fAXtlhq0SC9 Dkhd7fyDu0lbLDqj6+tpJHbsIQiflPrJYH3VfYDubpQkhezLG0lENFfPR6au/VTMhvxZ Osx/+86mGhRHKu7rIQdPJrMtcD3u149r/f3Fk6WNmZbXpQXlZpsH36xo/w9fEPC6XYdx WW+N4YiEikQfAOtyBpYf8eIpfQwNj2R2OEtEkb/c0NV3oNBZC/tuKQtA9OZHBBKUz/dg Bmbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=p7dTXxCOijETsweYTDexJuYUrDXWLkABopStaGeiROk=; b=grArcBvoz9AMYfVvQmPYEWDD48bzGiyTsno4PCe8IzKonhlRdjL/By9KDVbWa/U4EP 0amlcBgeOWDbyYjO6osEk7esf8V9lwcVad6+uUYyna5Uwaw5iYCbw6M8u1CelrlEU3z0 WHBkJpv7QjTUD5bP/yuLfN4Ee+cLvFC9ldBaLQWNIg7rrTpBoccGmp7c4AM/8DaOS/xL ea6PgcAYiQvV/MFmAtaSyu94u2n6dXwrdmTBkj5a4iskYSb277tmznjzVOTeOmwucf35 AOEIhwRDSyd2X6COfOlwXXY3wHIsd0LkRFvvFMXmZXDvsEeAt8C1HN9eUx6yiyXAU+HA cLuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XB+eAL++; spf=pass (google.com: domain of gcc-patches-return-477910-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-477910-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v10-v6si6646728ply.328.2018.05.18.01.50.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 01:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-477910-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XB+eAL++; spf=pass (google.com: domain of gcc-patches-return-477910-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-477910-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=iHrqJH10UL9x8cMr9GRLSGNadq+HTj1oNc4i5NxY5Bvvn8 4Ge50XEdQf7/gQa0FUvt/LvlB4rAnlCLAenaMxIvX/5I68EgFtvnRskw2Ds8kGc9 JXmjmmnsjJ/F6ccMoUP9zeyXR1DkNK0186JCvpy5hUmLtWwn8qsgNwZ65PGSA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=SUpJkXQEEQkWMUjtdL6GLBtOHVk=; b=XB+eAL++d70ZRRr0Lb9G 9dFLiy47DZaxhZEFFH96z8du/OmX7q3xVhBaWiR/ORuTg7bwFB5pi3DCkszDoB+4 SQjf8+ZqXsnt52KHyvQVC90R071l1popcGngOVYONecly1+SagNkxkwMNno24jgw J3z6lGUSOZJnSt8pQmaLY9w= Received: (qmail 15409 invoked by alias); 18 May 2018 08:50:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 110385 invoked by uid 89); 18 May 2018 08:49:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:e7-v6mr, UD:ipa-pure-const.c, sk:ipapur, sk:ipa-pur X-HELO: mail-wr0-f181.google.com Received: from mail-wr0-f181.google.com (HELO mail-wr0-f181.google.com) (209.85.128.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 May 2018 08:49:27 +0000 Received: by mail-wr0-f181.google.com with SMTP id p18-v6so8350447wrm.1 for ; Fri, 18 May 2018 01:49:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=aXx84+T4pZQGFFqLwxZX2BZNacG/cOcyrT3cPu8tpCs=; b=gH/CoB9sDlCvb/SVgxioTejtb8lkB/puTBhq6Oo06iKTRG1KzFVcC18aB9utopANaA krvFqQhaqkkQ1bmEqAMelQZDjmHmMdPQx+rg9qT/BrlbkXy7llVgvF7YDGh5b388dU2d mtsmZtB7lYFuqchCLImzNfOlwcpdiiNzO1mwtyMMqJSpNqAndEYwKhtxHivt6tlZ1p83 oeov0z+I+tJANHmI4AF3JCworv2fb/AZB2gG8obIko6+A24laky+IFQ3KLUxp5pDBiCu OXKPGdmZKviRQSPlu9HvoUKIuH6/LyZOSBKBDNxD5U/Dedd25P0mBYoyzXfjLEO/WZ1N T31w== X-Gm-Message-State: ALKqPwfdF3VNdR+ABl/kdWtKk1dYvt5fhDiBT2Xt/jljMZnAghb9Nq0r 6TjT0PEYehT4aUHu+9emR4zGhRNF/GT/YwrPPWIome1y X-Received: by 2002:adf:e0c7:: with SMTP id e7-v6mr4194056wri.70.1526633364674; Fri, 18 May 2018 01:49:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.222.16 with HTTP; Fri, 18 May 2018 01:49:24 -0700 (PDT) From: Prathamesh Kulkarni Date: Fri, 18 May 2018 14:19:24 +0530 Message-ID: Subject: PR85817 To: gcc Patches , Richard Biener X-IsSubscribed: yes Hi, In r260250, the condition if (integer_zerop (retval)) continue; was added before checking retval was of pointer type which caused functions having return type apart from void *, to be marked as malloc. The attached patch gets rid of the above check since we do not wish to mark function returning NULL as malloc. Also, it adds a check to return false if all args to phi are 0, although I am not sure if this'd actually trigger in practice since constant propagation should have folded the phi into constant 0 already. Bootstrap+test in progress on x86_64-linux-gnu and aarch64-linux-gnu. OK to commit if passes ? Thanks, Prathamesh 2018-05-18 Prathamesh Kulkarni PR middle-end/85817 * ipa-pure-const.c (malloc_candidate_p): Remove the check integer_zerop for retval and return false if all args to phi are zero. testsuite/ * gcc.dg/tree-ssa/pr83648.c: Change scan-tree-dump to scan-tree-dump-not for h. diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index 567b615fb60..528ea6695ac 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -940,9 +940,6 @@ malloc_candidate_p (function *fun, bool ipa) if (!retval) DUMP_AND_RETURN("No return value.") - if (integer_zerop (retval)) - continue; - if (TREE_CODE (retval) != SSA_NAME || TREE_CODE (TREE_TYPE (retval)) != POINTER_TYPE) DUMP_AND_RETURN("Return value is not SSA_NAME or not a pointer type.") @@ -972,37 +969,44 @@ malloc_candidate_p (function *fun, bool ipa) } else if (gphi *phi = dyn_cast (def)) - for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) - { - tree arg = gimple_phi_arg_def (phi, i); - if (integer_zerop (arg)) - continue; + { + bool all_args_zero = true; + for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) + { + tree arg = gimple_phi_arg_def (phi, i); + if (integer_zerop (arg)) + continue; + + all_args_zero = false; + if (TREE_CODE (arg) != SSA_NAME) + DUMP_AND_RETURN ("phi arg is not SSA_NAME."); + if (!check_retval_uses (arg, phi)) + DUMP_AND_RETURN ("phi arg has uses outside phi" + " and comparisons against 0.") + + gimple *arg_def = SSA_NAME_DEF_STMT (arg); + gcall *call_stmt = dyn_cast (arg_def); + if (!call_stmt) + return false; + tree callee_decl = gimple_call_fndecl (call_stmt); + if (!callee_decl) + return false; + if (!ipa && !DECL_IS_MALLOC (callee_decl)) + DUMP_AND_RETURN("callee_decl does not have malloc attribute" + " for non-ipa mode.") + + cgraph_edge *cs = node->get_edge (call_stmt); + if (cs) + { + ipa_call_summary *es = ipa_call_summaries->get (cs); + gcc_assert (es); + es->is_return_callee_uncaptured = true; + } + } - if (TREE_CODE (arg) != SSA_NAME) - DUMP_AND_RETURN ("phi arg is not SSA_NAME."); - if (!check_retval_uses (arg, phi)) - DUMP_AND_RETURN ("phi arg has uses outside phi" - " and comparisons against 0.") - - gimple *arg_def = SSA_NAME_DEF_STMT (arg); - gcall *call_stmt = dyn_cast (arg_def); - if (!call_stmt) - return false; - tree callee_decl = gimple_call_fndecl (call_stmt); - if (!callee_decl) - return false; - if (!ipa && !DECL_IS_MALLOC (callee_decl)) - DUMP_AND_RETURN("callee_decl does not have malloc attribute for" - " non-ipa mode.") - - cgraph_edge *cs = node->get_edge (call_stmt); - if (cs) - { - ipa_call_summary *es = ipa_call_summaries->get (cs); - gcc_assert (es); - es->is_return_callee_uncaptured = true; - } - } + if (all_args_zero) + DUMP_AND_RETURN ("Return value is a phi with all args equal to 0."); + } else DUMP_AND_RETURN("def_stmt of return value is not a call or phi-stmt.") diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c b/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c index febfd7d9319..884faf81167 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c @@ -12,4 +12,4 @@ void *h() } /* { dg-final { scan-tree-dump "Function found to be malloc: g" "local-pure-const1" } } */ -/* { dg-final { scan-tree-dump "Function found to be malloc: h" "local-pure-const1" } } */ +/* { dg-final { scan-tree-dump-not "Function found to be malloc: h" "local-pure-const1" } } */