Open vext01 opened 2 years ago
https://github.com/ykjit/ykllvm/pull/24 works around this by disabling the optimisation, but in the long run we should find a better way.
This is related to https://github.com/ykjit/yk/issues/610, in the sense that both are "unusual control flow things we don't handle".
At
clang -O3
on amd64 is codegenned to:Here
fwrite
is jumped to, rather than called. The compiler does this because it's cheaper to re-use the caller's frame (where possible, and here it is). This means that the x86ret
instruction offwrite()
will effectively return from bothf()
andfwrite()
.The optimisation happens during instruction selection, meaning that the IR used to build traces always contains a
call
IR instruction regardless of whether this optimisation is applied.The optimisation confuses the trace compiler, which, after seeing the IR call to
fwrite
expects to see trace execution pass through a block containing aret
IR instruction forfwrite
, but of course one never comes.