Refactor recode test loop

Consolidated overlay checking into recode test loop. This was a
refactoring CL.

Change-Id: I43963675d337a6333c9f1c2f51da0610c4c4a313
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 8ed9952..cc681bc 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2552,19 +2552,11 @@
       recode_loop_update_q(cpi, &loop, &q, &q_low, &q_high, top_index,
                            bottom_index, &undershoot_seen, &overshoot_seen,
                            &low_cr_seen, loop_count);
-    }
 
-    // Special case for overlay frame.
-    if (loop && rc->is_src_frame_alt_ref &&
-        rc->projected_frame_size < rc->max_frame_bandwidth) {
-      loop = 0;
-    }
-
-    if (allow_recode && !cpi->sf.gm_sf.gm_disable_recode &&
-        av1_recode_loop_test_global_motion(cm->global_motion,
-                                           cpi->td.rd_counts.global_motion_used,
-                                           gm_info->params_cost)) {
-      loop = 1;
+      if (!loop && !cpi->sf.gm_sf.gm_disable_recode)
+        loop = av1_recode_loop_test_global_motion(
+            cm->global_motion, cpi->td.rd_counts.global_motion_used,
+            gm_info->params_cost);
     }
 
     if (loop) {
diff --git a/av1/encoder/rc_utils.h b/av1/encoder/rc_utils.h
index b30ef28..98cec2e 100644
--- a/av1/encoder/rc_utils.h
+++ b/av1/encoder/rc_utils.h
@@ -229,6 +229,11 @@
   const RateControlCfg *const rc_cfg = &cpi->oxcf.rc_cfg;
   *loop = 0;
 
+  // Special case for overlay frame.
+  if (rc->is_src_frame_alt_ref &&
+      rc->projected_frame_size < rc->max_frame_bandwidth)
+    return;
+
   const int min_cr = rc_cfg->min_cr;
   if (min_cr > 0) {
     aom_clear_system_state();
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index 9f2a99b..f2d9707 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -123,11 +123,11 @@
   /*
    * Allow recode only for KF/ARF/GF frames
    */
-  ALLOW_RECODE_KFARFGF = 2,
+  ALLOW_RECODE_KFARFGF = 1,
   /*
    * Allow recode for all frame types based on bitrate constraints.
    */
-  ALLOW_RECODE = 3,
+  ALLOW_RECODE = 2,
 } UENUM1BYTE(RECODE_LOOP_TYPE);
 
 enum {