+2008-04-03 Richard Guenther <rguenther@suse.de>
+
+ PR middle-end/35800
+ * expr.h (try_casesi): Adjust prototype.
+ * expr.c (try_casesi): Take fallback label as extra parameter.
+ Use that for gen_casesi if default_label is NULL.
+ * stmt.c (expand_case): Pass fallback label to try_casesi,
+ make sure to fill gaps with a fallback label if default_label
+ is not present.
+
2008-04-03 Dominique d'Humieres <dominiq@lps.ens.fr>
PR target/35801
0 otherwise (i.e. if there is no casesi instruction). */
int
try_casesi (tree index_type, tree index_expr, tree minval, tree range,
- rtx table_label ATTRIBUTE_UNUSED, rtx default_label)
+ rtx table_label ATTRIBUTE_UNUSED, rtx default_label,
+ rtx fallback_label ATTRIBUTE_UNUSED)
{
enum machine_mode index_mode = SImode;
int index_bits = GET_MODE_BITSIZE (index_mode);
op2 = copy_to_mode_reg (op_mode, op2);
emit_jump_insn (gen_casesi (index, op1, op2,
- table_label, default_label));
+ table_label, !default_label
+ ? fallback_label : default_label));
return 1;
}
enum machine_mode, rtx, rtx, rtx);
/* Two different ways of generating switch statements. */
-extern int try_casesi (tree, tree, tree, tree, rtx, rtx);
+extern int try_casesi (tree, tree, tree, tree, rtx, rtx, rtx);
extern int try_tablejump (tree, tree, tree, tree, rtx, rtx);
/* Smallest number of adjacent cases before we use a jump table.
}
else
{
+ rtx fallback_label = label_rtx (case_list->code_label);
table_label = gen_label_rtx ();
if (! try_casesi (index_type, index_expr, minval, range,
- table_label, default_label))
+ table_label, default_label, fallback_label))
{
bool ok;
= gen_rtx_LABEL_REF (Pmode, label_rtx (n->code_label));
}
- /* Fill in the gaps with the default. */
- if (default_label)
- for (i = 0; i < ncases; i++)
- if (labelvec[i] == 0)
- labelvec[i] = gen_rtx_LABEL_REF (Pmode, default_label);
+ /* Fill in the gaps with the default. We may have gaps at
+ the beginning if we tried to avoid the minval subtraction,
+ so substitute some label even if the default label was
+ deemed unreachable. */
+ if (!default_label)
+ default_label = fallback_label;
+ for (i = 0; i < ncases; i++)
+ if (labelvec[i] == 0)
+ labelvec[i] = gen_rtx_LABEL_REF (Pmode, default_label);
/* Output the table. */
emit_label (table_label);