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

            Bug ID: 103072
           Summary: Folding common switch code
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: llvm at rifkin dot dev
  Target Milestone: ---

In the following code, GCC can optimize foo but not bar:

void foo(int x) {
    switch(x) {
        case 1: func1(); break;
        case 2: func1(); break;
        case 3: func1(); break;
        case 4: func1(); break;
        case 5: func1(); break;
        default: __builtin_unreachable();
    }
}

void bar(int x) {
    switch(x) {
        case 1: func2(x); break;
        case 2: func2(x); break;
        case 3: func2(x); break;
        case 4: func2(x); break;
        case 5: func2(x); break;
        default: __builtin_unreachable();
    }
}

https://godbolt.org/z/3eqnG71f5 (LLVM optimizes both)

Reply via email to