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: Jason Merrill <jason at redhat dot com>
- To: law at redhat dot com
- Cc: Jeff Sturm <jsturm at one-point dot com>, gcc-patches at gcc dot gnu dot org
- Date: Tue, 05 Aug 2003 13:26:35 -0400
- Subject: Re: [tree-ssa] Remove useless null pointer checks
- References: <200308051635.h75GZbFj013872@speedy.slc.redhat.com>
On Tue, 05 Aug 2003 10:35:37 -0600, law@redhat.com wrote:
> You can see the annoying typecast is gone. However, you'll also note that
> the LHS of the two marked statements have different types. One is a
> void *, the other is a struct mem_attrs *.
Yep. When I tried changing the type of expressions to remove casts, I ran
into problems with code that, for instance, assumes that &foo has type
typeof(foo) *.
> So the "trick" is to recognize typecasts which are not important from
> a code generation standpoint and enter the proper equivalences into
> the const_and_copies table.
Yes, I think this is a better approach.
> So given a statement such as
>
> LHS = (TYPE) RHS;
>
> If the main variant of TYPE and RHS is the same, then enter LHS = RHS into
> the const_and_copies table.
>
> If TYPE and RHS's type are both pointers and one is a void *, then enter
> LHS = RHS into the const_and_copies table.
You should also handle casts between pointer and reference type; they are
equivalent outside the front end.
> For integral types, we can safely call STRIP_SIGN_NOPS to remove any
> casts which do not change the underlying mode or sign.
>
> There may be other "rules" we could use for typecasts which are safe to
> ignore in the gimplifier and tree-ssa optimizers.
>
> Thoughts?
Could we go all the way and allow any cast which doesn't change mode or
sign?
Jason