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

            Bug ID: 127246
           Summary: [17 Regression] Vectorisation vs computed goto
                    unfactoring
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

We've noticed a large ~30% regression on Cpython performance on aarch64 with
GCC trunk. The problem seems to be with the hot interpreter switch not getting
the pass_duplicate_computed_gotos treatment. A reduced testcase is:
struct frame
{
  const unsigned short *instr_ptr;
  long *stackpointer;
};

/* Opcode number and stack delta.  The deltas must not all be equal, otherwise
   the handler tails are identical and cross-jumping merges them anyway.  */
#define OPS(X)                                                          \
  X (0, -1)  X (1, 0)  X (2, -1)  X (3, 0)  X (4, -1)  X (5, 0)         \
  X (6, -1)  X (7, 0)  X (8, -1)  X (9, 0)  X (10, -1) X (11, 0)        \
  X (12, -1) X (13, 0) X (14, -1) X (15, 0) X (16, -1) X (17, 0)        \
  X (18, -1) X (19, 0)

extern long op (long);

#define DISPATCH()                              \
  {                                             \
    unsigned int word = *next_instr;            \
    goto *targets[word & 0xff];                 \
  }

#define HANDLER(N, SD)                          \
  L_##N:                                        \
    frame->instr_ptr = next_instr;              \
    next_instr += 1;                            \
    frame->stackpointer = stack_pointer;        \
    stack_pointer[-1] = op (N);                 \
    stack_pointer += (SD);                      \
    DISPATCH ();

#define ENTRY(N, SD) &&L_##N,

long
interp (struct frame *frame)
{
  static const void *const targets[] = { OPS (ENTRY) };
  const unsigned short *next_instr = frame->instr_ptr;
  long *stack_pointer = frame->stackpointer;

  DISPATCH ();

  OPS (HANDLER)
}

https://godbolt.org/z/Ee57vv5o9

Reply via email to