[LLVMdev] Missed optimization with indirectbr terminator

John McCall rjmccall at apple.com
Thu Jul 7 10:41:16 PDT 2011

On Jul 7, 2011, at 4:33 AM, Carlo Alberto Ferraris wrote:
> Il 07/07/2011 11:14, Cameron Zwarich ha scritto:
>> I haven't read the code in detail, but it looks like JumpThreading at least attempts to thread across indirect branches. You can either try to fix it or file a bug with your test case.
> In the source it says "If the predecessor is an indirect goto, we can't split the edge." Why would that be the case?

Splitting an edge creates a block which executes when leaving a
specific block to go to a specific successor.  The only way to split an
indirect goto is to insert code before the jump which checks for a
specific destination address.  This is very likely to be a pessimization.

To answer your original question, the current implementation design
for indirect goto is intentionally based around having a single block
that terminates in an indirectbr.  Otherwise the CFG of a
context-threaded interpreter loop becomes inherently O(N^2): there
are N instruction labels, each of which has approximately N
predecessors.  We rely on a code-generation optimization, tail
duplication, to actually restore the context-threading behavior.

In short, don't look at the IR for whether context-threading is
happening;  look at the generated code.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110707/9958ba8d/attachment.html>

More information about the llvm-dev mailing list