Index: gcc/tree-switch-conversion.c
===================================================================
--- gcc/tree-switch-conversion.c	(revision 162573)
+++ gcc/tree-switch-conversion.c	(working copy)
@@ -721,6 +721,21 @@
 
   bound = fold_convert_loc (loc, utype, info.range_size);
   cond_stmt = gimple_build_cond (LE_EXPR, tmp_u_2, bound, NULL_TREE, NULL_TREE);
+
+  /* Check that the subtraction does not cause underflow - if it does then we
+     must fix up the max value for the tmp_u expression used in the cond_stmt,
+     so that simplify_cond_using_ranges() in tree-vrp.c has the correct value
+     ranges to play with.  */
+  if ((TREE_INT_CST_LOW(TYPE_MIN_VALUE (TREE_TYPE(tmp_u_2)))
+       - TREE_INT_CST_LOW(ulb))
+     > TREE_INT_CST_LOW(TYPE_MIN_VALUE (TREE_TYPE(tmp_u_2))))
+    {
+      TYPE_MAX_VALUE (TREE_TYPE (gimple_cond_lhs(cond_stmt)))
+        = build_int_cst (TREE_TYPE(gimple_cond_lhs(cond_stmt)),
+                         TREE_INT_CST_LOW(TYPE_MIN_VALUE (TREE_TYPE(tmp_u_2)))
+                         - TREE_INT_CST_LOW(ulb)); 
+    }
+
   gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
   update_stmt (cond_stmt);
 
