Is there a way (at least in GCC or clang's take on C and C++) to mark (un-)likely situations that doesn't involve conditionals?

Like, for example, in `(x + 1) % y` I want to be able to tell the compiler that x+1 is likely to be less than y so it can (perhaps automagically) do a fast path for that situation :cirnothinking:

@koakuma

You can make up a conditional to do so: stackoverflow.com/a/26195434

It's always unclear whether the optimizer will be able to make use of that, but I'm pretty sure that (as long as the conditional expression is obviously side-effect-free) the optimizer will remove the conditional if its body is just assume_unreachable.

Follow

@koakuma

Ah, sorry, s/conditional with assume_unreachable inside/conditional with (un)likely around the condition with empty body/

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.