[cfe-dev] __builtin_expect hint ignored

Adam Nowacki via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 18 14:56:36 PDT 2017


https://godbolt.org/g/VvrbFZ

For the code below generated assembly is the worst possible - test 1, else test 3, else test 2 with expected value of 2 last ... Whats going on?

long case_2();
long case_3();
long case_1();
long case_else();
long test(long a) {
    switch (__builtin_expect(a, 2)) {
        case 2: return case_2();
        case 3: return case_3();
        case 1: return case_1();
        case 0: 
        case 4: 
        case 5: return case_else();
        default: __builtin_unreachable();
    }
}



More information about the cfe-dev mailing list