Add back the if statement in set_size_literal()

Add back the if statement that checks whether we need to reallocate
compressor data in set_size_literal().

We are not sure that if statement will never be executed. So it is safer
to add it back.

Bug: aomedia:3526
Change-Id: I9953da3f218571e7eeca1b295ba7791fb03a5082
(cherry picked from commit 4f632e5b6d1c3cce0bbbc0f2c030171082fc1b3e)
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 4c15ebf..ce6176c 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2121,6 +2121,7 @@
 // Returns 1 if the assigned width or height was <= 0.
 int av1_set_size_literal(AV1_COMP *cpi, int width, int height) {
   AV1_COMMON *cm = &cpi->common;
+  InitialDimensions *const initial_dimensions = &cpi->initial_dimensions;
   av1_check_initial_width(cpi, cm->seq_params->use_highbitdepth,
                           cm->seq_params->subsampling_x,
                           cm->seq_params->subsampling_y);
@@ -2134,10 +2135,19 @@
   setup_denoiser_buffer(cpi);
 #endif
 
-  // No need to reallocate compressor data.
-  assert(cm->width <= cpi->initial_dimensions.width &&
-         cm->height <= cpi->initial_dimensions.height);
-
+  if (cm->width > initial_dimensions->width ||
+      cm->height > initial_dimensions->height) {
+    av1_free_context_buffers(cm);
+    av1_free_shared_coeff_buffer(&cpi->td.shared_coeff_buf);
+    av1_free_sms_tree(&cpi->td);
+    av1_free_pmc(cpi->td.firstpass_ctx, av1_num_planes(cm));
+    cpi->td.firstpass_ctx = NULL;
+    alloc_compressor_data(cpi);
+    realloc_segmentation_maps(cpi);
+    initial_dimensions->width = cm->width;
+    initial_dimensions->height = cm->height;
+    cpi->frame_size_related_setup_done = false;
+  }
   alloc_mb_mode_info_buffers(cpi);
   av1_update_frame_size(cpi);