Commit 26347f13f7 for aom

commit 26347f13f7bd27125f2f9ef17453dbef9b2c6438
Author: Frank Galligan <fgalligan@google.com>
Date:   Tue Nov 10 19:41:49 2026 -0800

    txb_rdopt: hoist qmatrix lookup above rdmult

    Hoist xd->mi[0]->segment_id and resolve the segment's iqmatrix and
    qmatrix pointers right before get_txb_rdmult() in
    av1_optimize_txb_multi(). Loading segment_id once alongside
    is_inter_block() avoids spilling or reloading xd->mi[0] across
    get_txb_rdmult() and get_scan().

    Speedup vs origin/main (AMD EPYC 7B13, --cpu-used=6, x86_64 AVX2,
    bit-exact):
      -0.82% (1T) / -2.44% (8T) 1080p allintra,
      -2.04% 720p allintra (8T, 10-rep), -3.44% 720p good (8T).
    Binary size (x86_64 -O3): libaom.a .text -0.2 KiB (-0.00%),
      .rodata +0.1 KiB (+0.01%); stripped aomenc +0.0 KiB (+0.00%).
    Memory (peak RSS, 1080p allintra): +1236 KiB 1T / +340 KiB 8T
      (allocator variance; no heap or stack allocations added).

    TAG=agy
    CONV=b929a630-a6cd-45a0-979c-1767c30178ee

    Change-Id: Ic8bef5ccf9f3dce3c608086f05112763ebc98023

diff --git a/av1/encoder/txb_rdopt.c b/av1/encoder/txb_rdopt.c
index a2526a3e5a..42d00b8328 100644
--- a/av1/encoder/txb_rdopt.c
+++ b/av1/encoder/txb_rdopt.c
@@ -653,6 +653,16 @@ int av1_optimize_txb_multi(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
   int eob = p->eobs[block];
   assert(eob > 1);
   const PLANE_TYPE plane_type = get_plane_type(plane);
+  const int seg_id = xd->mi[0]->segment_id;
+  // Resolve qmatrix pointers before get_txb_rdmult() so xd->mi[0] is loaded
+  // once alongside use_intrabc before av1_get_variance_stats().
+  const qm_val_t *const iqmatrix =
+      tx_type < IDTX ? xd->plane[plane].seg_iqmatrix[seg_id][tx_size] : NULL;
+  const qm_val_t *const qmatrix =
+      (cpi->oxcf.tune_cfg.dist_metric == AOM_DIST_METRIC_QM_PSNR &&
+       tx_type < IDTX)
+          ? xd->plane[plane].seg_qmatrix[seg_id][tx_size]
+          : NULL;
   int is_noise_pattern = 0;
   const int64_t rdmult = get_txb_rdmult(cpi, x, xd, plane, plane_type,
                                         sharpness, &is_noise_pattern);
@@ -660,15 +670,6 @@ int av1_optimize_txb_multi(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
   const int16_t *scan = scan_order->scan;
   const int shift = av1_get_tx_scale(tx_size);
   const int16_t *dequant = p->dequant_QTX;
-  const qm_val_t *iqmatrix =
-      tx_type < IDTX
-          ? xd->plane[plane].seg_iqmatrix[xd->mi[0]->segment_id][tx_size]
-          : NULL;
-  const qm_val_t *qmatrix =
-      (cpi->oxcf.tune_cfg.dist_metric == AOM_DIST_METRIC_QM_PSNR &&
-       tx_type < IDTX)
-          ? xd->plane[plane].seg_qmatrix[xd->mi[0]->segment_id][tx_size]
-          : NULL;
   const int block_offset = BLOCK_OFFSET(block);
   tran_low_t *qcoeff = p->qcoeff + block_offset;
   tran_low_t *dqcoeff = p->dqcoeff + block_offset;