+2018-04-22  Shiva Chen  <shiva0217@gmail.com>
+           Chung-Ju Wu  <jasonwucj@gmail.com>
+
+       * config/nds32/nds32-protos.h (nds32_case_vector_shorten_mode):
+       Declare.
+       * config/nds32/nds32.c (nds32_case_vector_shorten_mode): New function.
+       * config/nds32/nds32.h (CASE_VECTOR_SHORTEN_MODE): Modify.
+
 2018-04-22  Chung-Ju Wu  <jasonwucj@gmail.com>
 
        * config/nds32/nds32.c (nds32_compute_stack_frame): Fix wrong value.
 
 /* Auxiliary functions to check using return with null epilogue.  */
 
 extern int nds32_can_use_return_insn (void);
+extern scalar_int_mode nds32_case_vector_shorten_mode (int, int, rtx);
 
 /* Auxiliary functions to decide output alignment or not.  */
 
 
   return (cfun->machine->naked_p && (cfun->machine->va_args_size == 0));
 }
 
+scalar_int_mode
+nds32_case_vector_shorten_mode (int min_offset, int max_offset,
+                               rtx body ATTRIBUTE_UNUSED)
+{
+  if (min_offset < 0 || max_offset >= 0x2000)
+    return SImode;
+  else
+    {
+      /* The jump table maybe need to 2 byte alignment,
+        so reserved 1 byte for check max_offset.  */
+      if (max_offset >= 0xff)
+       return HImode;
+      else
+       return QImode;
+    }
+}
+
 /* ------------------------------------------------------------------------ */
 
 /* Function to test 333-form for load/store instructions.
 
 /* Return the preferred mode for and addr_diff_vec when the mininum
    and maximum offset are known.  */
 #define CASE_VECTOR_SHORTEN_MODE(min_offset, max_offset, body)  \
-   ((min_offset < 0 || max_offset >= 0x2000 ) ? SImode          \
-   : (max_offset >= 100) ? HImode                               \
-   : QImode)
+  nds32_case_vector_shorten_mode (min_offset, max_offset, body)
 
 /* Generate pc relative jump table when -fpic or -Os.  */
 #define CASE_VECTOR_PC_RELATIVE (flag_pic || optimize_size)