3 ms·
> I don’t really understand the point you’re trying to make. Figuring out if a value is unused is most definitely the purview of an optimizer. If the conditio
by CyberShadow 5y ago
> I don’t really understand the point you’re trying to make. Figuring out if a value is unused is most definitely the purview of an optimizer.
If the conditional move doesn't happen, then the source (insofar as the move is concerned) is unused.
Consider this pseudocode:
int value = some_nontrivial_function_with_no_side_effects();
if (condition)
*target = value;
Note that the function can be as simple as a memory read.
The compiler could compile this in two ways:
1. Observing that the function's result is used only if condition is true, move the function call inside the if block.
2. Always call the function, as in the source code, but compile the if block to a conditional move.
In such situations, it would make sense to allow programmers to indicate the desired strategy to the compiler.
I suppose CPUs might elide calculating the value even with a conditional move if they can predict the condition is [likely to be] false; I don't know how true that is in practice.
> Also, the “calculating a value” isn’t really the trade off being made between cmov and branching.
Depending on the situation and interpretation of terms, I also agree.
- danachow 5y ago> In such situations, it would make sense to allow programmers to indicate the desired strategy to the compiler. If the function truly has no side effects then why would the programmer care which strategy was used other than cost? This is just an optimization that can be mechanistically applied. And if it does have side effects then the two constructs are not equivalent - one would just put the function call inside the conditional.
- adgjlsfhk1 5y agothe problem is that without pgo, the compiler can't know the odds that a condition will be true.