public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/50430] New: Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE).
@ 2011-09-16 10:38 hubicka at gcc dot gnu.org
  2011-09-16 14:43 ` [Bug lto/50430] " hubicka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2011-09-16 10:38 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50430
           Summary: Constructors of static external vars are throwed away
                    leading to missed optimizations (and ipa-cp ICE).
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hubicka@gcc.gnu.org


The LTO streaming code deals only with ctors of finalized variables, however
static external vars are useful for optimization. Vtables are common cases like
this.  Current mainline dies building libreoffice at:
(gdb) bt
#0  useless_type_conversion_p (outer_type=0x7ffff53501f8,
inner_type=0x66686e6973615f6e) at ../../gcc/tree-ssa.c:1292
#1  0x00000000005d77fc in fold_ctor_reference (type=0x7ffff53501f8,
ctor=0x7ffff7ec0b10, offset=1088, size=64) at ../../gcc/gimple-fold.c:2880
#2  0x00000000005d7e38 in gimple_get_virt_method_for_binfo (token=15,
known_binfo=0x7ffff2d39820) at ../../gcc/gimple-fold.c:3056
#3  0x0000000000ae6fde in devirtualization_time_bonus (node=<optimized out>,
known_csts=0x3625de0, known_binfos=0x3625d80) at ../../gcc/ipa-cp.c:1170
#4  0x0000000000aeae9c in estimate_local_effects (node=<optimized out>) at
../../gcc/ipa-cp.c:1401
#5  propagate_constants_topo (topo=<optimized out>) at ../../gcc/ipa-cp.c:1548
#6  ipcp_propagate_stage (topo=<optimized out>) at ../../gcc/ipa-cp.c:1631
#7  ipcp_driver () at ../../gcc/ipa-cp.c:2434
#8  0x00000000006733b7 in execute_one_pass (pass=0x10946e0) at
../../gcc/passes.c:2063
#9  0x0000000000673b86 in execute_ipa_pass_list (pass=0x10946e0) at
../../gcc/passes.c:2430
#10 0x00000000004ab3c4 in do_whole_program_analysis () at
../../gcc/lto/lto.c:2670
#11 0x00000000004adf6d in lto_main () at ../../gcc/lto/lto.c:2796
#12 0x0000000000706d42 in compile_file () at ../../gcc/toplev.c:548
#13 do_compile () at ../../gcc/toplev.c:1886
#14 toplev_main (argc=171, argv=0x1201290) at ../../gcc/toplev.c:1962
#15 0x00007ffff63efbc6 in __libc_start_main () from /lib64/libc.so.6
#16 0x00000000004909e9 in _start () at ../sysdeps/x86_64/elf/start.S:113

ctor passed to ctor_reference is error_mark indicating that the value has not
been streamed.

(gdb) p debug_tree (v)
 <var_decl 0x7fffe55dc140 _ZTV11SfxVoidItem
    type <array_type 0x7ffff5367e70
        type <pointer_type 0x7ffff53501f8 __vtbl_ptr_type type <function_type
0x7ffff53502a0>
            public unsigned DI
            size <integer_cst 0x7ffff7eb9ec0 constant 64>
            unit size <integer_cst 0x7ffff7eb9ee0 constant 8>
            align 64 symtab 0 alias set -1 canonical type 0x7ffff53591f8
            pointer_to_this <pointer_type 0x7ffff5350150>>
        BLK
        size <integer_cst 0x7ffff5366000 constant 1152>
        unit size <integer_cst 0x7ffff5366080 constant 144>
        align 64 symtab 0 alias set 2 canonical type 0x7ffff5367e70
        domain <integer_type 0x7ffff5367f18 type <integer_type 0x7ffff7ec9000
sizetype>
            DI size <integer_cst 0x7ffff7eb9ec0 64> unit size <integer_cst
0x7ffff7eb9ee0 8>
            align 64 symtab 0 alias set -1 canonical type 0x7ffff7ec9738
precision 64 min <integer_cst 0x7ffff7eb9f00 0> max <integer_cst 0x7ffff53660a0
17>>
        pointer_to_this <pointer_type 0x7ffff4f41738>>
    readonly public static ignored external virtual BLK file
/abuild/jh/libreoffice/core/solver/unxlngx6.pro/inc/svl/poolitem.hxx line 352
col 0 size <integer_cst 0x7ffff5366000 1152> unit size <integer_cst
0x7ffff5366080 144>
    align 64 context <record_type 0x7ffff53bb2a0 SfxVoidItem> initial
<error_mark 0x7ffff7ec0b10>>
$2 = void

I guess the following is correct fix for the ICE (to also avoid ICEs in case of
invalid programs etc.)

jan@linux-7ldc:~/trunk/gcc> svn diff gimple-fold.c
Index: gimple-fold.c
===================================================================
--- gimple-fold.c       (revision 178905)
+++ gimple-fold.c       (working copy)
@@ -3048,7 +3048,8 @@ gimple_get_virt_method_for_binfo (HOST_W

   if (TREE_CODE (v) != VAR_DECL
       || !DECL_VIRTUAL_P (v)
-      || !DECL_INITIAL (v))
+      || !DECL_INITIAL (v)
+      || DECL_INITIAL (v) == error_mark_node)
     return NULL_TREE;
   gcc_checking_assert (TREE_CODE (TREE_TYPE (v)) == ARRAY_TYPE);
   size = tree_low_cst (TYPE_SIZE (TREE_TYPE (TREE_TYPE (v))), 1);


but then we are missing optimization here.  I guess extern static vars should
go same way as extern inlines: i.e. be finalized to cgraph and then optimized
out after devirtualization.

Honza


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug lto/50430] Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE).
  2011-09-16 10:38 [Bug lto/50430] New: Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE) hubicka at gcc dot gnu.org
@ 2011-09-16 14:43 ` hubicka at gcc dot gnu.org
  2011-09-16 15:42 ` hubicka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2011-09-16 14:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jan Hubicka <hubicka at gcc dot gnu.org> 2011-09-16 14:40:14 UTC ---
Author: hubicka
Date: Fri Sep 16 14:40:06 2011
New Revision: 178908

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178908
Log:
    PR lto/50430
    * gimple-fold.c (gimple_get_virt_method_for_binfo): Do not ICE on
    error_mark_node in the DECL_INITIAL of vtable.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-fold.c


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug lto/50430] Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE).
  2011-09-16 10:38 [Bug lto/50430] New: Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE) hubicka at gcc dot gnu.org
  2011-09-16 14:43 ` [Bug lto/50430] " hubicka at gcc dot gnu.org
@ 2011-09-16 15:42 ` hubicka at gcc dot gnu.org
  2011-09-22 14:44 ` hubicka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2011-09-16 15:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> 2011-09-16 15:02:42 UTC ---
Created attachment 25306
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25306
testcase

One will need to revert the gimple-fold.c patch mentioned above to get an
error. Otherwise it is just missed optimization.

/abuild/jh/trunk-install/bin/g++ -O2 -flto -fuse-linker-plugin -Ur -nostdlib
*.ii -fpermissive -std=c++0x
lto1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: /abuild/jh/trunk-install/bin/g++ returned 1 exit status


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug lto/50430] Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE).
  2011-09-16 10:38 [Bug lto/50430] New: Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE) hubicka at gcc dot gnu.org
  2011-09-16 14:43 ` [Bug lto/50430] " hubicka at gcc dot gnu.org
  2011-09-16 15:42 ` hubicka at gcc dot gnu.org
@ 2011-09-22 14:44 ` hubicka at gcc dot gnu.org
  2012-05-07 12:59 ` rguenth at gcc dot gnu.org
  2021-01-07 16:52 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2011-09-22 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jan Hubicka <hubicka at gcc dot gnu.org> 2011-09-22 14:20:07 UTC ---
Created attachment 25340
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25340
reduced testcase

This is somewhat reduced testcase.  The problem can be a bit illustrated on C.

We have something like

extern vtable[]={vtable2}

where vtable2 sits in other unit and is static.  We however know the
constructor and it is
extern static vtable2[]={function_ptr};

now we can fold vtable[0] to the external vtable2 that we can not reffer in
code, but still can fold references into it into function_ptr.

now with LTO we decide to not stream vtable initializer and replace it by
error_mark losing the knowledge.  This is an regression to 4.6 even though it
is not too important one.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug lto/50430] Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE).
  2011-09-16 10:38 [Bug lto/50430] New: Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE) hubicka at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-09-22 14:44 ` hubicka at gcc dot gnu.org
@ 2012-05-07 12:59 ` rguenth at gcc dot gnu.org
  2021-01-07 16:52 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-05-07 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |lto, missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-05-07
     Ever Confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-05-07 12:57:52 UTC ---
Confirmed.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug lto/50430] Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE).
  2011-09-16 10:38 [Bug lto/50430] New: Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE) hubicka at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-05-07 12:59 ` rguenth at gcc dot gnu.org
@ 2021-01-07 16:52 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jamborm at gcc dot gnu.org @ 2021-01-07 16:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50430

--- Comment #5 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Am I correct thinking that this has been addressed (long time ago)?

The entire optimized dump of the testcase from comment #3 is now the
following, so no missed devirtualization there:

void _GLOBAL__sub_I_typelib_TypeClass ()
{
  <bb 2> [local count: 1073741824]:
  __ct_comp  (&typelib_TypeClass, 0, 1); [tail call]
  return;

}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-07 16:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-16 10:38 [Bug lto/50430] New: Constructors of static external vars are throwed away leading to missed optimizations (and ipa-cp ICE) hubicka at gcc dot gnu.org
2011-09-16 14:43 ` [Bug lto/50430] " hubicka at gcc dot gnu.org
2011-09-16 15:42 ` hubicka at gcc dot gnu.org
2011-09-22 14:44 ` hubicka at gcc dot gnu.org
2012-05-07 12:59 ` rguenth at gcc dot gnu.org
2021-01-07 16:52 ` jamborm at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).