Stephen Sprunk said:
A less futuristic example is to consider what happens if f() and g()
can be inlined. Today, since the order of evaluation is unspecified,
the compiler is allowed to mix the execution of the two together with
optimal scheduling; in Kaz's proposal f() must be completed before g()
can start, so the compiler can't produce optimal code. In an extreme
case, like f() being all FP code and g() being all integer code, this
may double execution time.
I am confused again. From elsewhere in the thread, I had the impression
that under the current standard the compiler may execute f() and g() in
either order, but it still must execute them sequentially. So it seems
to me that if f() and g() are inlined, and the compiler wants to mix
their instructions together, it must do so in a manner that behaves "as
if" they were executed sequentially in one order or the other. E.g. in
int i = 10;
int f(void) { i++; i *= 2; return i; }
int g(void) { i++; i *= 3; return i; }
printf("%d %d\n", f(), g());
it can print "22 69" or "33 68". But it cannot move the `i++; i *= 3;' in g()
in between the `i++' and `i *= 2' in f() and print "24 72". I think
you'd need for this code to invoke undefined behavior for that to be
legal, and the consensus seems to be that this code doesn't.
I guess there are three possibilities:
1. The ordering of f() and g() matters to the program.
2. The ordering of f() and g() doesn't matter to the program (they are
independent), and the compiler can prove it.
3. The ordering of f() and g() doesn't matter, but the compiler can't
prove it.
Code in case 1 is currently incorrect, but would be made correct (or at
least well-defined) by the proposal.
It is case 3 that the proposal would hurt. At present the compiler is
free to evaluate them in the more efficient order, at the expense of
causing case 1 to behave unpredictably. Case 2 in principle is
unaffected, since by the "as if" rule if the compiler knows the ordering
doesn't matter, it can choose the more efficient order anyway. But the
other issue is that under the proposal the compiler either has to try
and prove the independence, adding complexity, or else not try, dumping
everything into the less efficient case 3.