From patchwork Thu Oct 13 22:49:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 119660 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 87AEFB71BF for ; Fri, 14 Oct 2011 09:50:23 +1100 (EST) Received: (qmail 2003 invoked by alias); 13 Oct 2011 22:50:19 -0000 Received: (qmail 1975 invoked by uid 22791); 13 Oct 2011 22:50:17 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-qy0-f175.google.com (HELO mail-qy0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Oct 2011 22:50:01 +0000 Received: by qyk10 with SMTP id 10so611799qyk.20 for ; Thu, 13 Oct 2011 15:50:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.62.220 with SMTP id y28mr1249084qch.208.1318546200152; Thu, 13 Oct 2011 15:50:00 -0700 (PDT) Received: by 10.229.83.146 with HTTP; Thu, 13 Oct 2011 15:49:59 -0700 (PDT) In-Reply-To: <11110132233.AA24293@vlsi1.ultra.nyu.edu> References: <20111012223450.GA11516@intel.com> <11110122240.AA07538@vlsi1.ultra.nyu.edu> <11110122304.AA07835@vlsi1.ultra.nyu.edu> <4E96BAA6.9000809@gnu.org> <11110131251.AA14799@vlsi1.ultra.nyu.edu> <4E96E571.3060006@gnu.org> <11110131414.AA16597@vlsi1.ultra.nyu.edu> <11110131611.AA19261@vlsi1.ultra.nyu.edu> <11110131635.AA19765@vlsi1.ultra.nyu.edu> <4E97197B.8080102@gnu.org> <11110131706.AA20218@vlsi1.ultra.nyu.edu> <11110131815.AA21002@vlsi1.ultra.nyu.edu> <11110132123.AA23359@vlsi1.ultra.nyu.edu> <11110132130.AA23753@vlsi1.ultra.nyu.edu> <11110132233.AA24293@vlsi1.ultra.nyu.edu> Date: Thu, 13 Oct 2011 15:49:59 -0700 Message-ID: Subject: Re: PATCH: PR rtl-optimization/50696: [x32] Unnecessary lea From: "H.J. Lu" To: Richard Kenner Cc: bonzini@gnu.org, gcc-patches@gcc.gnu.org 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 On Thu, Oct 13, 2011 at 3:33 PM, Richard Kenner wrote: >> I am testing this patch.  The difference is it checks nonzero >> bits of the first operand. > > I would suggest moving (and expanding) the comments from the existing block > into your new block. > Like ths? diff --git a/gcc/combine.c b/gcc/combine.c index 6c3b17c..4b57b88 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -7739,16 +7739,6 @@ make_compound_operation (rtx x, enum rtx_code in_code) XEXP (XEXP (x, 0), 1))); } - /* If the constant is one less than a power of two, this might be - representable by an extraction even if no shift is present. - If it doesn't end up being a ZERO_EXTEND, we will ignore it unless - we are in a COMPARE. */ - else if ((i = exact_log2 (UINTVAL (XEXP (x, 1)) + 1)) >= 0) - new_rtx = make_extraction (mode, - make_compound_operation (XEXP (x, 0), - next_code), - 0, NULL_RTX, i, 1, 0, in_code == COMPARE); - /* If we are in a comparison and this is an AND with a power of two, convert this into the appropriate bit extract. */ else if (in_code == COMPARE @@ -7758,6 +7748,26 @@ make_compound_operation (rtx x, enum rtx_code in_code) next_code), i, NULL_RTX, 1, 1, 0, 1); + /* If the constant is an extraction mask with the zero bits in + the first operand ignored, this might be representable by an + extraction even if no shift is present. If it doesn't end up + being a ZERO_EXTEND, we will ignore it unless we are in a + COMPARE. */ + else + { + unsigned HOST_WIDE_INT nonzero = + nonzero_bits (XEXP (x, 0), GET_MODE (XEXP (x, 0))); + unsigned HOST_WIDE_INT mask = UINTVAL (XEXP (x, 1)); + unsigned HOST_WIDE_INT len = ceil_log2 (mask); + if ((nonzero & (((unsigned HOST_WIDE_INT) 1 << len) - 1)) + == (nonzero & mask)) + { + new_rtx = make_compound_operation (XEXP (x, 0), next_code); + new_rtx = make_extraction (mode, new_rtx, 0, NULL_RTX, + len, 1, 0, in_code == COMPARE); + } + } + break; case LSHIFTRT: