public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5104] switch expansion: limit JT growth param values
@ 2023-01-11 12:06 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2023-01-11 12:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8221efae233e2d5992a79600071dd0a52f1b3c74

commit r13-5104-g8221efae233e2d5992a79600071dd0a52f1b3c74
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Dec 28 09:11:40 2022 +0100

    switch expansion: limit JT growth param values
    
    Currently, one can request a huge jump table creation which
    leads to a non-sensual huge output. Moreover, use auto_vec rather
    than a stack-allocated array.
    
            PR middle-end/107976
    
    gcc/ChangeLog:
    
            * params.opt: Limit JT params.
            * stmt.cc (emit_case_dispatch_table): Use auto_vec.

Diff:
---
 gcc/params.opt | 4 ++--
 gcc/stmt.cc    | 9 ++++-----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/gcc/params.opt b/gcc/params.opt
index 929131254d2..8a128c321c9 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -323,11 +323,11 @@ Common Joined UInteger Var(param_iv_max_considered_uses) Init(250) Param Optimiz
 Bound on number of iv uses in loop optimized in iv optimizations.
 
 -param=jump-table-max-growth-ratio-for-size=
-Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_size) Init(300) Param Optimization
+Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_size) Init(300) IntegerRange(0, 10000) Param Optimization
 The maximum code size growth ratio when expanding into a jump table (in percent).  The parameter is used when optimizing for size.
 
 -param=jump-table-max-growth-ratio-for-speed=
-Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_speed) Init(800) Param Optimization
+Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_speed) Init(800) IntegerRange(0, 10000) Param Optimization
 The maximum code size growth ratio when expanding into a jump table (in percent).  The parameter is used when optimizing for speed.
 
 -param=l1-cache-line-size=
diff --git a/gcc/stmt.cc b/gcc/stmt.cc
index 82a3e1035ec..b239c02018a 100644
--- a/gcc/stmt.cc
+++ b/gcc/stmt.cc
@@ -746,7 +746,7 @@ emit_case_dispatch_table (tree index_expr, tree index_type,
 			  tree range, basic_block stmt_bb)
 {
   int i, ncases;
-  rtx *labelvec;
+  auto_vec<rtx> labelvec;
   rtx_insn *fallback_label = label_rtx (case_list[0].m_code_label);
   rtx_code_label *table_label = gen_label_rtx ();
   bool has_gaps = false;
@@ -779,8 +779,7 @@ emit_case_dispatch_table (tree index_expr, tree index_type,
   /* Get table of labels to jump to, in order of case index.  */
 
   ncases = tree_to_shwi (range) + 1;
-  labelvec = XALLOCAVEC (rtx, ncases);
-  memset (labelvec, 0, ncases * sizeof (rtx));
+  labelvec.safe_grow_cleared (ncases);
 
   for (unsigned j = 0; j < case_list.length (); j++)
     {
@@ -860,11 +859,11 @@ emit_case_dispatch_table (tree index_expr, tree index_type,
     emit_jump_table_data (gen_rtx_ADDR_DIFF_VEC (CASE_VECTOR_MODE,
 						 gen_rtx_LABEL_REF (Pmode,
 								    table_label),
-						 gen_rtvec_v (ncases, labelvec),
+						 gen_rtvec_v (ncases, labelvec.address ()),
 						 const0_rtx, const0_rtx));
   else
     emit_jump_table_data (gen_rtx_ADDR_VEC (CASE_VECTOR_MODE,
-					    gen_rtvec_v (ncases, labelvec)));
+					    gen_rtvec_v (ncases, labelvec.address ())));
 
   /* Record no drop-through after the table.  */
   emit_barrier ();

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-11 12:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 12:06 [gcc r13-5104] switch expansion: limit JT growth param values Martin Liska

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).