>>1
A loop can be inlined if the values of the iteration values can be predicted at compile time. For instance, in
for(int i = 0; i < 5; i++) { printf("%d,", i); }
it is quite clear that the variable i will take on the values, 0, 1, 2, 3, 4, during the execution of the loop. Thus the loop can be unrolled into:
printf("%d", 0); printf("%d", 1); printf("%d", 2); printf("%d", 3); printf("%d", 4);
The key is that the initial values of i and all values in the loop terminate condition must be constant. The increment function must also only depend on constants and the current value of i. With these conditions, the values of the iteration variable can be calculated at compile time and the loop can be unrolled.
In the case of your example, the initial value of i is known at compile if and only if one of the following hold:
* It is known that a < b and the value of x is known at compile time.
* It is known that !(a < b) and the value of y is known at compile time.
The termination condition depends only on constant values and i if and only if the following holds:
* c is a known constant.
So yes, you are right. If the value of the expression (a < b ? x : y) cannot be determined at compile time, then this would prevent total loop unrolling.