re PR middle-end/39157 (Code that compiles fine in 1GB of memory with 4.1.2 requires...
authorJakub Jelinek <jakub@redhat.com>
Fri, 20 Feb 2009 12:56:01 +0000 (13:56 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 20 Feb 2009 12:56:01 +0000 (13:56 +0100)
PR middle-end/39157
* Makefile.in (loop-invariant.o): Depend on $(PARAMS_H).
* params.h (LOOP_INVARIANT_MAX_BBS_IN_LOOP): Define.
* params.def (loop-invariant-max-bbs-in-loop): New parameter.
* opts.c (decode_options): Set loop-invariant-max-bbs-in-loop
parameter to 1000 for -O1 by default.
* doc/invoke.texi (loop-invariant-max-bbs-in-loop): Document new
parameter.
* loop-invariant.c: Include params.h.
(move_loop_invariants): Don't call move_single_loop_invariants on
very large loops.

From-SVN: r144320

gcc/ChangeLog
gcc/Makefile.in
gcc/doc/invoke.texi
gcc/loop-invariant.c
gcc/opts.c
gcc/params.def
gcc/params.h

index 64bfbe0629656d052ea18ac3350a92722b54e3ba..bb0ad681a4a5a31a721eaee097ea27208ce813c1 100644 (file)
@@ -1,3 +1,17 @@
+2009-02-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/39157
+       * Makefile.in (loop-invariant.o): Depend on $(PARAMS_H).
+       * params.h (LOOP_INVARIANT_MAX_BBS_IN_LOOP): Define.
+       * params.def (loop-invariant-max-bbs-in-loop): New parameter.
+       * opts.c (decode_options): Set loop-invariant-max-bbs-in-loop
+       parameter to 1000 for -O1 by default.
+       * doc/invoke.texi (loop-invariant-max-bbs-in-loop): Document new
+       parameter.
+       * loop-invariant.c: Include params.h.
+       (move_loop_invariants): Don't call move_single_loop_invariants on
+       very large loops.
+
 2009-02-20  Jaka Mocnik  <jaka@xlab.si>
 
        * calls.c (emit_library_call_value_1): Use slot_offset instead of
index 3e09ccadbf8553bf109bf5fae82b291b34371f21..5e3fc9d5a562b613a9d325806d9f0a5286939bde 100644 (file)
@@ -2814,7 +2814,7 @@ loop-iv.o : loop-iv.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) $(BASIC_BLOCK_H) \
 loop-invariant.o : loop-invariant.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) \
    $(BASIC_BLOCK_H) hard-reg-set.h $(CFGLOOP_H) $(EXPR_H) $(RECOG_H) coretypes.h \
    $(TM_H) $(TM_P_H) $(FUNCTION_H) $(FLAGS_H) $(DF_H) $(OBSTACK_H) output.h \
-   $(HASHTAB_H) except.h
+   $(HASHTAB_H) except.h $(PARAMS_H)
 cfgloopmanip.o : cfgloopmanip.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) \
    $(BASIC_BLOCK_H) hard-reg-set.h $(CFGLOOP_H) $(CFGLAYOUT_H) output.h \
    coretypes.h $(TM_H) cfghooks.h $(OBSTACK_H) $(TREE_FLOW_H)
index f52b6433160c8b6b8e954ee80b34e55d8600c4ee..f12124ccdc1e50862561d2956d87b831fa73e09e 100644 (file)
@@ -7766,6 +7766,13 @@ lower quality register allocation algorithm will be used.  The
 algorithm do not use pseudo-register conflicts.  The default value of
 the parameter is 2000.
 
+@item loop-invariant-max-bbs-in-loop
+Loop invariant motion can be very expensive, both in compile time and
+in amount of needed compile time memory, with very large loops.  Loops
+with more basic blocks than this parameter won't have loop invariant
+motion optimization performed on them.  The default value of the
+parameter is 1000 for -O1 and 10000 for -O2 and above.
+
 @end table
 @end table
 
index 8b8345fe5fd208851c499d79e1ecaa4476021d93..82e18297e2070bcf430f4a45dac54c257dc49457 100644 (file)
@@ -1,5 +1,6 @@
 /* RTL-level loop invariant motion.
-   Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -52,6 +53,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "df.h"
 #include "hashtab.h"
 #include "except.h"
+#include "params.h"
 
 /* The data stored for the loop.  */
 
@@ -1345,7 +1347,10 @@ move_loop_invariants (void)
   /* Process the loops, innermost first.  */
   FOR_EACH_LOOP (li, loop, LI_FROM_INNERMOST)
     {
-      move_single_loop_invariants (loop);
+      /* move_single_loop_invariants for very large loops
+        is time consuming and might need a lot of memory.  */
+      if (loop->num_nodes <= (unsigned) LOOP_INVARIANT_MAX_BBS_IN_LOOP)
+       move_single_loop_invariants (loop);
     }
 
   FOR_EACH_LOOP (li, loop, 0)
index cccb80b403fed8a82732386c853c826b98f45622..8ae79ae08899146c69b5ebeed23a52161edd3611 100644 (file)
@@ -1,5 +1,5 @@
 /* Command line option handling.
-   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Contributed by Neil Booth.
 
@@ -811,6 +811,7 @@ decode_options (unsigned int argc, const char **argv)
   static int initial_avg_aliased_vops;
   static int initial_min_crossjump_insns;
   static int initial_max_fields_for_field_sensitive;
+  static int initial_loop_invariant_max_bbs_in_loop;
   static unsigned int initial_lang_mask;
 
   unsigned int i, lang_mask;
@@ -833,6 +834,8 @@ decode_options (unsigned int argc, const char **argv)
        = compiler_params[PARAM_MIN_CROSSJUMP_INSNS].value;
       initial_max_fields_for_field_sensitive
        = compiler_params[PARAM_MAX_FIELDS_FOR_FIELD_SENSITIVE].value;
+      initial_loop_invariant_max_bbs_in_loop
+       = compiler_params[PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP].value;
     }
   else
     lang_mask = initial_lang_mask;
@@ -943,6 +946,10 @@ decode_options (unsigned int argc, const char **argv)
   set_param_value ("max-fields-for-field-sensitive",
                   (opt2) ? 100 : initial_max_fields_for_field_sensitive);
 
+  /* For -O1 only do loop invariant motion for very small loops.  */
+  set_param_value ("loop-invariant-max-bbs-in-loop",
+                  (opt2) ? initial_loop_invariant_max_bbs_in_loop : 1000);
+
   /* -O3 optimizations.  */
   opt3 = (optimize >= 3);
   flag_predictive_commoning = opt3;
index ea5efc3e85c4c3ed587d8bbebd1fd320fef1b493..3f7b2e77ed65cc7e9aea45fbaf6042aa353591c0 100644 (file)
@@ -1,5 +1,5 @@
 /* params.def - Run-time parameters.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 
+   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Written by Mark Mitchell <mark@codesourcery.com>.
 
@@ -764,6 +764,13 @@ DEFPARAM (PARAM_SWITCH_CONVERSION_BRANCH_RATIO,
          "a switch conversion to take place",
          8, 1, 0)
 
+/* Avoid doing loop invariant motion on very large loops.  */
+
+DEFPARAM (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
+         "loop-invariant-max-bbs-in-loop",
+         "max basic blocks number in loop for loop invariant motion",
+         10000, 0, 0)
+
 /*
 Local variables:
 mode:c
index 501259c78e14a088021a3b93e675139d5a94fafd..fb2dad5706f2ad01369e8a7ba25fd51eb2ffc270 100644 (file)
@@ -1,5 +1,6 @@
 /* params.h - Run-time parameters.
-   Copyright (C) 2001, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008, 2009
+   Free Software Foundation, Inc.
    Written by Mark Mitchell <mark@codesourcery.com>.
 
 This file is part of GCC.
@@ -173,4 +174,6 @@ typedef enum compiler_param
   PARAM_VALUE (PARAM_IRA_MAX_CONFLICT_TABLE_SIZE)
 #define SWITCH_CONVERSION_BRANCH_RATIO \
   PARAM_VALUE (PARAM_SWITCH_CONVERSION_BRANCH_RATIO)
+#define LOOP_INVARIANT_MAX_BBS_IN_LOOP \
+  PARAM_VALUE (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP)
 #endif /* ! GCC_PARAMS_H */