This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/45221] missed optimization with multiple bases and casting



------- Comment #4 from rguenth at gcc dot gnu dot org  2010-08-07 10:37 -------
I don't see what the bug is here - this is a feature of the C++ standard,
we can't really "optimize" anything here.  5.2.9/8 ... The null pointer
value is converted to the null pointer value of the destination type.
In the case of foo3 'y' is not a pointer so that special case does not apply.

The only thing we can do is excercise knowledge of undefined behavior as you
dereference the resulting pointer in foo1 and foo2 and thus the behavior
is undefined if that would be a null pointer.

The FE hands us

;; Function int foo2(Base2*) (null)
;; enabled by -tree-original

return <retval> = (x != 0B ? (struct Derived *) x + -4 : 0B)->data;

and we arrive with

<bb 2>:
  if (x_2(D) != 0B)
    goto <bb 3>;
  else
    goto <bb 4>;

<bb 3>:
  iftmp.1_3 = x_2(D) + -4;
  goto <bb 5>;

<bb 4>:
  iftmp.1_4 = 0;

<bb 5>:
  # iftmp.1_1 = PHI <iftmp.1_3(3), 0(4)>
  D.1726_5 = iftmp.1_1->data;

which we could for example (with -fdelete-null-pointer-checks, where no
objects at address zero can exist), optimize during phiprop if we
insert undefined values as loads from NULL.  We could also value-number
loads based on NULL to VN_TOP which would optimize the case during PRE.

Much less fragile is when the code gets inlined into a context where
we know that x isn't a NULL pointer.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45221


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]