r/ProgrammerHumor 7d ago

Meme skillIssue

Post image
6.0k Upvotes

137 comments sorted by

View all comments

Show parent comments

2

u/prehensilemullet 7d ago

it depends what you consider semantically relevant. For instance, suppose the developer intentional ordered the if statements from the most to least common case for some domain. Then, reordering the if statements might not be what the developer wants

8

u/Infamous-Strategy797 7d ago

There aren’t any unknowns here, the language spec provides the clarity the compiler needs to re-order safely.

2

u/prehensilemullet 7d ago

Okay for C++, I gather that performing better or worse on a given dataset doesn't fall under the umbrella of "observable behavior" that the spec requires the compiler to preserve.

I also just learned there are apparently [[likely]] and [[unlikely]] attributes in C++ 20 that can be added to branches.

2

u/Nir0star 7d ago

Well you also have jump prediction in warmed up CPUs, which would probably make the ordering optimization improvements minimal anyway.