From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23836 invoked by alias); 7 Aug 2010 10:37:41 -0000 Received: (qmail 23812 invoked by uid 48); 7 Aug 2010 10:37:29 -0000 Date: Sat, 07 Aug 2010 10:37:00 -0000 Message-ID: <20100807103729.23811.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/45221] missed optimization with multiple bases and casting In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenth at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-08/txt/msg00505.txt.bz2 ------- 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 = (x != 0B ? (struct Derived *) x + -4 : 0B)->data; and we arrive with : if (x_2(D) != 0B) goto ; else goto ; : iftmp.1_3 = x_2(D) + -4; goto ; : iftmp.1_4 = 0; : # iftmp.1_1 = PHI 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