From patchwork Thu Aug 19 16:33:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 62196 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 D3F6FB70A9 for ; Fri, 20 Aug 2010 02:33:40 +1000 (EST) Received: (qmail 27947 invoked by alias); 19 Aug 2010 16:33:35 -0000 Received: (qmail 27929 invoked by uid 22791); 19 Aug 2010 16:33:32 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_SB, TW_SW, TW_WT, 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; Thu, 19 Aug 2010 16:33:09 +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 o7JGX7ZH021478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 19 Aug 2010 12:33:07 -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 o7JGX6tE027599 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 19 Aug 2010 12:33:06 -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 o7JGXUoE015787 for ; Thu, 19 Aug 2010 18:33:30 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o7JGXUrc015786 for gcc-patches@gcc.gnu.org; Thu, 19 Aug 2010 18:33:30 +0200 Date: Thu, 19 Aug 2010 18:33:30 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Optimize nested SIGN_EXTENDs/ZERO_EXTENDs (PR target/45336) Message-ID: <20100819163330.GX702@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! This patch optimizes pextrw $3, %xmm0, %eax - cwtl - cltq + movswq %ax, %rax ret and pextrb $4, %xmm0, %eax - movsbl %al, %eax - cltq + movsbq %al, %rax ret in the testcase from the PR. While H.J. said he is working on something for the intrinsics, the patch below attempts to simplify the generic case of nested SIGN or ZERO_EXTENDs. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-08-19 Jakub Jelinek PR target/45336 * simplify-rtx.c (simplify_unary_operation_1): Optimize nested SIGN_EXTENDs or ZERO_EXTENDs. Jakub --- gcc/simplify-rtx.c.jj 2010-08-11 21:08:06.000000000 +0200 +++ gcc/simplify-rtx.c 2010-08-19 14:49:20.000000000 +0200 @@ -1010,6 +1010,31 @@ simplify_unary_operation_1 (enum rtx_cod && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (XEXP (op, 0)))) return rtl_hooks.gen_lowpart_no_emit (mode, op); + /* (sign_extend:M (sign_extend:N )) is (sign_extend:M ). */ + if (GET_CODE (op) == SIGN_EXTEND) + return simplify_gen_unary (SIGN_EXTEND, mode, XEXP (op, 0), + GET_MODE (XEXP (op, 0))); + + /* (sign_extend:M (ashirtrt:O (ashift (const_int N)) (const_int N))) + is (sign_extend:M (subreg:P )) if there is mode with + GET_MODE_BITSIZE (O) - N bits. */ + if (GET_CODE (op) == ASHIFTRT + && GET_CODE (XEXP (op, 0)) == ASHIFT + && CONST_INT_P (XEXP (op, 1)) + && XEXP (XEXP (op, 0), 1) == XEXP (op, 1) + && GET_MODE_BITSIZE (GET_MODE (op)) > INTVAL (XEXP (op, 1))) + { + enum machine_mode tmode + = mode_for_size (GET_MODE_BITSIZE (GET_MODE (op)) + - INTVAL (XEXP (op, 1)), MODE_INT, 1); + if (tmode != BLKmode) + { + rtx inner = + rtl_hooks.gen_lowpart_no_emit (tmode, XEXP (XEXP (op, 0), 0)); + return simplify_gen_unary (SIGN_EXTEND, mode, inner, tmode); + } + } + #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend) /* As we do not know which address space the pointer is refering to, we can do this only if the target does not support different pointer @@ -1036,6 +1061,11 @@ simplify_unary_operation_1 (enum rtx_cod && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (XEXP (op, 0)))) return rtl_hooks.gen_lowpart_no_emit (mode, op); + /* (zero_extend:M (zero_extend:N )) is (zero_extend:M ). */ + if (GET_CODE (op) == ZERO_EXTEND) + return simplify_gen_unary (ZERO_EXTEND, mode, XEXP (op, 0), + GET_MODE (XEXP (op, 0))); + #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend) /* As we do not know which address space the pointer is refering to, we can do this only if the target does not support different pointer