by 2102922286 · 3y ago · 0 comments
I can only assume the compiler is marking all the bounds checks as unlikely to fail, and correctly predicted branches must be more or less free in modern CPUs. It’s the only way I can explain it.
It is a common low level optimization to add a wide boundary check in the beginning to avoid successive smaller bounds checks.
You can see this pretty easily in compiler explorer. This is a simple array lookup compiled in release mode:
[0] https://clang.llvm.org/docs/LanguageExtensions.html#builtin-...
Thanks!
I've always felt uncomfortable about PGO for more complex programs because of this.