From patchwork Tue Mar 15 13:18:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 597536 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qPZvL3tW1z9snk for ; Wed, 16 Mar 2016 00:18:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=jmXuRwLl; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=H2zNFOc+FskPsxHJ9 cKXW5XZkS3khGJik7V43vbyqU16TW/MPj0V3/NGKxk6jb6mGK55FZe/99vewK2vc 5tvNLnuHvD3UHvb+HbD7fSMw3nvEx+SYVf3RvysQGOsG9sYxTohC8SAuIdwuGT0W gu9eNynoSOe9qx1ZYMvjcc6N24= 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:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=PphU3zQOiwQywYe6AFP9t5k unF4=; b=jmXuRwLlrGm6WwBLzOHwrqRWY3mWVexIHA4WvoEg6z/EIenBw56RfVh b1S0orp7axh/I1hPSCV6Y2qA1NSzb429ox+j2rNF1uNlhUCPQHpqgAJWu5O2zpWB 2vSHdjCOTbxxZ/nSpaBJgdPW6U2NLItZa35GRXXSGuOHlKVdzxYY= Received: (qmail 124425 invoked by alias); 15 Mar 2016 13:18:42 -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 124412 invoked by uid 89); 15 Mar 2016 13:18:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=spot X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 15 Mar 2016 13:18:40 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 1B41BC00B8C7; Tue, 15 Mar 2016 13:18:39 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2FDIb9s013848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 15 Mar 2016 09:18:38 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u2FDIZCL001208; Tue, 15 Mar 2016 14:18:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u2FDIYIM000967; Tue, 15 Mar 2016 14:18:34 +0100 Date: Tue, 15 Mar 2016 14:18:33 +0100 From: Jakub Jelinek To: Bernd Schmidt Cc: Segher Boessenkool , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix combine's simplify_shift_const_1 (PR rtl-optimization/70222) Message-ID: <20160315131833.GV3017@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20160315111448.GU3017@tucnak.redhat.com> <56E7FB52.2010402@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <56E7FB52.2010402@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes On Tue, Mar 15, 2016 at 01:08:50PM +0100, Bernd Schmidt wrote: > This looks really specialized, and I'd be worrying about whether it really > is the right condition. Where exactly was the constant shifted by 31 and > count set to 0? Must be here, right? Yes, it is that spot. > > /* If we have (A << B << C) for any shift, we can convert this to > (A << C << B). This wins if A is a constant. Only try this if > B is not a constant. */ > > else if (GET_CODE (varop) == code > && CONST_INT_P (XEXP (varop, 0)) > && !CONST_INT_P (XEXP (varop, 1))) > { > rtx new_rtx = simplify_const_binary_operation (code, mode, > XEXP (varop, 0), > GEN_INT (count)); > varop = gen_rtx_fmt_ee (code, mode, new_rtx, XEXP (varop, 1)); > count = 0; > continue; > } > > I think it might be clearer to notice and fix the problem here (or set a > need_mask flag). So do you prefer this instead? 2016-03-15 Jakub Jelinek PR rtl-optimization/70222 * combine.c (simplify_shift_const_1): For A >> B >> C LSHIFTRT optimization if mode is different from result_mode, queue up masking of the result in outer_op. Formatting fix. * gcc.c-torture/execute/pr70222-1.c: New test. * gcc.c-torture/execute/pr70222-2.c: New test. Jakub --- gcc/combine.c.jj 2016-03-14 23:18:37.958408627 +0100 +++ gcc/combine.c 2016-03-15 14:08:34.754434506 +0100 @@ -10524,9 +10524,19 @@ simplify_shift_const_1 (enum rtx_code co && CONST_INT_P (XEXP (varop, 0)) && !CONST_INT_P (XEXP (varop, 1))) { + /* For ((unsigned) (cstULL >> count)) >> cst2 we have to make + sure the result will be masked. See PR70222. */ + if (code == LSHIFTRT + && mode != result_mode + && !merge_outer_ops (&outer_op, &outer_const, AND, + GET_MODE_MASK (result_mode) + >> orig_count, result_mode, + &complement_p)) + break; + rtx new_rtx = simplify_const_binary_operation (code, mode, - XEXP (varop, 0), - GEN_INT (count)); + XEXP (varop, 0), + GEN_INT (count)); varop = gen_rtx_fmt_ee (code, mode, new_rtx, XEXP (varop, 1)); count = 0; continue; --- gcc/testsuite/gcc.c-torture/execute/pr70222-1.c.jj 2016-03-15 11:30:41.657000384 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr70222-1.c 2016-03-15 11:30:41.657000384 +0100 @@ -0,0 +1,30 @@ +/* PR rtl-optimization/70222 */ + +int a = 1; +unsigned int b = 2; +int c = 0; +int d = 0; + +void +foo () +{ + int e = ((-(c >= c)) < b) > ((int) (-1ULL >> ((a / a) * 15))); + d = -e; +} + +__attribute__((noinline, noclone)) void +bar (int x) +{ + if (x != -1) + __builtin_abort (); +} + +int +main () +{ +#if __CHAR_BIT__ == 8 && __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8 + foo (); + bar (d); +#endif + return 0; +} --- gcc/testsuite/gcc.c-torture/execute/pr70222-2.c.jj 2016-03-15 11:36:13.273366841 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr70222-2.c 2016-03-15 11:36:18.156298614 +0100 @@ -0,0 +1,20 @@ +/* PR rtl-optimization/70222 */ + +#if __CHAR_BIT__ == 8 && __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8 +__attribute__((noinline, noclone)) unsigned int +foo (int x) +{ + unsigned long long y = -1ULL >> x; + return (unsigned int) y >> 31; +} +#endif + +int +main () +{ +#if __CHAR_BIT__ == 8 && __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8 + if (foo (15) != 1 || foo (32) != 1 || foo (33) != 0) + __builtin_abort (); +#endif + return 0; +}