3 ms·
Lots of code has apparent branches which compilers effectively optimize. An easy example is integer signbit: int isignbit(int x) { return x < 0 ? 1 : 0; }
by ridiculous_fish 6y ago
Lots of code has apparent branches which compilers effectively optimize. An easy example is integer signbit:
int isignbit(int x) { return x < 0 ? 1 : 0; }
which is reliably optimized to logical right shift.
Are there any code patterns where the compiler emits branches that are not apparent in the code? Notwithstanding overflow checks, etc.
- oddity 6y agoSome targets don't support integer division/remainder or some floating point ops in hardware and automatic vectorization can add/remove branches in places that won't be easily predictable.
- moonchild 6y agoThat's a good point, but a bad example since 'x < 0 ? 1 : 0' is just the same as 'x < 0', which is also be implemented (on x86) as a CMP followed by SETcc.