https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128444

            Bug ID: 128444
           Summary: missed optimization for fold-mem-offsets
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
            Blocks: 26163
  Target Milestone: ---

rv64gcbv.  Also taken from x264:

typedef unsigned char uint8_t;

typedef struct
{
  int i_low;
  int i_range;
  int i_queue;
  int i_bytes_outstanding;
  uint8_t *p_start;
  uint8_t *p;
  uint8_t *p_end;
  int f8_bits_encoded;
  int i_pad[2];
  uint8_t state[1024];
} x264_cabac_t;

extern const uint8_t x264_cabac_range_lps[64][4];

void
f (x264_cabac_t *cb, int i_ctx, int b)
{
  int i_state = cb->state[i_ctx];
  int i_range_lps = x264_cabac_range_lps[i_state >> 1][(cb->i_range >> 6) - 4];
  cb->i_range -= i_range_lps;
  if (b != (i_state & 1))
    {
      cb->i_low += cb->i_range;
      cb->i_range = i_range_lps;
    }
}

Emits this fragment:
        sraiw   t1,a4,6 # 13    [c=8 l=4]  ashrsi3_extend
        sh2add  t2,a5,t0        # 23    [c=4 l=4]  *shNadd
        addiw   a7,t1,-4        # 15    [c=8 l=4]  addsi3_extended/1
        add     t3,t2,a7        # 24    [c=4 l=4]  *adddi3/0
        lbu     t4,0(t3)        # 27    [c=28 l=4] 
*zero_extendqidi2_internal/1

Note the addiw a7, t1, -4.   Conceptually we can sink the -4 offset into the
lbu instructions.  That leaves insn 15 as a sext.w a7, t1.  And that extension
is redundant with the one performed at insn 13.  This is probably around 40m
instructions saved in x264, so small.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26163
[Bug 26163] [meta-bug] missed optimization in SPEC (2026, 2k17, 2k and 2k6 and
95)

Reply via email to