This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Null pointer check elimination
- From: Diego Novillo <dnovillo at redhat dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: gcc at gcc dot gnu dot org, Per Bothner <per at bothner dot com>, Anthony Green <green at redhat dot com>, java at gcc dot gnu dot org
- Date: Sat, 12 Nov 2005 13:17:20 -0500
- Subject: Re: Null pointer check elimination
- References: <1131747852.3205.105.camel@localhost.localdomain> <200511121225.21933.dnovillo@redhat.com> <17270.9855.581880.413649@zapata.pink>
On Saturday 12 November 2005 12:29, Andrew Haley wrote:
> Diego Novillo writes:
>
> > if (shared_1)
> > x_4 = "x"
> > else
> > {
> > x_5 = new String("x");
> > x_6 = ASSERT_EXPR <x_5, x_5 != 0>
> > }
> > x_7 = PHI <x_4, x_6>
> >
> > VRP already knows that "x" is non-NULL. The new function attribute
> > will cause VRP to insert the ASSERT_EXPR for x_5. VRP will
> > detetermine that x_7 is non-NULL.
>
> OK, so what's to stop the front-end from generating the assertion at
> gimplification time? Then we don't need any new attributes in the
> middle-end.
>
The FE is not emitting SSA code. In 'x = new String("x")', it will know
that 'x' is non-NULL at that point, but it cannot prove that 'x' will
remain non-NULL everywhere. When you are in SSA form, x_6 is non-NULL and
everywhere you see x_6 you are guaranteed to be dealing with a non-NULL
value.
The helpful hint we need from the FE inside VRP is for it to mark the
actual call as returning non-NULL.