__builtin_expect hint ignored

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

__builtin_expect hint ignored

Robinson, Paul via cfe-dev
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();
    }
}
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: __builtin_expect hint ignored

Robinson, Paul via cfe-dev
I see this with clang trunk on the website too. Perhaps of interest to llvm-dev?

On Tue, Apr 18, 2017 at 2:56 PM, Adam Nowacki via cfe-dev <[hidden email]> wrote:
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();
    }
}
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: __builtin_expect hint ignored

Robinson, Paul via cfe-dev
In reply to this post by Robinson, Paul via cfe-dev
Interestingly, clang 3.6 seemed to do the right thing, but 3.7 onwards ignores __builtin_expect for this particular case.

All versions of gcc and Intel both generate jump tables, which I assume is even less optimal in this case.


- ½

On 18 April 2017 at 17:56, Adam Nowacki via cfe-dev <[hidden email]> wrote:
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();
    }
}
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...