diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f71edd54616085405e082f99bfa1a2991a540535..7c6fb7631c05444141a66c35383d6ee0e39123a7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2018-04-22  Chung-Ju Wu  <jasonwucj@gmail.com>
+
+	* config/nds32/nds32-protos.h (nds32_data_alignment,
+	nds32_local_alignment): Declare.
+	* config/nds32/nds32.c (nds32_data_alignment, nds32_constant_alignment,
+	nds32_local_alignment): New functions.
+	(TARGET_CONSTANT_ALIGNMENT): Define.
+	* config/nds32/nds32.h (DATA_ALIGNMENT, LOCAL_ALIGNMENT): Define.
+
 2018-04-22  Chung-Ju Wu  <jasonwucj@gmail.com>
 
 	* config/nds32/nds32.c
diff --git a/gcc/config/nds32/nds32-protos.h b/gcc/config/nds32/nds32-protos.h
index b7522f1ed7da910660ac818204adbabada61741b..2dce97ef91b8bd1aa4a78ec826b27bc334950a9f 100644
--- a/gcc/config/nds32/nds32-protos.h
+++ b/gcc/config/nds32/nds32-protos.h
@@ -223,6 +223,8 @@ extern int nds32_can_use_return_insn (void);
 /* Auxiliary functions to decide output alignment or not.  */
 
 extern int nds32_target_alignment (rtx_insn *);
+extern unsigned int nds32_data_alignment (tree, unsigned int);
+extern unsigned int nds32_local_alignment (tree, unsigned int);
 
 /* Auxiliary functions to expand builtin functions.  */
 
diff --git a/gcc/config/nds32/nds32.c b/gcc/config/nds32/nds32.c
index 76a72a8b12ebbf1e452f61f33e4d8d665f74d94d..a0012c0ccf3e21f938c41472536a501b0949dfac 100644
--- a/gcc/config/nds32/nds32.c
+++ b/gcc/config/nds32/nds32.c
@@ -4812,6 +4812,63 @@ nds32_target_alignment (rtx_insn *label)
     return 2;
 }
 
+/* Return alignment for data.  */
+unsigned int
+nds32_data_alignment (tree data,
+		      unsigned int basic_align)
+{
+  if ((basic_align < BITS_PER_WORD)
+      && (TREE_CODE (data) == ARRAY_TYPE
+	 || TREE_CODE (data) == UNION_TYPE
+	 || TREE_CODE (data) == RECORD_TYPE))
+    return BITS_PER_WORD;
+  else
+    return basic_align;
+}
+
+/* Return alignment for constant value.  */
+static HOST_WIDE_INT
+nds32_constant_alignment (const_tree constant,
+			  HOST_WIDE_INT basic_align)
+{
+  /* Make string literal and constant for constructor to word align.  */
+  if (((TREE_CODE (constant) == STRING_CST
+	|| TREE_CODE (constant) == CONSTRUCTOR
+	|| TREE_CODE (constant) == UNION_TYPE
+	|| TREE_CODE (constant) == RECORD_TYPE
+	|| TREE_CODE (constant) == ARRAY_TYPE)
+       && basic_align < BITS_PER_WORD))
+    return BITS_PER_WORD;
+  else
+    return basic_align;
+}
+
+/* Return alignment for local variable.  */
+unsigned int
+nds32_local_alignment (tree local ATTRIBUTE_UNUSED,
+		       unsigned int basic_align)
+{
+  bool at_least_align_to_word = false;
+  /* Make local array, struct and union at least align to word for make
+     sure it can unroll memcpy when initialize by constant.  */
+  switch (TREE_CODE (local))
+    {
+    case ARRAY_TYPE:
+    case RECORD_TYPE:
+    case UNION_TYPE:
+      at_least_align_to_word = true;
+      break;
+    default:
+      at_least_align_to_word = false;
+      break;
+    }
+  if (at_least_align_to_word
+      && (basic_align < BITS_PER_WORD))
+    return BITS_PER_WORD;
+  else
+    return basic_align;
+}
+
 bool
 nds32_split_double_word_load_store_p(rtx *operands, bool load_p)
 {
@@ -4865,6 +4922,9 @@ nds32_use_blocks_for_constant_p (machine_mode mode,
 #undef TARGET_EXPAND_TO_RTL_HOOK
 #define TARGET_EXPAND_TO_RTL_HOOK nds32_expand_to_rtl_hook
 
+#undef TARGET_CONSTANT_ALIGNMENT
+#define TARGET_CONSTANT_ALIGNMENT nds32_constant_alignment
+
 
 /* Layout of Source Language Data Types.  */
 
diff --git a/gcc/config/nds32/nds32.h b/gcc/config/nds32/nds32.h
index 9d673d54e804359eeb0849d760739eb5ad494269..6c2f1f8f13ed807cbd11aa9233297688306bec23 100644
--- a/gcc/config/nds32/nds32.h
+++ b/gcc/config/nds32/nds32.h
@@ -688,6 +688,12 @@ enum nds32_builtins
 
 #define BIGGEST_ALIGNMENT 64
 
+#define DATA_ALIGNMENT(constant, basic_align) \
+  nds32_data_alignment (constant, basic_align)
+
+#define LOCAL_ALIGNMENT(type, basic_align) \
+  nds32_local_alignment (type, basic_align)
+
 #define EMPTY_FIELD_BOUNDARY 32
 
 #define STRUCTURE_SIZE_BOUNDARY 8