Fix PR tree-optimization/98272

This fixes the precision mismatch introduced by the previous change.

gcc/ChangeLog:
	PR tree-optimization/98272
	* tree-switch-conversion.c (bit_test_cluster::emit): When finding
	out whether the entry test can be merged in the bit test, do the
	computation using the type of the index expression.

gcc/testsuite/ChangeLog:
	* gcc.dg/pr98272.c: New test.
This commit is contained in:
Eric Botcazou 2020-12-16 09:39:07 +01:00
parent 31008a8bb3
commit 61e3c180ad
2 changed files with 29 additions and 6 deletions

View file

@ -0,0 +1,22 @@
/* PR tree-optimization/98272 */
/* Reported by Zdenek Sojka <zsojka@seznam.cz> */
/* { dg-do compile } */
/* { dg-options "-O -fno-tree-forwprop" } */
void bar (void);
void
foo (unsigned char uc)
{
if (uc >= 5)
return;
switch (uc)
{
case 0:
case 2:
case 4:
bar ();
}
}

View file

@ -1557,21 +1557,22 @@ bit_test_cluster::emit (tree index_expr, tree index_type,
&& get_range_info (index_expr, &min, &max) == VR_RANGE
&& wi::leu_p (max - min, prec - 1))
{
tree index_type = TREE_TYPE (index_expr);
minval = fold_convert (index_type, minval);
wide_int iminval = wi::to_wide (minval);
tree minval_type = TREE_TYPE (minval);
if (wi::lt_p (min, iminval, TYPE_SIGN (minval_type)))
if (wi::lt_p (min, iminval, TYPE_SIGN (index_type)))
{
minval = wide_int_to_tree (minval_type, min);
minval = wide_int_to_tree (index_type, min);
for (i = 0; i < count; i++)
test[i].mask = wi::lshift (test[i].mask, iminval - min);
}
else if (wi::gt_p (min, iminval, TYPE_SIGN (minval_type)))
else if (wi::gt_p (min, iminval, TYPE_SIGN (index_type)))
{
minval = wide_int_to_tree (minval_type, min);
minval = wide_int_to_tree (index_type, min);
for (i = 0; i < count; i++)
test[i].mask = wi::lrshift (test[i].mask, min - iminval);
}
maxval = wide_int_to_tree (minval_type, max);
maxval = wide_int_to_tree (index_type, max);
entry_test_needed = false;
}
else