From patchwork Sat Jan 1 18:22:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 77147 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 DD8F2B70D4 for ; Sun, 2 Jan 2011 05:22:38 +1100 (EST) Received: (qmail 9195 invoked by alias); 1 Jan 2011 18:22:36 -0000 Received: (qmail 9185 invoked by uid 22791); 1 Jan 2011 18:22:36 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 01 Jan 2011 18:22:31 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p01IMUHY021884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 1 Jan 2011 13:22:30 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p01IMTVl010714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 1 Jan 2011 13:22:29 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p01IMSrK023262 for ; Sat, 1 Jan 2011 19:22:28 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p01IMSLE023261 for gcc-patches@gcc.gnu.org; Sat, 1 Jan 2011 19:22:28 +0100 Date: Sat, 1 Jan 2011 19:22:28 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ccp evaluate_stmt for tcc_comparison assignments (PR tree-optimization/47140) Message-ID: <20110101182228.GW16156@tyan-ft48-01.lab.bos.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 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 Hi! For tcc_comparison binary assignments the lhs type is often different from the type of the comparison operands, so when we bit_value_binop with rhs1's type instead of lhs' type, the type of the constant might be incorrect. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-01-01 Jakub Jelinek PR tree-optimization/47140 * tree-ssa-ccp.c (evaluate_stmt): For binary assignments, use TREE_TYPE (lhs) instead of TREE_TYPE (rhs1) as second argument to bit_value_binop. * gcc.c-torture/compile/pr47140.c: New test. Jakub --- gcc/tree-ssa-ccp.c.jj 2010-12-16 10:55:33.000000000 +0100 +++ gcc/tree-ssa-ccp.c 2011-01-01 16:12:57.000000000 +0100 @@ -2156,9 +2156,10 @@ evaluate_stmt (gimple stmt) if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) || POINTER_TYPE_P (TREE_TYPE (rhs1))) { + tree lhs = gimple_assign_lhs (stmt); tree rhs2 = gimple_assign_rhs2 (stmt); val = bit_value_binop (subcode, - TREE_TYPE (rhs1), rhs1, rhs2); + TREE_TYPE (lhs), rhs1, rhs2); } break; --- gcc/testsuite/gcc.c-torture/compile/pr47140.c.jj 2011-01-01 16:18:47.000000000 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr47140.c 2011-01-01 16:19:32.000000000 +0100 @@ -0,0 +1,25 @@ +/* PR tree-optimization/47140 */ + +static inline int +foo (int x, short y) +{ + return y == 0 ? x : x + y; +} + +static inline unsigned short +bar (unsigned short x, unsigned char y) +{ + return x - y; +} + +int w; + +int baz (void); + +int +test (void) +{ + int i; + for (i = 0; i < 50; i++) + w += foo ((unsigned char) (1 + baz ()) >= bar (0, 1), 0); +}