logoalt Hacker News

IshKebabtoday at 1:18 PM1 replyview on HN

Wow that is quite surprising. Almost seems like it could be a compiler bug tbh. Very fragile optimisation if not!


Replies

adgjlsfhk1today at 2:07 PM

it's arguably more of a cpu bug than a computer bug. The problem is that predictable data determined whether a cmov or a branch is faster. cmov is only faster than if when the branch is unpredictable. Summer the compiler doesn't know what values your program will be called with, it can only pick and hope. To fix this, cpus could have an instruction like cmov but that learns whether speculation would be profitable and converts to treat it like a branch if better.

show 3 replies