From patchwork Tue Aug 24 19:19:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 62620 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 B2ADDB70A6 for ; Wed, 25 Aug 2010 05:19:02 +1000 (EST) Received: (qmail 27295 invoked by alias); 24 Aug 2010 19:19:00 -0000 Received: (qmail 27282 invoked by uid 22791); 24 Aug 2010 19:18:59 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, 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; Tue, 24 Aug 2010 19:18:50 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7OJImfF022275 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 24 Aug 2010 15:18:48 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7OJIl7e031170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 24 Aug 2010 15:18:48 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o7OJJSiF006693 for ; Tue, 24 Aug 2010 21:19:28 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o7OJJQHC006687 for gcc-patches@gcc.gnu.org; Tue, 24 Aug 2010 21:19:26 +0200 Date: Tue, 24 Aug 2010 21:19:26 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid creating invalid gimple in eliminate_redundant_comparison (PR tree-optimization/45059) Message-ID: <20100824191926.GS702@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) 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! In some cases the operands of the comparison won't have the desired type, e.g. if there were any (useless) differences in types of the operands. Having a NOP_EXPR as gimple comparison's operand is invalid though. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for trunk? 2010-08-24 Jakub Jelinek PR tree-optimization/45059 * tree-ssa-reassoc.c (eliminate_redundant_comparison): Strip useless type conversions from newop{1,2}. Assert t is a comparison and newop{1,2} after the stripping are gimple vals. * gcc.c-torture/compile/pr45059.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2010-08-20 16:05:41.000000000 +0200 +++ gcc/tree-ssa-reassoc.c 2010-08-24 19:16:57.000000000 +0200 @@ -1314,9 +1314,14 @@ eliminate_redundant_comparison (enum tre enum tree_code subcode; tree newop1; tree newop2; + gcc_assert (COMPARISON_CLASS_P (t)); tmpvar = create_tmp_var (TREE_TYPE (t), NULL); add_referenced_var (tmpvar); extract_ops_from_tree (t, &subcode, &newop1, &newop2); + STRIP_USELESS_TYPE_CONVERSION (newop1); + STRIP_USELESS_TYPE_CONVERSION (newop2); + gcc_checking_assert (is_gimple_val (newop1) + && is_gimple_val (newop2)); sum = build_and_add_sum (tmpvar, newop1, newop2, subcode); curr->op = gimple_get_lhs (sum); } --- gcc/testsuite/gcc.c-torture/compile/pr45059.c.jj 2010-08-24 19:05:44.000000000 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr45059.c 2010-08-24 19:05:25.000000000 +0200 @@ -0,0 +1,23 @@ +/* PR tree-optimization/45059 */ + +typedef unsigned int T; +extern void foo (signed char *, int); + +static signed char a; +static T b[1] = { -1 }; +static unsigned char c; + +static inline short int +bar (short v) +{ + c |= a < b[0]; + return 0; +} + +int +main () +{ + signed char *e = &a; + foo (e, bar (bar (c))); + return 0; +}