From patchwork Mon Jul 4 18:22:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 103153 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 031EDB6F68 for ; Tue, 5 Jul 2011 04:23:36 +1000 (EST) Received: (qmail 28061 invoked by alias); 4 Jul 2011 18:23:35 -0000 Received: (qmail 28052 invoked by uid 22791); 4 Jul 2011 18:23:34 -0000 X-SWARE-Spam-Status: No, hits=-6.5 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; Mon, 04 Jul 2011 18:23:17 +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.14.4/8.14.4) with ESMTP id p64IMsFa012414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Jul 2011 14:22:54 -0400 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 p64IMrco006458 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 4 Jul 2011 14:22:53 -0400 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 p64IMq0x002104; Mon, 4 Jul 2011 20:22:52 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p64IMqOv002102; Mon, 4 Jul 2011 20:22:52 +0200 Date: Mon, 4 Jul 2011 20:22:52 +0200 From: Jakub Jelinek To: Eric Botcazou , Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE during combine (PR rtl-optimization/49619) Message-ID: <20110704182252.GW16443@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! The following testcase ICEs, because simplify_gen_binary (IOR, HImode, ...) simplifies into (subreg:HI (reg:SI ...) 0), but was still passing mode (HImode) as second argument to recursive combine_simplify_rtx call. The second argument is op0_mode, so is supposed to be the real mode which should be assumed for its first operand. Passing mode in that case is only safe if simplify_gen_binary doesn't actually simplify it, but as simplify_gen_binary would simplify constant arguments anyway into a constant, it doesn't make any sense to hint combine_simplify_rtx about the original op0_mode. That is something only useful when called from subst, which simplifies the operands (which may turn them from non-VOIDmode into VOIDmode) and then calls combine_simplify_rtx to simplify the whole operation. The second part of the patch attempts to optimize more, as simplify_gen_binary may already simplify the expression, so often (including the testcase) combine_simplify_rtx doesn't simplify anything, i.e. tor == temp, yet it is simplified over (ior plus_arg0 plus_arg1). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? For 4.6, I think safer would be just the first one liner change to pass VOIDmode to combine_simplify_rtx. Is that ok for 4.6? 2011-07-04 Jakub Jelinek PR rtl-optimization/49619 * combine.c (combine_simplify_rtx): In PLUS -> IOR simplification pass VOIDmode as op0_mode to recursive call, and return temp even when different from tor, just if it is not IOR of the original PLUS arguments. * gcc.dg/pr49619.c: New test. Jakub --- gcc/combine.c.jj 2011-06-21 16:46:01.000000000 +0200 +++ gcc/combine.c 2011-07-04 16:05:52.000000000 +0200 @@ -5681,12 +5681,17 @@ combine_simplify_rtx (rtx x, enum machin { /* Try to simplify the expression further. */ rtx tor = simplify_gen_binary (IOR, mode, XEXP (x, 0), XEXP (x, 1)); - temp = combine_simplify_rtx (tor, mode, in_dest, 0); + temp = combine_simplify_rtx (tor, VOIDmode, in_dest, 0); /* If we could, great. If not, do not go ahead with the IOR replacement, since PLUS appears in many special purpose address arithmetic instructions. */ - if (GET_CODE (temp) != CLOBBER && temp != tor) + if (GET_CODE (temp) != CLOBBER + && (GET_CODE (temp) != IOR + || ((XEXP (temp, 0) != XEXP (x, 0) + || XEXP (temp, 1) != XEXP (x, 1)) + && (XEXP (temp, 0) != XEXP (x, 1) + || XEXP (temp, 1) != XEXP (x, 0))))) return temp; } break; --- gcc/testsuite/gcc.dg/pr49619.c.jj 2011-07-04 16:04:21.000000000 +0200 +++ gcc/testsuite/gcc.dg/pr49619.c 2011-07-04 16:04:06.000000000 +0200 @@ -0,0 +1,13 @@ +/* PR rtl-optimization/49619 */ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-fre" } */ + +extern int a, b; + +void +foo (int x) +{ + a = 2; + b = 0; + b = (a && ((a = 1, 0 >= b) || (short) (x + (b & x)))); +}