--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -10234,11 +10234,7 @@ static int
 aarch64_parse_features (const char *str, const aarch64_feature_set **opt_p,
 			bool ext_only)
 {
-  /* We insist on extensions being added before being removed.  We achieve
-     this by using the ADDING_VALUE variable to indicate whether we are
-     adding an extension (1) or removing it (0) and only allowing it to
-     change in the order -1 -> 1 -> 0.  */
-  int adding_value = -1;
+  bool adding_value = false;
   aarch64_feature_set *ext_set = XNEW (aarch64_feature_set);
 
   /* Copy the feature set, so that we can modify it.  */
@@ -10269,31 +10265,20 @@ aarch64_parse_features (const char *str, const aarch64_feature_set **opt_p,
 
       if (optlen >= 2 && startswith (str, "no"))
 	{
-	  if (adding_value != 0)
-	    adding_value = 0;
+	  adding_value = 0;
 	  optlen -= 2;
 	  str += 2;
 	}
       else if (optlen > 0)
 	{
-	  if (adding_value == -1)
-	    adding_value = 1;
-	  else if (adding_value != 1)
-	    {
-	      as_bad (_("must specify extensions to add before specifying "
-			"those to remove"));
-	      return false;
-	    }
+	  adding_value = 1;
 	}
-
-      if (optlen == 0)
+      else if (optlen == 0)
 	{
 	  as_bad (_("missing architectural extension"));
 	  return 0;
 	}
 
-      gas_assert (adding_value != -1);
-
       for (opt = aarch64_features; opt->name != NULL; opt++)
 	if (strncmp (opt->name, str, optlen) == 0)
 	  {
diff --git a/gas/testsuite/gas/aarch64/opt_order.l b/gas/testsuite/gas/aarch64/opt_order.l
new file mode 100644
index 0000000000000000000000000000000000000000..94820513356d2d3c2a02c1f348e2c5423e43f1cd
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order.l
@@ -0,0 +1 @@
+#...
diff --git a/gas/testsuite/gas/aarch64/opt_order.s b/gas/testsuite/gas/aarch64/opt_order.s
new file mode 100644
index 0000000000000000000000000000000000000000..e0642b3a811ad7d944418f36e237e6fd87771051
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order.s
@@ -0,0 +1 @@
+UDOT    V0.2S, V0.8B, V0.8B
diff --git a/gas/testsuite/gas/aarch64/opt_order_1.d b/gas/testsuite/gas/aarch64/opt_order_1.d
new file mode 100644
index 0000000000000000000000000000000000000000..862f7be85f462bfc470a466e9652471d0d268652
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order_1.d
@@ -0,0 +1,4 @@
+# source: opt_order.s
+# as: -march=armv8.2-a+nodotprod+fp16+dotprod
+# objdump: -dr
+#...
diff --git a/gas/testsuite/gas/aarch64/opt_order_2.d b/gas/testsuite/gas/aarch64/opt_order_2.d
new file mode 100644
index 0000000000000000000000000000000000000000..77bd6c57ec9be2e24c3b673f4eccb2c0f7bfc16c
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order_2.d
@@ -0,0 +1,4 @@
+# source: opt_order.s
+# as: -march=armv8.2-a+fp16+nodotprod+dotprod
+# objdump: -dr
+#...
diff --git a/gas/testsuite/gas/aarch64/opt_order_3.d b/gas/testsuite/gas/aarch64/opt_order_3.d
new file mode 100644
index 0000000000000000000000000000000000000000..5b22090331d11965097a35bad181693c75d51f3c
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order_3.d
@@ -0,0 +1,4 @@
+# source: opt_order.s
+# as: -march=armv8.2-a+dotprod+fp16+dotprod
+# objdump: -dr
+#...
diff --git a/gas/testsuite/gas/aarch64/opt_order_4.d b/gas/testsuite/gas/aarch64/opt_order_4.d
new file mode 100644
index 0000000000000000000000000000000000000000..7ffe2a3011632fdcf25aa32eeb1bedbcc1f408ba
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order_4.d
@@ -0,0 +1,5 @@
+# source: opt_order.s
+# as: -march=armv8.2-a+nodotprod+fp16+nodotprod
+# objdump: -dr
+#error_output: opt_order.l
+#...
diff --git a/gas/testsuite/gas/aarch64/opt_order_5.d b/gas/testsuite/gas/aarch64/opt_order_5.d
new file mode 100644
index 0000000000000000000000000000000000000000..e7d057c77e7efa14caf55c96cba321e99c36ca21
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order_5.d
@@ -0,0 +1,5 @@
+# source: opt_order.s
+# as: -march=armv8.2-a+dotprod+fp16+nodotprod
+# objdump: -dr
+#error_output: opt_order.l
+#...
diff --git a/gas/testsuite/gas/aarch64/opt_order_6.d b/gas/testsuite/gas/aarch64/opt_order_6.d
new file mode 100644
index 0000000000000000000000000000000000000000..b39247de3b3c7261a700b96be8cfbf6b781cbb6b
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/opt_order_6.d
@@ -0,0 +1,5 @@
+# source: opt_order.s
+# as: -march=armv8.2-a+fp16+dotprod+nodotprod
+# objdump: -dr
+#error_output: opt_order.l
+#...
