Restrict the number of neighbors in obmc mode

Enable obmc mode only when there are <= 2 left neighbors and <=2
above neighbors. Also disable it when there is no overlappable
neighbors.

Gain in AWCY test: 1.60%, was 1.64% when there is no restriction

Change-Id: I2d82ef4fb4daa9b0843ac8844f99b9f412c4f379
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index c79c558..a64e8df 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -9649,19 +9649,22 @@
 #endif  // CONFIG_REF_MV
 
 #if CONFIG_MOTION_VAR
-  av1_build_prediction_by_above_preds(cm, xd, mi_row, mi_col,
-                                      opt_args.above_pred_buf, dst_width1,
-                                      dst_height1, opt_args.above_pred_stride);
-  av1_build_prediction_by_left_preds(cm, xd, mi_row, mi_col,
-                                     opt_args.left_pred_buf, dst_width2,
-                                     dst_height2, opt_args.left_pred_stride);
-  av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
-  x->mask_buf = mask2d_buf;
-  x->wsrc_buf = weighted_src_buf;
-  calc_target_weighted_pred(
-      cm, x, xd, mi_row, mi_col, opt_args.above_pred_buf[0],
-      opt_args.above_pred_stride[0], opt_args.left_pred_buf[0],
-      opt_args.left_pred_stride[0]);
+  av1_count_overlappable_neighbors(cm, xd, mi_row, mi_col);
+  if (check_num_overlappable_neighbors(mbmi)) {
+    av1_build_prediction_by_above_preds(
+        cm, xd, mi_row, mi_col, opt_args.above_pred_buf, dst_width1,
+        dst_height1, opt_args.above_pred_stride);
+    av1_build_prediction_by_left_preds(cm, xd, mi_row, mi_col,
+                                       opt_args.left_pred_buf, dst_width2,
+                                       dst_height2, opt_args.left_pred_stride);
+    av1_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
+    x->mask_buf = mask2d_buf;
+    x->wsrc_buf = weighted_src_buf;
+    calc_target_weighted_pred(
+        cm, x, xd, mi_row, mi_col, opt_args.above_pred_buf[0],
+        opt_args.above_pred_stride[0], opt_args.left_pred_buf[0],
+        opt_args.left_pred_stride[0]);
+  }
 #endif  // CONFIG_MOTION_VAR
 
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {