[llvm-dev] FYI: gc relocations on exception path w/RS4GC currently broken

Joseph Tremoulet via llvm-dev llvm-dev at lists.llvm.org
Sat Jan 23 18:06:47 PST 2016


[speaking to your 2nd idea, because the “change dominance” plan doesn’t accommodate “you want to use this exceptional token with more than one invoke” without token PHIs]

It’s an interesting idea, and some of the ideas we discussed and abandoned were similar to pieces of it.  I think my objections to doing this as stated would be:

1. The lifetime of the token is no longer the lifetime where you’d want to enregister the pointer that gets relocated, so it moves us away from the goal of explicit relocate instructions in the first place – putting an alloca up where you’d put the gc.exceptional.token call and putting stores and loads around the EH edge uses IR artifacts in roughly the same places but without introducing new IR constructs.

2. The “A given exceptional token can be used with exactly one or zero GC statepoint calls” part places an awkward constraint on static code duplication (by which I mean something like jump threading, loop unswitching, etc).  I suppose we already have a notion of “not duplicatable” that applies to thusly-attributed calls and token defs, so code-wise it wouldn’t be invasive to represent that constraint, but it feels like an unnatural constraint.

3. You’re right about “you want to use this exceptional token with more than one invoke”.  We pushed on some similar ideas a bit and realized we were basically working on introducing a back-door way to have token PHIs (that’s arguably exactly what you’ve done, as the uses are correlated with and occur in the predecessor blocks by virtue of appearing on the terminators, and are wedded to the join point by virtue of the exception edge constraints requiring the landingpad to be the immediate successor of the invoke), which seemed to be an indication that it might not be the best-suited abstraction for the job.

4. With unsplittable catchswitches in the mix, the invoke : splittable pad relation is many : many.  I’d rather have one gc.relocate per relocated value after each catchpad, and I think this is going in the direction of requiring (token PHIs or) one gc.relocate per relocated value per predecessor invoke (including transitive predecessors through catchswitches) after each catchpad.  Or I guess gc.relocate could be variadic and just take all the predecessor invokes’ tokens as arguments, but that still seems like more IR than should be needed.

Thanks
-Joseph

From: Reid Kleckner [mailto:rnk at google.com]
Sent: Friday, January 22, 2016 4:39 PM
To: Philip Reames <listmail at philipreames.com>
Cc: llvm-dev <llvm-dev at lists.llvm.org>; Joseph Tremoulet <jotrem at microsoft.com>; Manuel Jacob <me at manueljacob.de>; chenli at azulsystems.com; Sanjoy Das <sanjoy at playingwithpointers.com>
Subject: Re: [llvm-dev] FYI: gc relocations on exception path w/RS4GC currently broken

So, here's a crazy idea. What if we change the definition of dominance for invokes that produce tokens so that the token return value is live out the exceptional edge?

If that's too crazy, what if we used operand bundles to make a new token that "forward declares" the statepoint token:
  %exceptional_token = call token @llvm.gc.exceptional.token()
  %normal_token = invoke @llvm.gc.experimental.statepoint(....) [ "eh_token" token %exceptional_token ]
    to label %normal_dest unwind label %lpad_dest
...
lpad_dest:
  %ehvals = { i8*, i32 } landingpad ... like usual
  %p1 = @llvm.gc.relocate(token %exceptional_token)

A given exceptional token can be used with exactly one or zero GC statepoint calls, so a late pass can map from one to the other and insert reloads in the usual way.

That said, I imagine you want to use this exceptional token with more than one invoke, so that you don't end up needing a landingpad per potentially throwing call site. I think this design can be extended to handle that, though.

On Fri, Jan 22, 2016 at 12:35 PM, Philip Reames via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
For anyone following along on ToT using the gc.statepoint mechanism, you should know that ToT is currently not able to express arbitrary exceptional control flow and relocations along exceptional edges. This is a direct result of moving the gc.statepoint representation to using a token type landingpad.  Essentially, we have a design inconsistency where we expect to be able to "resume" a phi of arbitrary landing pads, but we expect relocations to be tied specifically to a particular invoke.

Chen, Joseph, and I have spent some time talking about how to resolve this.  All of the schemes we've come up with representing relocations using gc.relocates on the exceptional path require either a change to how we define an invoke instruction (something we'd really like to avoid) or a new intrinsic with special treatment in the optimizer so that it basically "becomes part of" the landing pad without actually being the landing pad.  None of us were particular thrilled by the changes involved.

Given exceptional paths are nearly by definition cold, we're currently exploring another option.  We're considering having RS4GC insert explicit spill slots at the IR level (via allocas) for values live along exceptional paths, and leaving all of the normal path values represented as gc.relocates.  This avoids the need for another IR extension, makes it slightly easier to meet an ABI requirement Joseph has, and provides a better platform for lowering experimentation.  Joseph is working on implementing this and will probably have something up for review next week or the week after. Once that's in, we're going to run some performance experiments to see if it's a viable lowering strategy even without Joseph's particular ABI requirement, and if so, make that the standard way of representing relocations on exceptional edges.

Assuming this approach works, we're going to defer solving the problem of how to cleanly represent explicit relocations along the exceptional path until a later point in time.  In particular, the value of the explicit relocations comes mainly from being able to lower them efficiently to register uses.  Since the work to integrate relocations with the register allocator hasn't happened and doesn't look like it's going to happen in the near term (*), this seems like a reasonable compromise.

Philip

(*) To give some context on this, it turns out one of our initial starting assumptions was wrong in practice.  We expected the quality of lowering for the gc arguments at statepoint/safepoint to be very important for overall code quality.  While this may some day become true, we've found that whenever we encounter a hot safepoint, the problem is usually that we didn't inline appropriately.  As a result, we've ended up fixing (out of tree) inlining or devirtualization bugs rather than working on the lowering itself. For us, a truly hot megamorphic call site has turned out to be a very rare beast.  Worth noting is that this is only true because we're a high tier JIT with good profiling information.  It's likely that other users who don't have the same design point may find the lowering far more problematic; in fact, we have some evidence this may already be true.

_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2flists.llvm.org%2fcgi-bin%2fmailman%2flistinfo%2fllvm-dev&data=01%7c01%7cjotrem%40microsoft.com%7cad0c71085d7448cbe9fb08d32374656b%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=uhqlKuPQz2JzEdsp%2by%2fggD8x9i5AembWF4xQ8aUzr38%3d>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160124/5f4b4cae/attachment.html>


More information about the llvm-dev mailing list