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

            Bug ID: 86525
           Summary: [missed-optimization] extraneous instruction emitted
                    in switch converted to look-uptable load
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: a...@cloudius-systems.com
  Target Milestone: ---

The code 


enum  xx  { x1 = 1, x2 = 2, x3 = 3, x4, x5, x6 };

unsigned char f(xx x) {
    switch (x) {
    case xx::x1:
        return 2;
    case xx::x2:
        return 2;
    case xx::x3:
        return 7;
    case xx::x4:
        return 7;
    case xx::x5:
        return 7;
    case xx::x6:
        return 9;
    }
}

compiles to (thanks godbolt)

f(xx):
  leal -1(%rdi), %eax
  movzbl CSWTCH.1(%rax), %eax
  ret
CSWTCH.1:
  .byte 2
  .byte 2
  .byte 7
  .byte 7
  .byte 7
  .byte 9

which is lovely, but the lea instruction can be folded into the movzbl
instruction:


  movzbl CSWTCH.1 - 1(%rax), %eax


This assumes that CSWTCH.1 is placed at offset != 0.

Reply via email to