diff --git a/gcc/configure b/gcc/configure
index 6f5fc20fcf33deb91573f5638e2833b1603899ca..14b19c8fe0c16a46900368f5149261da6734f972 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -26034,11 +26034,11 @@ if test -f liblto_plugin.la; then
     # Require GNU ld or gold 2.21+ for plugin support by default.
     if test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -ge 21; then
       gcc_cv_lto_plugin=2
+    elif test "$ld_is_mold" = yes; then
+      gcc_cv_lto_plugin=2
     # Allow -fuse-linker-plugin to enable plugin support in GNU gold 2.20.
     elif test "$ld_is_gold" = yes -a "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -eq 20; then
       gcc_cv_lto_plugin=1
-    elif test "$ld_is_mold" = yes; then
-      gcc_cv_lto_plugin=1
     fi
   fi
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 3d85d33bc805a68a3db90127a754e9fd6c342c24..90cad3097621eba8c2e4b73943a0b34d4e9defb1 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -4275,11 +4275,11 @@ changequote([,])dnl
     # Require GNU ld or gold 2.21+ for plugin support by default.
     if test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -ge 21; then
       gcc_cv_lto_plugin=2
+    elif test "$ld_is_mold" = yes; then
+      gcc_cv_lto_plugin=2
     # Allow -fuse-linker-plugin to enable plugin support in GNU gold 2.20.
     elif test "$ld_is_gold" = yes -a "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -eq 20; then
       gcc_cv_lto_plugin=1
-    elif test "$ld_is_mold" = yes; then
-      gcc_cv_lto_plugin=1
     fi
   fi