enc: always alloc tile data w/tile count change

Previously the code would retain an earlier allocation if the number of
tiles was less than or equal to the current count. This change always
reallocates tile data when the tile count changes. It avoids holding on
to extra memory unnecessarily. This is an uncommon condition, so there's
no need to optimize this.

Note this may be unnecessary after
  c2daa0f13c Use enc_row_mt->allocated_tile_cols/rows correctly
but given the complex logic around this code, forcing the allocation may
be safest.

Bug: 487259772
Change-Id: I6acd5febcd79dce89b59869bf65386df2c993dc8
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 6cc6770..6f3bbc2 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1564,9 +1564,8 @@
   int tile_col, tile_row;
 
   MACROBLOCK *const mb = &cpi->td.mb;
-  assert(IMPLIES(cpi->tile_data == NULL,
-                 cpi->allocated_tiles < tile_cols * tile_rows));
-  if (cpi->allocated_tiles < tile_cols * tile_rows) av1_alloc_tile_data(cpi);
+  assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
+  if (cpi->allocated_tiles != tile_cols * tile_rows) av1_alloc_tile_data(cpi);
 
   av1_init_tile_data(cpi);
   av1_alloc_mb_data(cpi, mb);
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 1c8d1bd..4f5fe5d 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -249,6 +249,7 @@
   av1_row_mt_mem_dealloc(cpi);
 
   // Allocate memory for row based multi-threading
+  assert(cpi->allocated_tiles == tile_cols * tile_rows);
   for (tile_row = 0; tile_row < tile_rows; tile_row++) {
     for (tile_col = 0; tile_col < tile_cols; tile_col++) {
       int tile_index = tile_row * tile_cols + tile_col;
@@ -1745,9 +1746,8 @@
   const int tile_rows = cm->tiles.rows;
   int num_workers = mt_info->num_mod_workers[MOD_ENC];
 
-  assert(IMPLIES(cpi->tile_data == NULL,
-                 cpi->allocated_tiles < tile_cols * tile_rows));
-  if (cpi->allocated_tiles < tile_cols * tile_rows) av1_alloc_tile_data(cpi);
+  assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
+  if (cpi->allocated_tiles != tile_cols * tile_rows) av1_alloc_tile_data(cpi);
 
   av1_init_tile_data(cpi);
   num_workers = AOMMIN(num_workers, mt_info->num_workers);
@@ -1935,9 +1935,10 @@
        enc_row_mt->allocated_rows != max_sb_rows_in_tile ||
        enc_row_mt->allocated_cols != (max_sb_cols_in_tile - 1) ||
        enc_row_mt->allocated_sb_rows != sb_rows_in_frame);
-  const bool alloc_tile_data = cpi->allocated_tiles < tile_cols * tile_rows;
+  const bool alloc_tile_data = cpi->allocated_tiles != tile_cols * tile_rows;
 
   assert(IMPLIES(cpi->tile_data == NULL, alloc_tile_data));
+  assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
   if (alloc_tile_data) {
     av1_alloc_tile_data(cpi);
   }
@@ -2013,9 +2014,10 @@
   const bool alloc_row_mt_mem = enc_row_mt->allocated_tile_cols != tile_cols ||
                                 enc_row_mt->allocated_tile_rows != tile_rows ||
                                 enc_row_mt->allocated_rows != max_mb_rows;
-  const bool alloc_tile_data = cpi->allocated_tiles < tile_cols * tile_rows;
+  const bool alloc_tile_data = cpi->allocated_tiles != tile_cols * tile_rows;
 
   assert(IMPLIES(cpi->tile_data == NULL, alloc_tile_data));
+  assert(IMPLIES(cpi->tile_data == NULL, cpi->allocated_tiles == 0));
   if (alloc_tile_data) {
     av1_alloc_tile_data(cpi);
   }
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 0c66d7f..07a9d3b 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -1361,7 +1361,7 @@
 
   const int tile_cols = cm->tiles.cols;
   const int tile_rows = cm->tiles.rows;
-  if (cpi->allocated_tiles < tile_cols * tile_rows) {
+  if (cpi->allocated_tiles != tile_cols * tile_rows) {
     av1_alloc_tile_data(cpi);
   }