[llvm-dev] Altering the return address , for a function with multiple return paths

Jacob Lifshay via llvm-dev llvm-dev at lists.llvm.org
Sun Jul 21 03:17:58 PDT 2019


one (non-LLVM) problem you will run into is that almost all processors
are optimized to have functions return to the instruction right after
the instruction that called them.

The most common method is to predict where the return instruction will
jump to by using a processor-internal stack of return addresses, which
is separate from the in-memory call stack. This enables the processor
to fetch, decode, and execute instructions following (in program
order) the return instruction before the processor knows for sure what
address the return instruction will branch to. If the return address
turns out to be different than the processor predicted, it has to
throw out all the instructions it started executing that it thought
came after the return, causing massive slow-downs.

For an interesting application of changing the return address, lookup
retpolines.

On Sun, Jul 21, 2019 at 2:07 AM Tsur Herman via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> Playing around with calling conventions naked functions and epilogue/prologue...
> Is it possible/expressible/feasible to alter the return address the function will return to?
>
> For example, when a function may return an Int8 or a Float64, depending on some external state
> (user, or random variable), instead of checking the returned type in the calling function, is it possible
> to pass 2 potential return addresses one suitable for Int8 and one suitable for Float64 and let the function return to the right place?
>
> if it is possible, what are the implications? do these inhibit the optimization opportunities somehow?
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list