This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Remove useless null pointer checks
- From: Jeff Sturm <jsturm at one-point dot com>
- To: law at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 30 Jul 2003 23:07:38 -0400 (EDT)
- Subject: Re: [tree-ssa] Remove useless null pointer checks
On Wed, 30 Jul 2003 law@redhat.com wrote:
> This is a first cut at removal of useless null pointer checks based
> on the knowledge that after a memory load/store we know the pointer
> used must not be null.
This is excellent. Java emits tons of useless null pointer checks.
Without this patch, the class:
class A {
int i;
final int j() {
return i;
}
static int sum(A a) {
return a.i + a.j();
}
}
would optimize to (in method sum):
A.sum(A) (a)
{
int T.3;
A:: * j.5;
int T.6;
T.3 = a->i;
if (a == 0B)
{
_Jv_ThrowNullPointerException ()
};
j.5 = (A:: *)j;
T.6 = j.5 (a);
int = T.3 + T.6;
return T.3 + T.6;
}
With your patch, I get:
A.sum(A) (a)
{
int T.4;
A:: * j.6;
int T.7;
T.4 = a->i;
j.6 = (A:: *)j;
T.7 = j.6 (a);
return T.4 + T.7;
}
Somehow the RTL optimizers never caught on to this.
A related question came up just the other day on the java list. There are
often-called functions (e.g. allocators) in libgcj that cannot return
null. Is there a good way to tell the tree optimizers about these, to
eliminate even more useless null pointer checks?
Jeff