From patchwork Wed Nov 9 15:32:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 124573 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 24C36B6F65 for ; Thu, 10 Nov 2011 02:32:58 +1100 (EST) Received: (qmail 10921 invoked by alias); 9 Nov 2011 15:32:55 -0000 Received: (qmail 10910 invoked by uid 22791); 9 Nov 2011 15:32:53 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Wed, 09 Nov 2011 15:32:38 +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 pA9FWbVn010623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Nov 2011 10:32:38 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pA9FWaH4030462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 9 Nov 2011 10:32:37 -0500 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 pA9FWaJA016337; Wed, 9 Nov 2011 16:32:36 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id pA9FWZg5016336; Wed, 9 Nov 2011 16:32:35 +0100 Date: Wed, 9 Nov 2011 16:32:35 +0100 From: Jakub Jelinek To: bernds@redhat.com, ebotcazou@redhat.com Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix combine's simplify_comparison (PR rtl-optimization/51023) Message-ID: <20111109153235.GA27242@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! This patch essentially reverts part of Bernd's 2011-07-06 changes, which was IMHO wrong. As const_op here is a constant in wider mode than MODE (which is the inner mode of the SIGN_EXTEND), the old code (and what this patch is restoring) didn't check just that the sign bit is clear, but also that all bits above the sign bit of MODE are clear too. I've used GET_MODE_PRECISION instead of GET_MODE_BITSIZE (as changed in many other places around that date) and HWI_COMPUTABLE_MODE_P macro. Additionally, if GET_MODE_CLASS (mode) == MODE_INT, we know mode != VOIDmode, there is no point testing it (but the compiler will likely not know it, as GET_MODE_CLASS is reading from an array). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? BTW, the @@ -6546,10 +6551,8 @@ simplify_set (rtx x) enum machine_mode inner_mode = GET_MODE (inner); /* Here we make sure that we don't have a sign bit on. */ - if (GET_MODE_BITSIZE (inner_mode) <= HOST_BITS_PER_WIDE_INT - && (nonzero_bits (inner, inner_mode) - < ((unsigned HOST_WIDE_INT) 1 - << (GET_MODE_BITSIZE (GET_MODE (src)) - 1)))) + if (val_signbit_known_clear_p (GET_MODE (src), + nonzero_bits (inner, inner_mode))) { SUBST (SET_SRC (x), inner); src = SET_SRC (x); hunk from the same patch might have the same problem (can't nonzero_bits be wider than the mode of src there?), but I don't have a testcase for that. Can you please double check that? 2011-11-09 Jakub Jelinek PR rtl-optimization/51023 * combine.c (simplify_comparison) : Don't use val_signbit_known_clear_p for signed comparison narrowing optimization. Don't check for non-VOIDmode, use HWI_COMPUTABLE_MODE_P macro. : Don't check for non-VOIDmode. * gcc.c-torture/execute/pr51023.c: New test. Jakub --- gcc/combine.c.jj 2011-11-08 23:35:12.000000000 +0100 +++ gcc/combine.c 2011-11-09 10:06:27.207333364 +0100 @@ -11397,9 +11397,12 @@ simplify_comparison (enum rtx_code code, later on, and then we wouldn't know whether to sign- or zero-extend. */ mode = GET_MODE (XEXP (op0, 0)); - if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT + if (GET_MODE_CLASS (mode) == MODE_INT && ! unsigned_comparison_p - && val_signbit_known_clear_p (mode, const_op) + && HWI_COMPUTABLE_MODE_P (mode) + && ((unsigned HOST_WIDE_INT) const_op + < (((unsigned HOST_WIDE_INT) 1 + << (GET_MODE_PRECISION (mode) - 1)))) && have_insn_for (COMPARE, mode)) { op0 = XEXP (op0, 0); @@ -11477,7 +11480,7 @@ simplify_comparison (enum rtx_code code, case ZERO_EXTEND: mode = GET_MODE (XEXP (op0, 0)); - if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT + if (GET_MODE_CLASS (mode) == MODE_INT && (unsigned_comparison_p || equality_comparison_p) && HWI_COMPUTABLE_MODE_P (mode) && ((unsigned HOST_WIDE_INT) const_op < GET_MODE_MASK (mode)) --- gcc/testsuite/gcc.c-torture/execute/pr51023.c.jj 2011-11-09 10:17:31.133406427 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr51023.c 2011-11-09 10:17:13.000000000 +0100 @@ -0,0 +1,18 @@ +/* PR rtl-optimization/51023 */ + +extern void abort (void); + +short int +foo (long int x) +{ + return x; +} + +int +main () +{ + long int a = 0x4272AL; + if (foo (a) == a) + abort (); + return 0; +}