https://godbolt.org/z/dE7eGzojn
bool is_multiple_of(unsigned a, unsigned b) {
return __builtin_expect(a % b == 0, 1);
}
unsigned test(unsigned n, unsigned* out) {
auto b = is_multiple_of(n, 2);
if (b) {
return 0;
} else {
*out = 0;
return 1;
}
}
unsigned test2(unsigned n, unsigned* out) {
auto b = is_multiple_of(n, 2);
// redundant expect call
if (__builtin_expect(b, 1)) {
return 0;
} else {
*out = 0;
return 1;
}
}
test(unsigned int, unsigned int*):
xor eax, eax
test dil, 1
je .LBB1_2
mov dword ptr [rsi], 0
mov eax, 1
.LBB1_2:
ret
test2(unsigned int, unsigned int*):
xor eax, eax
test dil, 1
jne .LBB2_1
ret
.LBB2_1:
mov dword ptr [rsi], 0
mov eax, 1
ret
https://godbolt.org/z/dE7eGzojn