Further rs_code_align support refinement

Don't write the repeating nop pattern if it won't be used.
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 9005fc7..5d35a90 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -9058,11 +9058,15 @@
 #endif
       memset (p, 0, fix);
       p += fix;
+      bytes -= fix;
       fragP->fr_fix += fix;
     }
 
-  memcpy (p, aarch64_noop, noop_size);
-  fragP->fr_var = noop_size;
+  if (bytes != 0)
+    {
+      fragP->fr_var = noop_size;
+      memcpy (p, aarch64_noop, noop_size);
+    }
 }
 
 /* Perform target specific initialisation of a frag.
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index ad4eef4..44020e3 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -26602,7 +26602,6 @@
 
   bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
   p = fragP->fr_literal + fragP->fr_fix;
-  fix = 0;
 
   gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
 
@@ -26633,9 +26632,9 @@
 #endif
     }
 
-  if (bytes & (noop_size - 1))
+  fix = bytes & (noop_size - 1);
+  if (fix != 0)
     {
-      fix = bytes & (noop_size - 1);
 #ifdef OBJ_ELF
       insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
 #endif
@@ -26660,8 +26659,11 @@
     }
 
   fragP->fr_fix += fix;
-  fragP->fr_var = noop_size;
-  memcpy (p, noop, noop_size);
+  if (bytes != 0)
+    {
+      fragP->fr_var = noop_size;
+      memcpy (p, noop, noop_size);
+    }
 }
 
 /* Perform target specific initialisation of a frag.
diff --git a/gas/config/tc-epiphany.c b/gas/config/tc-epiphany.c
index be3235a..4a027e9 100644
--- a/gas/config/tc-epiphany.c
+++ b/gas/config/tc-epiphany.c
@@ -326,11 +326,15 @@
   if (bytes & 1)
     {
       *p++ = 0;
+      bytes--;
       fragp->fr_fix++;
     }
 
-  memcpy (p, nop_pattern, 2);
-  fragp->fr_var = 2;
+  if (bytes != 0)
+    {
+      fragp->fr_var = 2;
+      memcpy (p, nop_pattern, 2);
+    }
 }
 
 /* Read a comma separated incrementing list of register names
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 73d552e..723f021 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -1775,9 +1775,11 @@
 	 included in fr_fix.  The repeating larger nop only needs to
 	 be written once to the frag memory.  */
       fragP->fr_fix = where - fragP->fr_literal;
-      fragP->fr_var = limit;
       if (count != 0)
-	count = limit;
+	{
+	  fragP->fr_var = limit;
+	  count = limit;
+	}
     }
 
   const unsigned char *nops = patt[limit - 1];
diff --git a/gas/config/tc-metag.c b/gas/config/tc-metag.c
index 195e6a4..09ee5c3 100644
--- a/gas/config/tc-metag.c
+++ b/gas/config/tc-metag.c
@@ -6853,11 +6853,15 @@
     {
       memset (p, 0, fix);
       p += fix;
+      bytes -= fix;
       fragP->fr_fix += fix;
     }
 
-  memcpy (p, noop, 4);
-  fragP->fr_var = 4;
+  if (bytes != 0)
+    {
+      fragP->fr_var = 4;
+      memcpy (p, noop, 4);
+    }
 }
 
 static char *
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c
index 26172e5..3c16216 100644
--- a/gas/config/tc-nds32.c
+++ b/gas/config/tc-nds32.c
@@ -4657,12 +4657,16 @@
 		   BFD_RELOC_NDS32_INSN16);
       memcpy (p, nop16, 2);
       p += 2;
+      bytes -= 2;
       fix += 2;
     }
   fragp->fr_fix += fix;
 
-  fragp->fr_var = 4;
-  memcpy (p, nop32, 4);
+  if (bytes != 0)
+    {
+      fragp->fr_var = 4;
+      memcpy (p, nop32, 4);
+    }
 }
 
 /* md_flush_pending_output  */
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index eef82d7..b59a2f5 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -6887,6 +6887,9 @@
 {
   valueT count = (fragP->fr_next->fr_address
 		  - (fragP->fr_address + fragP->fr_fix));
+  if (count == 0)
+    return;
+
   char *dest = fragP->fr_literal + fragP->fr_fix;
   enum ppc_nop_encoding_for_rs_align_code nop_select = *dest & 0xff;
 
@@ -6894,8 +6897,7 @@
      We could pad with zeros up to an instruction boundary then follow
      with nops but odd counts indicate data in an executable section
      so padding with zeros is most appropriate.  */
-  if (count == 0
-      || (nop_select == PPC_NOP_VLE ? (count & 1) != 0 : (count & 3) != 0))
+  if (nop_select == PPC_NOP_VLE ? (count & 1) != 0 : (count & 3) != 0)
     {
       *dest = 0;
       return;