public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] switch expansion: limit JT growth param values
@ 2023-01-11 10:30 Martin Liška
  2023-01-11 12:05 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2023-01-11 10:30 UTC (permalink / raw)
  To: gcc-patches

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.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR middle-end/107976

gcc/ChangeLog:

	* params.opt: Limit JT params.
	* stmt.cc (emit_case_dispatch_table): Use auto_vec.
---
 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 e178dec1600..3454700eb91 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -327,11 +327,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 ();
-- 
2.39.0


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

* Re: [PATCH] switch expansion: limit JT growth param values
  2023-01-11 10:30 [PATCH] switch expansion: limit JT growth param values Martin Liška
@ 2023-01-11 12:05 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-01-11 12:05 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

On Wed, Jan 11, 2023 at 11:31 AM Martin Liška <mliska@suse.cz> wrote:
>
> 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.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

OK.

Thanks,
Richard.

> Thanks,
> Martin
>
>         PR middle-end/107976
>
> gcc/ChangeLog:
>
>         * params.opt: Limit JT params.
>         * stmt.cc (emit_case_dispatch_table): Use auto_vec.
> ---
>  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 e178dec1600..3454700eb91 100644
> --- a/gcc/params.opt
> +++ b/gcc/params.opt
> @@ -327,11 +327,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 ();
> --
> 2.39.0
>

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

end of thread, other threads:[~2023-01-11 12:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 10:30 [PATCH] switch expansion: limit JT growth param values Martin Liška
2023-01-11 12:05 ` Richard Biener

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