Fix a bug in optical flow refinement
diff --git a/av1/common/reconinter.h b/av1/common/reconinter.h
index 717c57e..5bac718 100644
--- a/av1/common/reconinter.h
+++ b/av1/common/reconinter.h
@@ -557,9 +557,15 @@
 #endif  // CONFIG_OPTFLOW_REFINEMENT
 }
 
-static INLINE int av1_is_interp_needed(const MACROBLOCKD *const xd) {
+static INLINE int av1_is_interp_needed(const AV1_COMMON *const cm,
+                                       const MACROBLOCKD *const xd) {
+  (void)cm;
   const MB_MODE_INFO *const mbmi = xd->mi[0];
   if (mbmi->skip_mode) return 0;
+#if CONFIG_OPTFLOW_REFINEMENT
+  // No interpolation filter search when optical flow MV refinement is used.
+  if (mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi)) return 0;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   if (mbmi->motion_mode == WARPED_CAUSAL) return 0;
   if (is_nontrans_global_motion(xd, xd->mi[0])) return 0;
   return 1;
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index b77d7c9..d4c57d9 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1456,12 +1456,7 @@
                                          aom_reader *r) {
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
 
-#if CONFIG_OPTFLOW_REFINEMENT
-  if (!av1_is_interp_needed(xd) || mbmi->mode > NEW_NEWMV ||
-      use_opfl_refine_all(cm, mbmi)) {
-#else
-  if (!av1_is_interp_needed(xd)) {
-#endif  // CONFIG_OPTFLOW_REFINEMENT
+  if (!av1_is_interp_needed(cm, xd)) {
     set_default_interp_filters(mbmi,
 #if CONFIG_OPTFLOW_REFINEMENT
                                cm,
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 00539a2..f95acac 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -865,7 +865,7 @@
   const MB_MODE_INFO *const mbmi = xd->mi[0];
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
 
-  if (!av1_is_interp_needed(xd)) {
+  if (!av1_is_interp_needed(cm, xd)) {
 #if CONFIG_DEBUG
 #if CONFIG_OPTFLOW_REFINEMENT
     // Sharp filter is always used whenever optical flow refinement is applied.
diff --git a/av1/encoder/interp_search.c b/av1/encoder/interp_search.c
index 2427cae..999b511 100644
--- a/av1/encoder/interp_search.c
+++ b/av1/encoder/interp_search.c
@@ -729,12 +729,7 @@
   const int num_planes = av1_num_planes(cm);
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = xd->mi[0];
-#if CONFIG_OPTFLOW_REFINEMENT
-  const int need_search = av1_is_interp_needed(xd) && mbmi->mode <= NEW_NEWMV &&
-                          !use_opfl_refine_all(cm, mbmi);
-#else
-  const int need_search = av1_is_interp_needed(xd);
-#endif  // CONFIG_OPTFLOW_REFINEMENT
+  const int need_search = av1_is_interp_needed(cm, xd);
   const int ref_frame = xd->mi[0]->ref_frame[0];
   RD_STATS rd_stats_luma, rd_stats;
 
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index fd520d0..77b6bbb 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1666,7 +1666,7 @@
   MB_MODE_INFO best_mbmi;
   const int interp_filter = features->interp_filter;
   const int switchable_rate =
-      av1_is_interp_needed(xd)
+      av1_is_interp_needed(cm, xd)
           ? av1_get_switchable_rate(x, xd,
 #if !CONFIG_REMOVE_DUAL_FILTER
                                     cm->seq_params.enable_dual_filter,
@@ -2979,7 +2979,7 @@
   const int mi_row = xd->mi_row;
   const int mi_col = xd->mi_col;
   // Find matching interp filter or set to default interp filter
-  const int need_search = av1_is_interp_needed(xd);
+  const int need_search = av1_is_interp_needed(cm, xd);
   const InterpFilter assign_filter = cm->features.interp_filter;
   int is_luma_interp_done = 0;
   av1_find_interp_filter_match(mbmi, cpi, assign_filter, need_search,
@@ -6296,7 +6296,7 @@
     best_filter = interp_filter;
   } else {
     best_filter = EIGHTTAP_REGULAR;
-    if (av1_is_interp_needed(xd)) {
+    if (av1_is_interp_needed(cm, xd)) {
       int rs;
       int best_rs = INT_MAX;
       for (i = 0; i < SWITCHABLE_FILTERS; ++i) {