public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Roger Sayle <roger@nextmovesoftware.com>
To: Andrew Haley <aph@redhat.com>
Cc: java-patches@gcc.gnu.org
Subject: Re: [JAVA PATCH] Enable more array bounds check elimination
Date: Mon, 22 Feb 2016 23:02:00 -0000	[thread overview]
Message-ID: <74FFBDDA-D906-470D-A7BA-559AAD71E76A@nextmovesoftware.com> (raw)


Hi Andrew,

On 02/22/2016, Andrew Haley wrote:
> I take it that this only really works with new arrays?

Alas yes, this patch only addresses the case that the array allocation is
visible (in the same method after inlining) as the array bounds check,
which fortunately is fairly frequent, especially for initializers.

I'd assumed that the middle-end optimizers were already doing a reasonable
job for the harder cases, but inspired by your question above, I've done some
more investigating and noticed other areas where improvements are possible.

For example

	int len = arr.length;
	for (int i=0; i<arr.length; i++)
	  arr[i] = arr[i]+1;

eliminates all bounds checks when arr is double[], but disappointingly
not when arr is int[].  I suspect that the middle-end optimizers assume
the worst, perhaps that arr.data[-1] potentially aliases arr.length, or
similar.  Obviously, java doesn't allow negative array indices, but I
suspect the gcj front-end's gimple doesn't manage to convey this.

I'm personally impressed that GCC recognizes that although

	for (int i=0; i<3; i++)
	  ... arr[i] ...

typically needs to perform index checking on every iteration,
that the reversed loop

	for (int i=2; i>=0; i--)
	  ... arr[i] ...

only needs to perform array bounds checking on the first iteration,
i.e. optimizes away the later checks [in unrolled loops].  This might
seem obvious, but there's a lot of analysis required to recover this
from java's bytecodes.


Please point me towards any relevant postings (of yours) on the subject of
gcj bounds check elimination, as I'd love to catch up on current thinking.

Cheers,

Roger
--

             reply	other threads:[~2016-02-22 23:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22 23:02 Roger Sayle [this message]
2016-02-23  9:56 ` Andrew Haley
2016-02-23 17:45   ` Andrew Hughes
2016-02-24  1:11     ` Roger Sayle
2016-02-24  3:23       ` Andrew Hughes
2016-02-24  9:53       ` Andrew Haley
  -- strict thread matches above, loose matches on Subject: below --
2016-02-22 18:10 roger
2016-02-22 18:13 ` Andrew Haley
2016-02-22 18:18 ` Jeff Law
2016-07-13 20:07 ` Jeff Law
2016-07-14 17:12   ` Andrew Hughes
2016-07-14 17:43     ` Andrew Haley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74FFBDDA-D906-470D-A7BA-559AAD71E76A@nextmovesoftware.com \
    --to=roger@nextmovesoftware.com \
    --cc=aph@redhat.com \
    --cc=java-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).