From patchwork Fri Jul 30 15:45:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 60364 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 C0841B70B9 for ; Sat, 31 Jul 2010 01:46:05 +1000 (EST) Received: (qmail 29843 invoked by alias); 30 Jul 2010 15:46:04 -0000 Received: (qmail 29834 invoked by uid 22791); 30 Jul 2010 15:46:03 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM X-Spam-Check-By: sourceware.org Received: from mail-fx0-f47.google.com (HELO mail-fx0-f47.google.com) (209.85.161.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Jul 2010 15:45:56 +0000 Received: by fxm12 with SMTP id 12so1113117fxm.20 for ; Fri, 30 Jul 2010 08:45:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.115.201 with SMTP id j9mr2290981faq.48.1280504754404; Fri, 30 Jul 2010 08:45:54 -0700 (PDT) Received: by 10.220.182.135 with HTTP; Fri, 30 Jul 2010 08:45:53 -0700 (PDT) In-Reply-To: References: <20100525235926.GA3326@kam.mff.cuni.cz> <20100527075632.GA12991@kam.mff.cuni.cz> <20100528085052.GA3423@kam.mff.cuni.cz> <20100529152243.GA18706@kam.mff.cuni.cz> <20100529191446.GA3996@kam.mff.cuni.cz> <20100604105451.GB5105@kam.mff.cuni.cz> Date: Fri, 30 Jul 2010 08:45:53 -0700 Message-ID: Subject: Re: IVOPT improvement patch From: "H.J. Lu" To: Xinliang David Li Cc: Richard Guenther , Pat Haugen , GCC Patches , Zdenek Dvorak 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, Jul 29, 2010 at 6:04 PM, H.J. Lu wrote: > It looks strange: > > +      width = (GET_MODE_BITSIZE (address_mode) <  HOST_BITS_PER_WIDE_INT - 1) > +          ? GET_MODE_BITSIZE (address_mode) : HOST_BITS_PER_WIDE_INT - 1; >       addr = gen_rtx_fmt_ee (PLUS, address_mode, reg1, NULL_RTX); > -      for (i = start; i <= 1 << 20; i <<= 1) > +      for (i = 1; i < width; i++) >        { > -         XEXP (addr, 1) = gen_int_mode (i, address_mode); > +          HOST_WIDE_INT offset = (1ll << i); > +         XEXP (addr, 1) = gen_int_mode (offset, address_mode); >          if (!memory_address_addr_space_p (mem_mode, addr, as)) >            break; >        } > > HOST_WIDE_INT may be long or long long. "1ll" isn't always correct. > I think width can be >= 31. Depending on HOST_WIDE_INT, > > HOST_WIDE_INT offset = -(1ll << i); > > may have different values. The whole function looks odd to me. > > Here is a different approach to check address overflow. diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 1d65b4a..55aa10c 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -3243,7 +3243,7 @@ get_address_cost (bool symbol_present, bool var_present, HOST_WIDE_INT i; HOST_WIDE_INT start = BIGGEST_ALIGNMENT / BITS_PER_UNIT; HOST_WIDE_INT rat, off; - int old_cse_not_expected; + int old_cse_not_expected, width; unsigned sym_p, var_p, off_p, rat_p, add_c; rtx seq, addr, base; rtx reg0, reg1; @@ -3252,8 +3252,10 @@ get_address_cost (bool symbol_present, bool var_present, reg1 = gen_raw_REG (address_mode, LAST_VIRTUAL_REGISTER + 1); + width = (GET_MODE_BITSIZE (address_mode) < HOST_BITS_PER_WIDE_INT - 2) + ? GET_MODE_BITSIZE (address_mode) : HOST_BITS_PER_WIDE_INT - 2; addr = gen_rtx_fmt_ee (PLUS, address_mode, reg1, NULL_RTX); - for (i = start; i <= 1 << 20; i <<= 1) + for (i = start; i && i <= (HOST_WIDE_INT) 1 << width; i <<= 1) { XEXP (addr, 1) = gen_int_mode (i, address_mode); if (!memory_address_addr_space_p (mem_mode, addr, as)) @@ -3262,7 +3264,7 @@ get_address_cost (bool symbol_present, bool var_present, data->max_offset = i == start ? 0 : i >> 1; off = data->max_offset; - for (i = start; i <= 1 << 20; i <<= 1) + for (i = start; i && i <= (HOST_WIDE_INT) 1 << width; i <<= 1) { XEXP (addr, 1) = gen_int_mode (-i, address_mode); if (!memory_address_addr_space_p (mem_mode, addr, as)) @@ -3273,12 +3275,12 @@ get_address_cost (bool symbol_present, bool var_present, if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "get_address_cost:\n"); - fprintf (dump_file, " min offset %s %d\n", + fprintf (dump_file, " min offset %s " HOST_WIDE_INT_PRINT_DEC "\n", GET_MODE_NAME (mem_mode), - (int) data->min_offset); - fprintf (dump_file, " max offset %s %d\n", + data->min_offset); + fprintf (dump_file, " max offset %s " HOST_WIDE_INT_PRINT_DEC "\n", GET_MODE_NAME (mem_mode), - (int) data->max_offset); + data->max_offset); } rat = 1;