From patchwork Wed Apr 3 19:18:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 233573 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 885142C010E for ; Thu, 4 Apr 2013 06:18:48 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Efelb8itb0Uvv/eWktZc1sr0+MXozfrQvxumcc9WDYKWUo MgtSfErXkg1rMUO3jAfQqT23iRHXzUQIIKuPZkcX/ZpFk1KI2TIe5qevmV8Asruh jhHkzBQLnsGPpo2DVoh7tvRxKr6ymXGLe4eHH7szxXRTV0u+kX7TJWXLE/9Ao= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=3270vXeX5Fm3N9Zf4UVSM6PcYEA=; b=qMZuBz9sQM/jNW5wagO9 RJUbEBNJPqzSEO6B1PNAQyz/ngzKeyGe3Um3XJcG0qz4TQ2wxTzDvMEt6NRZPVCA hJ93aeDnknmHdPdnNUHZSLnz4ewA582p9ezzaEEAW8eY8iVf/030bDFjbzmRxoqb 3je/LjFrEyra1EdHdvBgpBc= Received: (qmail 3239 invoked by alias); 3 Apr 2013 19:18:38 -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 3228 invoked by uid 89); 3 Apr 2013 19:18:37 -0000 X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, SUBJ_ALL_CAPS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 03 Apr 2013 19:18:34 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r33JIWAt006161 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 3 Apr 2013 15:18:33 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-84.phx2.redhat.com [10.3.113.84]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r33JIWv5028319 for ; Wed, 3 Apr 2013 15:18:32 -0400 Message-ID: <515C8088.1040908@redhat.com> Date: Wed, 03 Apr 2013 13:18:32 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH] PR56799 X-Virus-Found: No Per Richi's suggestions I tweaked the recent tree-ssa-dom.c equivalence code to use int_fits_type_p rather than creating a new integer node and verifying it had the same value as the old node. At the time I dropped the TYPE_PRECISION check as I thought it was redundant with the int_fits_type_p tests. However int_fits_type_p only checks for a widening precision if it can't prove the constant fits within the bounds of the new type. Thus we could record an equivalence after a narrowing conversion, which is wrong in this particular case. Fixed by adding the TYPE_PRECISION checks back. Bootstrapped & regression tested on x86_64-unknown-linux-gnu. Installed. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e25a82..a3b60c9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2013-04-03 Jeff Law + + PR tree-optimization/56799 + * tree-ssa-dom.c (record_equivalences_from_incoming_edge): Bring + back test for widening conversion erroneously dropped in prior + change. + 2013-04-03 Kyrylo Tkachov PR target/56809 @@ -896,6 +903,7 @@ * config/tilegx/tilepro.h (PROFILE_BEFORE_PROLOGUE): Define. 2013-03-25 Jeff Law + * tree-ssa-dom.c (record_equivalences_from_incoming_edge): Add missing check for INTEGRAL_TYPE_P that was missing due to checking in wrong version of prior patch. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2cc5fa8..dc0b745 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-04-03 Jeff Law + + PR tree-optimization/56799 + * gcc.c-torture/execute/pr56799.c: New test. + 2013-04-03 Paolo Carlini PR c++/56815 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr56799.c b/gcc/testsuite/gcc.c-torture/execute/pr56799.c new file mode 100644 index 0000000..d9ee26b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr56799.c @@ -0,0 +1,43 @@ + +#include +typedef struct { int x; int y;} S; +extern int foo(S*); +int hi = 0, lo = 0; + +int main() +{ + S a; + int r; + a.x = (int) 0x00010000; + a.y = 1; + r = foo (&a); + if (r == 2 && lo==0 && hi==1) + { + exit (0); + } + abort (); +} + +typedef unsigned short u16; + +__attribute__ ((noinline)) int foo (S* ptr) +{ + int a = ptr->x; + int c = 0; + u16 b = (u16) a; + if (b != 0) + { + lo = 1; + c += ptr->y; + } + b = a >> 16; + if (b != 0) + { + hi = 1; + c+= ptr->y; + } + c += ptr->y; + return c; +} + + diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 29d2bb4..d98a646 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -1151,9 +1151,15 @@ record_equivalences_from_incoming_edge (basic_block bb) { tree old_rhs = gimple_assign_rhs1 (defstmt); - /* If the constant is in the range of the type of OLD_RHS, - then convert the constant and record the equivalence. */ + /* If the conversion widens the original value and + the constant is in the range of the type of OLD_RHS, + then convert the constant and record the equivalence. + + Note that int_fits_type_p does not check the precision + if the upper and lower bounds are OK. */ if (INTEGRAL_TYPE_P (TREE_TYPE (old_rhs)) + && (TYPE_PRECISION (TREE_TYPE (lhs)) + > TYPE_PRECISION (TREE_TYPE (old_rhs))) && int_fits_type_p (rhs, TREE_TYPE (old_rhs))) { tree newval = fold_convert (TREE_TYPE (old_rhs), rhs);