public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use proper type in linear transformation in tree-switch-conversion (PR tree-optimization/88753).
@ 2019-01-08 12:40 Martin Liška
  2019-01-08 12:52 ` Jakub Jelinek
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2019-01-08 12:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]

Hi.

As seen in the PR, when doing switch convert linear transformation,
one needs to first convert to unsigned type for constructor values.

Patch survives regression tests and bootstrap on x86_64-linux-gnu.
Ready for trunk?
Thanks,
Martin


gcc/ChangeLog:

2019-01-08  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/88753
	* tree-switch-conversion.c (switch_conversion::build_one_array):
	Come up with local variable constructor.  Convert first to
	type of constructor values.
---
 gcc/tree-switch-conversion.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)



[-- Attachment #2: 0001-Use-proper-type-in-linear-transformation-in-tree-swi.patch --]
[-- Type: text/x-patch, Size: 1697 bytes --]

diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
index 614c450dd4d..de41050f317 100644
--- a/gcc/tree-switch-conversion.c
+++ b/gcc/tree-switch-conversion.c
@@ -600,9 +600,9 @@ switch_conversion::build_one_array (int num, tree arr_index_type,
   name = copy_ssa_name (PHI_RESULT (phi));
   m_target_inbound_names[num] = name;
 
+  vec<constructor_elt, va_gc> *constructor = m_constructors[num];
   wide_int coeff_a, coeff_b;
-  bool linear_p = contains_linear_function_p (m_constructors[num], &coeff_a,
-					      &coeff_b);
+  bool linear_p = contains_linear_function_p (constructor, &coeff_a, &coeff_b);
   if (linear_p)
     {
       if (dump_file && coeff_a.to_uhwi () > 0)
@@ -610,7 +610,8 @@ switch_conversion::build_one_array (int num, tree arr_index_type,
 		 " and B = %" PRId64 "\n", coeff_a.to_shwi (),
 		 coeff_b.to_shwi ());
 
-      tree t = unsigned_type_for (TREE_TYPE (m_index_expr));
+      /* We must use type of constructor values.  */
+      tree t = unsigned_type_for (TREE_TYPE ((*constructor)[0].value));
       gimple_seq seq = NULL;
       tree tmp = gimple_convert (&seq, t, m_index_expr);
       tree tmp2 = gimple_build (&seq, MULT_EXPR, t,
@@ -633,10 +634,10 @@ switch_conversion::build_one_array (int num, tree arr_index_type,
 	  unsigned int i;
 	  constructor_elt *elt;
 
-	  FOR_EACH_VEC_SAFE_ELT (m_constructors[num], i, elt)
+	  FOR_EACH_VEC_SAFE_ELT (constructor, i, elt)
 	    elt->value = fold_convert (value_type, elt->value);
 	}
-      ctor = build_constructor (array_type, m_constructors[num]);
+      ctor = build_constructor (array_type, constructor);
       TREE_CONSTANT (ctor) = true;
       TREE_STATIC (ctor) = true;
 


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

end of thread, other threads:[~2019-01-08 14:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-08 12:40 [PATCH] Use proper type in linear transformation in tree-switch-conversion (PR tree-optimization/88753) Martin Liška
2019-01-08 12:52 ` Jakub Jelinek
2019-01-08 13:08   ` Jakub Jelinek
2019-01-08 13:56     ` Martin Liška
2019-01-08 14:15       ` Jakub Jelinek
2019-01-08 14:25         ` Martin Liška
2019-01-08 13:09   ` Martin Liška
2019-01-08 13:50     ` Jakub Jelinek
2019-01-08 13:57       ` Martin Liška
2019-01-08 14:41         ` Martin Liška

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