The following code,
<code>int foo(int);
int bar(int);
int foobar(int i) {
int a = foo(i);
int b = bar(i);
return a == b ? a : b;
};
</code>
<code>int foo(int);
int bar(int);
int foobar(int i) {
int a = foo(i);
int b = bar(i);
return a == b ? a : b;
};
</code>
int foo(int);
int bar(int);
int foobar(int i) {
int a = foo(i);
int b = bar(i);
return a == b ? a : b;
};
with GCC trunk is compiling to this assembly:
<code>foobar(int):
push rbx
mov ebx, edi
call foo(int)
mov edi, ebx
pop rbx
jmp bar(int)
</code>
<code>foobar(int):
push rbx
mov ebx, edi
call foo(int)
mov edi, ebx
pop rbx
jmp bar(int)
</code>
foobar(int):
push rbx
mov ebx, edi
call foo(int)
mov edi, ebx
pop rbx
jmp bar(int)
Here is it live.
This TU has no clue what i
it will be given, and it has no clue what foo
and bar
will return, so it has no clue whether a == b
will be true
or false
. So it must
inspect the outputs of the two calls and somehow compare them to decide which one it shuld return.
But I can’t see that in the assembly. What am I missing?