From patchwork Tue Nov 18 21:59:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 412205 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 25FBF140142 for ; Wed, 19 Nov 2014 08:59:44 +1100 (AEDT) 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:mime-version :content-type; q=dns; s=default; b=v8JIusha0XOsvelb34xbqVQLB/thj Y/FeQZtDXjs/Gn/C8ivjhtvnyMoCJK4F5sxAbpXD3/2WxVbwjpNsmONZRAhM3g5h WjvWMGcAz7Zw2TUKD3Q3mAS3MMO9EuuwVgsqFn61E6bSt++ADPAsDFuPkW7xG6Cz ap4TKvcpf2DGy8= 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:mime-version :content-type; s=default; bh=F4YQe1n/k15Vv6TbIBwpaMbOkMA=; b=y4l Yh0BDFzvLTNNLz1WzkvprztDQEfQ1Ju9+DtGIgl75DQYHKAQBPtBDHUxxs9g8QtX LxsUlQgT1vzDCp29RKtlgm3sBtkIbs1KxIZG6LfYX71oGufiGt3KhuyPieTyejqA t8ES1GWImAQw/TZZH6oLIooBxLGRr+zRfdXfC3wg= Received: (qmail 9240 invoked by alias); 18 Nov 2014 21:59:37 -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 9229 invoked by uid 89); 18 Nov 2014 21:59:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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, 18 Nov 2014 21:59:36 +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 sAILxYBq019539 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 18 Nov 2014 16:59:34 -0500 Received: from tucnak.zalov.cz (ovpn-116-73.ams2.redhat.com [10.36.116.73]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAILxWvh029148 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Tue, 18 Nov 2014 16:59:33 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.9/8.14.9) with ESMTP id sAILxUrQ013810; Tue, 18 Nov 2014 22:59:30 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.9/8.14.9/Submit) id sAILxSg1013809; Tue, 18 Nov 2014 22:59:28 +0100 Date: Tue, 18 Nov 2014 22:59:28 +0100 From: Jakub Jelinek To: Richard Biener , Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up r217118 - simplify_binary_operation_1 (PR rtl-optimization/63843) Message-ID: <20141118215928.GR1745@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi! The case ASHIFTRT: which is meant for this optimization is preceeded by /* FALLTHRU */ from ROTATE cases, which can't be optimized this way. Thus, this patch limits this optimization to ASHIFTRT. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-11-18 Jakub Jelinek PR rtl-optimization/63843 * simplify-rtx.c (simplify_binary_operation_1) : For optimization of ashiftrt of subreg of lshiftrt, check that code is ASHIFTRT. * gcc.c-torture/execute/pr63843.c: New test. Jakub --- gcc/simplify-rtx.c.jj 2014-11-18 10:17:01.000000000 +0100 +++ gcc/simplify-rtx.c 2014-11-18 13:44:26.727792683 +0100 @@ -3118,10 +3118,11 @@ simplify_binary_operation_1 (enum rtx_co (subreg:M1 (ashiftrt:M2 (reg:M2) (const_int )) ). */ - if (!VECTOR_MODE_P (mode) + if (code == ASHIFTRT + && !VECTOR_MODE_P (mode) && SUBREG_P (op0) && CONST_INT_P (op1) - && (GET_CODE (SUBREG_REG (op0)) == LSHIFTRT) + && GET_CODE (SUBREG_REG (op0)) == LSHIFTRT && !VECTOR_MODE_P (GET_MODE (SUBREG_REG (op0))) && CONST_INT_P (XEXP (SUBREG_REG (op0), 1)) && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) --- gcc/testsuite/gcc.c-torture/execute/pr63843.c.jj 2014-11-18 13:43:45.417544096 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr63843.c 2014-11-18 13:43:32.000000000 +0100 @@ -0,0 +1,31 @@ +/* PR rtl-optimization/63843 */ + +static inline __attribute__ ((always_inline)) +unsigned short foo (unsigned short v) +{ + return (v << 8) | (v >> 8); +} + +unsigned short __attribute__ ((noinline, noclone, hot)) +bar (unsigned char *x) +{ + unsigned int a; + unsigned short b; + __builtin_memcpy (&a, &x[0], sizeof (a)); + a ^= 0x80808080U; + __builtin_memcpy (&x[0], &a, sizeof (a)); + __builtin_memcpy (&b, &x[2], sizeof (b)); + return foo (b); +} + +int +main () +{ + unsigned char x[8] = { 0x01, 0x01, 0x01, 0x01 }; + if (__CHAR_BIT__ == 8 + && sizeof (short) == 2 + && sizeof (int) == 4 + && bar (x) != 0x8181U) + __builtin_abort (); + return 0; +}