From patchwork Thu Apr 26 18:43:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 155316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 273A9B6FAB for ; Fri, 27 Apr 2012 04:44:14 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1336070655; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:cc:Subject:In-Reply-To:Message-ID:References:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=8KhTQ9Dxw1cyaH/MT7uLATNHz98=; b=jybkmUGZl40IfVe +cIGYM2chA3aTMkI8wMHZR0NNvJ3YZ2i+HOU2pSj6UspO8TeV95Q0egVWcz+3eIv 6DFhXsC1O55uv2b9hvGFlgEJbGX7fJ/OSoFqdUsH6QGVFywMkyHA/Vdibu9KzZJf TSkftzewbN++2HjAGSgsrzQSc2UY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=NRsu8OF9Kg4p8F0/Su7ycTwlMHvqBUl/bFlDHP0XK/Vg8OH07dZ8BhnzscGkET Ea4fQnlz61edN42kw8PR/u6XVN4HQToaf018HRKeGdV/fqgG13dcHkmRpFsBWDPI GNwCa9DQIWBE4H896PLAE/htautiumI0SbluGN5tlFrgY=; Received: (qmail 29500 invoked by alias); 26 Apr 2012 18:44:11 -0000 Received: (qmail 29487 invoked by uid 22791); 26 Apr 2012 18:44:09 -0000 X-SWARE-Spam-Status: No, hits=-7.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail1-relais-roc.national.inria.fr (HELO mail1-relais-roc.national.inria.fr) (192.134.164.82) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Apr 2012 18:43:55 +0000 Received: from ip-216.net-81-220-90.toulouse.rev.numericable.fr (HELO laptop-mg.local) ([81.220.90.216]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 26 Apr 2012 20:43:41 +0200 Date: Thu, 26 Apr 2012 20:43:37 +0200 (CEST) From: Marc Glisse To: Richard Guenther cc: gcc-patches@gcc.gnu.org Subject: Re: combine_conversions int->double->int In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 On Thu, 26 Apr 2012, Richard Guenther wrote: > On Wed, Apr 25, 2012 at 3:58 PM, Marc Glisse wrote: >> Here is take 2 on this patch, which seems cleaner. Bootstrapped and >> regression tested. >> >> gcc/ChangeLog >> >> 2012-04-25  Marc Glisse   >> >>        PR middle-end/27139 >>        * tree-ssa-forwprop.c (combine_conversions): Handle INT->FP->INT. >> >> gcc/testsuite/ChangeLog >> >> 2012-04-25  Marc Glisse   >> >>        PR middle-end/27139 >>        * gcc.dg/tree-ssa/forwprop-18.c: New test. >> >> >> In my patch, the lines with gimple_assign_* are vaguely guessed from what is >> around, I don't pretend to understand them. > > ;) > > The patch looks good to me - on a 2nd thought folding the case back in > to the if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))) > block to benefit from the local vars therein makes sense (but as separate > sub-if () as it is now). Like the attached? (c,c++ bootstrapped, make -k check, no regression) I changed the types in the testcase to make it really unlikely that a platform needs to skip it (it would require a long double that can't represent all signed char, or a float that can represent all unsigned long long). Index: testsuite/gcc.dg/tree-ssa/forwprop-18.c =================================================================== --- testsuite/gcc.dg/tree-ssa/forwprop-18.c (revision 0) +++ testsuite/gcc.dg/tree-ssa/forwprop-18.c (revision 0) @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-forwprop1" } */ + +signed char f1(signed char n) +{ + return (long double)n; +} +unsigned long long f2(signed char n) +{ + return (long double)n; +} + +unsigned long long g1(unsigned long long n) +{ + return (float)n; +} +signed char g2(unsigned long long n) +{ + return (float)n; +} + +/* { dg-final { scan-tree-dump-times "\\\(float\\\)" 2 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-not "\\\(long double\\\)" "forwprop1" } } */ +/* { dg-final { cleanup-tree-dump "forwprop1" } } */ Property changes on: testsuite/gcc.dg/tree-ssa/forwprop-18.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision URL Added: svn:eol-style + native Index: tree-ssa-forwprop.c =================================================================== --- tree-ssa-forwprop.c (revision 186876) +++ tree-ssa-forwprop.c (working copy) @@ -2403,10 +2403,11 @@ combine_conversions (gimple_stmt_iterato { gimple stmt = gsi_stmt (*gsi); gimple def_stmt; tree op0, lhs; enum tree_code code = gimple_assign_rhs_code (stmt); + enum tree_code code2; gcc_checking_assert (CONVERT_EXPR_CODE_P (code) || code == FLOAT_EXPR || code == FIX_TRUNC_EXPR); @@ -2423,11 +2424,13 @@ combine_conversions (gimple_stmt_iterato def_stmt = SSA_NAME_DEF_STMT (op0); if (!is_gimple_assign (def_stmt)) return 0; - if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))) + code2 = gimple_assign_rhs_code (def_stmt); + + if (CONVERT_EXPR_CODE_P (code2) || code2 == FLOAT_EXPR) { tree defop0 = gimple_assign_rhs1 (def_stmt); tree type = TREE_TYPE (lhs); tree inside_type = TREE_TYPE (defop0); tree inter_type = TREE_TYPE (op0); @@ -2551,10 +2554,33 @@ combine_conversions (gimple_stmt_iterato else gimple_assign_set_rhs_from_tree (gsi, tem); update_stmt (gsi_stmt (*gsi)); return 1; } + + /* If we are converting an integer to a floating-point that can + represent it exactly and back to an integer, we can skip the + floating-point conversion. */ + if (inside_int && inter_float && final_int && + (unsigned) significand_size (TYPE_MODE (inter_type)) + >= inside_prec - !inside_unsignedp) + { + if (useless_type_conversion_p (type, inside_type)) + { + gimple_assign_set_rhs1 (stmt, unshare_expr (defop0)); + gimple_assign_set_rhs_code (stmt, TREE_CODE (defop0)); + update_stmt (stmt); + return remove_prop_source_from_use (op0) ? 2 : 1; + } + else + { + gimple_assign_set_rhs1 (stmt, defop0); + gimple_assign_set_rhs_code (stmt, CONVERT_EXPR); + update_stmt (stmt); + return remove_prop_source_from_use (op0) ? 2 : 1; + } + } } return 0; }