From patchwork Tue Apr 29 14:48:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 343860 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2D16E140104 for ; Wed, 30 Apr 2014 00:49:03 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=Yyxx2jX7mQ3hV9RqkyC1JXqDGMfuD97FvPhQewCY4ua Z9MGp2Sqh2FAFYMa+LKRq5iAkAC+jBD7E50eq5jC3aSNkEnwPjnk6GsMMykR1Moh PrJcIM7rPZmoZTbVeXPejSjKpcdWm6iCn8PPjWwSi3P2Uh6+HAtARbGtWcnmS2Oo = 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:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=bBnKDd3cD8e9X2xX95E70FObX+c=; b=AdchEmBERjcieMikq 2niiFYv2bwlecLGlnY1OPhqn0NmjVeW4LRIZy1KEQ3uLV7fty/susXcBjGx4xqn4 sn/eo/yq8D3SUIq77OtAp4FDvRxm+EWoxfCt8M3cWE2vUCQUosf30eQnp1xTcM05 DNcdgT+QJza6vBaExCaQOGoLAE= Received: (qmail 14242 invoked by alias); 29 Apr 2014 14:48: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 14230 invoked by uid 89); 29 Apr 2014 14:48:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Apr 2014 14:48:51 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3TEmoFe022922 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Apr 2014 10:48:50 -0400 Received: from tucnak.zalov.cz (ovpn-116-116.ams2.redhat.com [10.36.116.116]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3TEmmsr030444 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 29 Apr 2014 10:48:49 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.8/8.14.7) with ESMTP id s3TEmkDc014355 for ; Tue, 29 Apr 2014 16:48:46 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.8/8.14.8/Submit) id s3TEmji7014353 for gcc-patches@gcc.gnu.org; Tue, 29 Apr 2014 16:48:45 +0200 Date: Tue, 29 Apr 2014 16:48:45 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Avoid tail call opt if bit field reduction is needed (PR tree-optimization/60971) Message-ID: <20140429144845.GP1817@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! I've committed following fix, approved by Richard on IRC and Jeff in the PR. process_assignment was assuming that no code needs to be emitted for gimple_assign_cast_p if the mode is the same, which is usually true, except for the case when REDUCE_BIT_FIELD in expand_expr_real_2 needs to mask or shift up/down to adjust for reduced precision. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk and 4.9. 2014-04-29 Jakub Jelinek PR tree-optimization/60971 * tree-tailcall.c (process_assignment): Reject conversions which reduce precision. * c-c++-common/turtore/pr60971.c: New test. Jakub --- gcc/tree-tailcall.c.jj 2014-04-17 14:48:59.000000000 +0200 +++ gcc/tree-tailcall.c 2014-04-29 12:13:12.649414120 +0200 @@ -285,9 +285,19 @@ process_assignment (gimple stmt, gimple_ { /* Reject a tailcall if the type conversion might need additional code. */ - if (gimple_assign_cast_p (stmt) - && TYPE_MODE (TREE_TYPE (dest)) != TYPE_MODE (TREE_TYPE (src_var))) - return false; + if (gimple_assign_cast_p (stmt)) + { + if (TYPE_MODE (TREE_TYPE (dest)) != TYPE_MODE (TREE_TYPE (src_var))) + return false; + + /* Even if the type modes are the same, if the precision of the + type is smaller than mode's precision, + reduce_to_bit_field_precision would generate additional code. */ + if (INTEGRAL_TYPE_P (TREE_TYPE (dest)) + && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (dest))) + > TYPE_PRECISION (TREE_TYPE (dest)))) + return false; + } if (src_var != *ass_var) return false; --- gcc/testsuite/c-c++-common/torture/pr60971.c.jj 2014-04-29 11:15:06.448764325 +0200 +++ gcc/testsuite/c-c++-common/torture/pr60971.c 2014-04-29 11:14:49.000000000 +0200 @@ -0,0 +1,34 @@ +/* PR tree-optimization/60971 */ +/* { dg-do run } */ + +#ifndef __cplusplus +#define bool _Bool +#endif + +volatile unsigned char c; + +__attribute__((noinline)) unsigned char +foo (void) +{ + return c; +} + +__attribute__((noinline)) bool +bar (void) +{ + return foo () & 1; +} + +int +main () +{ + c = 0x41; + c = bar (); + if (c != 1) + __builtin_abort (); + c = 0x20; + c = bar (); + if (c != 0) + __builtin_abort (); + return 0; +}