From patchwork Fri Nov 3 05:15:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 117851 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3024631qgn; Thu, 2 Nov 2017 22:18:58 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RPpFMgHHblBifmjgz+KwQnb4ksyxBYNDkPPdvvPt7f7STMZ1rQZyQrzbCcFE+hheiUdpQ2 X-Received: by 10.98.68.8 with SMTP id r8mr6358194pfa.161.1509686338055; Thu, 02 Nov 2017 22:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509686338; cv=none; d=google.com; s=arc-20160816; b=JY51yJRDC2r4qZ/7aUxQI4Zjt/TdcTlceNWWbw8OpadJkyzFXr7FHAMXOnnwyoLfbb SMC5lGvVtds/jHhndX7v0GoRsECHXWIMOP2nVuAp6/IebbDVUJFa0yaHv0b6PHktZM2c 5O8FM+EYycBuZoEOjv+GlzGAgIpeLoZKSuixEyLR9tM0n5649h6tu9e2pE7R6Cpl0R1H IeVHsKDXzD50E8QxXs0M+CZ3MLCOhxEIjHMFidpgQ++3dAczs/EaI3SlvQ9M74U2sF9f 9KQBb5lJkVQWlqpGrBt4D0WQHoNN5e1YPXBqkG1Y9CplweIRe93DJW6kK7xA3t7J2vgX iiUg== 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=mbQcjxE8GkGykK5Y9uOTLXBU7BwQm7gQXfiVpJrMWyE=; b=xS5KEyUqp9Ht4yAmWs+awuijOn7kuSD5Ige3LIouviT+FDg4r7VS1garhmzrq87gih gJfFcE9ZTHEYQekh0HAyGrjM3zzu3jb1zmTyPif8xQA0RFWHp3/mIUFZ8ITKgzUnrq0B lYsOqIc1NjTkzuBrkFk3QA/kffBR3/mQAjLV8+2o7BnCtMWofqygem6XaMQNsyh71Fmo wIjh+AI4fpC1hbPJ2HUvmBTCfUt+kSxtilvDBPwtos8nVYANzOyQ6Z6Q7D7qih7BEgvW HUpfrJlwS6drd1ljbO68EUrxpT66ts+4NUZshwME8/5KakUJlVTg45lE/YgOHKQOSp50 3LWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PLFNYOJS; spf=pass (google.com: domain of gcc-patches-return-465811-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465811-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 r63si3997270plb.638.2017.11.02.22.18.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Nov 2017 22:18:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-465811-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=PLFNYOJS; spf=pass (google.com: domain of gcc-patches-return-465811-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465811-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=qxdccqyOcROgvUz+mGRCtNJ6tqhJoVHLtZDfLJkEoDlDbj dmPSDXQsdCIRPypl1Z1yoGsz9AYYihzfYBqEpVOVocO55EJbO1M1kwqsWpPwz0er /KxNzlIc9i3NrPoeYtHcKx62K8o2CqXEXvStHXbFmknyIDu/8SMAR0MZ312P0= 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=88bQ3TY0L1uiM4R59DUs+u6tiUE=; b=PLFNYOJS8iPXJs//xGWS w6xIf0Yi2bkQ8DUq9APIf3mig7xOEMxKxhELq8uOZLzheaQkgEGqKoBwmlujVDEL k0hcBmSANFdmHGSliVrSNe27xRbdoVbadgUHx2UgQjFaOnHCQu1csOl4Zm97gxug 4ViE3rxx6NRom5RKC7WeVTY= Received: (qmail 38331 invoked by alias); 3 Nov 2017 05:16:52 -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 37811 invoked by uid 89); 3 Nov 2017 05:15:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=15677, 15817 X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Nov 2017 05:15:41 +0000 Received: by mail-wm0-f54.google.com with SMTP id t139so2763753wmt.1 for ; Thu, 02 Nov 2017 22:15:40 -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=jWTLzRGYVf5IhyjCJuGLAzFZ6czhBaRv8AxUhH3CL1E=; b=ZLvs086ngqIkU6fl2sqfPPBeFaGk24IXXhhjdUR2vcIh8LYlFz6CDND/GuoLmms95y rnnYbQQwzNTLDCLTbnjL6tECZq6WNJKRstSOBZVsH5AV7Av2AZyvYtb1vOOHrQkr4ZsO 8kph/SFmyCmBnLiD9uivKzp9X9USan2optk/bR4yYG47RoMTDzFfcl51HvCNnjtjw5wm cJMi1IiEcMoUFq1/VJ7UcouiDyxg9G2lKPbiGcrttlLh3rKPEs08WNw3VmOTRiRYOWzj 37ozWezWiZChq3wfFDiygqhkLqaFYS6QfekaSnocdCawoodp71FOiExncpCm4FZKsVKu IUGg== X-Gm-Message-State: AMCzsaV57httuYqTQxurpyx+x8rS4vjKlZ9wvC7gN2mltIs7Ol2DxNwy ldmvIvfnYsZp+QaS3bGeWdni2om+pwBGP4IOBuaHnN4PC6s= X-Received: by 10.28.56.198 with SMTP id f189mr3645539wma.16.1509686138858; Thu, 02 Nov 2017 22:15:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.151.103 with HTTP; Thu, 2 Nov 2017 22:15:36 -0700 (PDT) From: Prathamesh Kulkarni Date: Fri, 3 Nov 2017 10:45:36 +0530 Message-ID: Subject: PR82808 To: gcc Patches , Martin Jambor X-IsSubscribed: yes Hi Martin, As mentioned in PR, the issue here for propagating value of 'm' from f_c1 to foo() is that the jump function operation is FLOAT_EXPR, and the type of input param 'm' is int, so fold_unary() doesn't do the conversion to real_type. The attached patch fixes that by calling fold_convert if operation is FLOAT_EXPR / FIX_TRUNC_EXPR / CONVERT_EXPR and converts it to the type of corresponding parameter in callee. There are still two issues: a) Using NOP_EXPR for early_exit in ipa_get_jf_pass_through_result. I suppose we need to change to some other code to indicate that there is no operation ? b) Patch does not passing param_type from all callers. I suppose we could fix these incrementally ? Bootstrap+tested on x86_64-unknown-linux-gnu. OK for trunk ? Thanks, Prathamesh 2017-11-03 Prathamesh Kulkarni * ipa-cp.c (ipa_get_jf_pass_through_result): Add new parameter parm_type with default value set to NULL. Call fold_convert if jfunc operation is FLOAT_EXPR or FIX_TRUNC_EXPR or CONVERT_EXPR. (propagate_vals_across_pass_through): Add parameter parm_type. (propagate_scalar_across_jump_function): Add parameter parm_type and pass it to propagate_vals_across_pass_through. (propagate_constants_across_call): Pass param_type to propagate_scalar_across_jump_function. testsuite/ * gcc.dg/ipa/pr82808.c: New test. diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 6b3d8d7364c..20328a43f9b 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -1224,7 +1224,8 @@ initialize_node_lattices (struct cgraph_node *node) determined or be considered an interprocedural invariant. */ static tree -ipa_get_jf_pass_through_result (struct ipa_jump_func *jfunc, tree input) +ipa_get_jf_pass_through_result (struct ipa_jump_func *jfunc, tree input, + tree parm_type = NULL_TREE) { tree restype, res; @@ -1233,7 +1234,17 @@ ipa_get_jf_pass_through_result (struct ipa_jump_func *jfunc, tree input) if (!is_gimple_ip_invariant (input)) return NULL_TREE; - if (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc)) + if (ipa_get_jf_pass_through_operation (jfunc) == FLOAT_EXPR + || ipa_get_jf_pass_through_operation (jfunc) == FIX_TRUNC_EXPR + || ipa_get_jf_pass_through_operation (jfunc) == CONVERT_EXPR) + { + if (!parm_type) + return NULL_TREE; + + res = fold_convert (parm_type, input); + restype = parm_type; + } + else if (TREE_CODE_CLASS (ipa_get_jf_pass_through_operation (jfunc)) == tcc_unary) res = fold_unary (ipa_get_jf_pass_through_operation (jfunc), TREE_TYPE (input), input); @@ -1567,7 +1578,8 @@ ipcp_lattice::add_value (valtype newval, cgraph_edge *cs, static bool propagate_vals_across_pass_through (cgraph_edge *cs, ipa_jump_func *jfunc, ipcp_lattice *src_lat, - ipcp_lattice *dest_lat, int src_idx) + ipcp_lattice *dest_lat, int src_idx, + tree parm_type) { ipcp_value *src_val; bool ret = false; @@ -1581,7 +1593,8 @@ propagate_vals_across_pass_through (cgraph_edge *cs, ipa_jump_func *jfunc, else for (src_val = src_lat->values; src_val; src_val = src_val->next) { - tree cstval = ipa_get_jf_pass_through_result (jfunc, src_val->value); + tree cstval = ipa_get_jf_pass_through_result (jfunc, src_val->value, + parm_type); if (cstval) ret |= dest_lat->add_value (cstval, cs, src_val, src_idx); @@ -1627,7 +1640,8 @@ propagate_vals_across_ancestor (struct cgraph_edge *cs, static bool propagate_scalar_across_jump_function (struct cgraph_edge *cs, struct ipa_jump_func *jfunc, - ipcp_lattice *dest_lat) + ipcp_lattice *dest_lat, + tree param_type) { if (dest_lat->bottom) return false; @@ -1662,7 +1676,7 @@ propagate_scalar_across_jump_function (struct cgraph_edge *cs, if (jfunc->type == IPA_JF_PASS_THROUGH) ret = propagate_vals_across_pass_through (cs, jfunc, src_lat, - dest_lat, src_idx); + dest_lat, src_idx, param_type); else ret = propagate_vals_across_ancestor (cs, jfunc, src_lat, dest_lat, src_idx); @@ -2279,7 +2293,7 @@ propagate_constants_across_call (struct cgraph_edge *cs) else { ret |= propagate_scalar_across_jump_function (cs, jump_func, - &dest_plats->itself); + &dest_plats->itself, param_type); ret |= propagate_context_across_jump_function (cs, jump_func, i, &dest_plats->ctxlat); ret diff --git a/gcc/testsuite/gcc.dg/ipa/pr82808.c b/gcc/testsuite/gcc.dg/ipa/pr82808.c new file mode 100644 index 00000000000..e9a90e3ce2e --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr82808.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -flto -fno-inline" } */ + +void foo(double *a, double x) +{ + *a = x; +} + +double f_c1(int m, double *a) +{ + foo(a, m); + return *a; +} + +int main(){ + double data; + double ret = 0 ; + + if ((ret = f_c1(2, &data)) != 2) + { + __builtin_abort (); + } + return 0; +}