public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR37285, switch default label issues
@ 2008-10-01 15:37 Richard Guenther
  0 siblings, 0 replies; only message in thread
From: Richard Guenther @ 2008-10-01 15:37 UTC (permalink / raw)
  To: gcc-patches


This fixes PR37285 a case where we are confused with a switch stmt
without a default label.  Fortunately(?) after the tuples merge we
always have a default label again(!) - we just fail to mark it as
such properly.  This also addresses a missed-optimization during
expansion (I don't remember exactly, but HP does maybe ...).

That said, if we ever remove the default case during VRP we can
promote any remaining case to the default one.  Which is what this
patch does - simply chose the one we put in the location for the
default case.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

In theory we should be able to revert all the expander and middle-end
changes from the original patch now ...

Richard.

2008-10-01  Richard Guenther  <rguenther@suse.de>

        PR middle-end/37285
        * tree-vrp.c (execute_vrp): If we optimized away the default
        case make sure to promote the label that got in place of it
        to a default case label.

        * gcc.c-torture/compile/pr37285.c: New testcase.

Index: testsuite/gcc.c-torture/compile/pr37285.c
===================================================================
*** testsuite/gcc.c-torture/compile/pr37285.c	(revision 0)
--- testsuite/gcc.c-torture/compile/pr37285.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ _bfd_xcoff_canonicalize_dynamic_reloc (unsigned long long l_symndx)
+ {
+   if (l_symndx < 3)
+     {
+       switch (l_symndx)
+       {
+         case 0:
+         case 1:
+          break;
+         case 2:
+          _bfd_abort ("HI");
+     }
+   }
+ }
+ 
Index: tree-vrp.c
===================================================================
*** tree-vrp.c	(revision 140810)
--- tree-vrp.c	(working copy)
*************** execute_vrp (void)
*** 7149,7157 ****
--- 7149,7164 ----
      {
        size_t j;
        size_t n = TREE_VEC_LENGTH (su->vec);
+       tree label;
        gimple_switch_set_num_labels (su->stmt, n);
        for (j = 0; j < n; j++)
  	gimple_switch_set_label (su->stmt, j, TREE_VEC_ELT (su->vec, j));
+       /* As we may have replaced the default label with a regular one
+ 	 make sure to make it a real default label again.  This ensures
+ 	 optimal expansion.  */
+       label = gimple_switch_default_label (su->stmt);
+       CASE_LOW (label) = NULL_TREE;
+       CASE_HIGH (label) = NULL_TREE;
      }
  
    if (VEC_length (edge, to_remove_edges) > 0)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-10-01 15:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-01 15:37 [PATCH] Fix PR37285, switch default label issues Richard Guenther

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