+ /* Check whether there are tablejumps in the end of BB1 and BB2.
+ Return true if they are identical. */
+ {
+ rtx label1, label2;
+ rtx table1, table2;
+
+ if (tablejump_p (BB_END (bb1), &label1, &table1)
+ && tablejump_p (BB_END (bb2), &label2, &table2)
+ && GET_CODE (PATTERN (table1)) == GET_CODE (PATTERN (table2)))
+ {
+ /* The labels should never be the same rtx. If they really are same
+ the jump tables are same too. So disable crossjumping of blocks BB1
+ and BB2 because when deleting the common insns in the end of BB1
+ by delete_basic_block () the jump table would be deleted too. */
+ /* If LABEL2 is referenced in BB1->END do not do anything
+ because we would loose information when replacing
+ LABEL1 by LABEL2 and then LABEL2 by LABEL1 in BB1->END. */
+ if (label1 != label2 && !rtx_referenced_p (label2, BB_END (bb1)))
+ {
+ /* Set IDENTICAL to true when the tables are identical. */
+ bool identical = false;
+ rtx p1, p2;
+
+ p1 = PATTERN (table1);
+ p2 = PATTERN (table2);
+ if (GET_CODE (p1) == ADDR_VEC && rtx_equal_p (p1, p2))
+ {
+ identical = true;
+ }
+ else if (GET_CODE (p1) == ADDR_DIFF_VEC
+ && (XVECLEN (p1, 1) == XVECLEN (p2, 1))
+ && rtx_equal_p (XEXP (p1, 2), XEXP (p2, 2))
+ && rtx_equal_p (XEXP (p1, 3), XEXP (p2, 3)))
+ {
+ int i;
+
+ identical = true;
+ for (i = XVECLEN (p1, 1) - 1; i >= 0 && identical; i--)
+ if (!rtx_equal_p (XVECEXP (p1, 1, i), XVECEXP (p2, 1, i)))
+ identical = false;
+ }
+
+ if (identical)
+ {
+ replace_label_data rr;
+ bool match;
+
+ /* Temporarily replace references to LABEL1 with LABEL2
+ in BB1->END so that we could compare the instructions. */
+ rr.r1 = label1;
+ rr.r2 = label2;
+ rr.update_label_nuses = false;
+ for_each_rtx (&BB_END (bb1), replace_label, &rr);
+
+ match = old_insns_match_p (mode, BB_END (bb1), BB_END (bb2));
+ if (dump_file && match)
+ fprintf (dump_file,
+ "Tablejumps in bb %i and %i match.\n",
+ bb1->index, bb2->index);
+
+ /* Set the original label in BB1->END because when deleting
+ a block whose end is a tablejump, the tablejump referenced
+ from the instruction is deleted too. */
+ rr.r1 = label2;
+ rr.r2 = label1;
+ for_each_rtx (&BB_END (bb1), replace_label, &rr);
+
+ return match;
+ }
+ }
+ return false;
+ }
+ }
+