This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Do not merge landingpads for invokes with deopt state.
AbandonedPublic

Authored by dantrushin on Feb 8 2022, 10:55 AM.

Details

Summary

Invokes with deopt states on them must have unique landingpads
for gc.relocate placement (see RewriteStatepointsForGC.cpp)

Disable landingpad merging for invokes with deopt states in SimplifyCFG,
to avoid need of undoing this optimization later.

Diff Detail

Event Timeline

dantrushin created this revision.Feb 8 2022, 10:55 AM
dantrushin requested review of this revision.Feb 8 2022, 10:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2022, 10:55 AM
lebedev.ri added a subscriber: lebedev.ri.

I'm not sure i understand why this is required. Going through all the invokes
and ensuring that every deopt invoke has a dedicated (empty) landingpad
seems both trivial to do and something that you'd want to do a part of lowering later on anyway?.

llvm/lib/Transforms/Utils/SimplifyCFG.cpp
6659

Why is only the first predecessor checked?

6660

Can landingpad has any other predecessor than an invoke?

llvm/test/Transforms/SimplifyCFG/duplicate-landingpad.ll
1

Please use the script.

I'm not sure i understand why this is required. Going through all the invokes
and ensuring that every deopt invoke has a dedicated (empty) landingpad
seems both trivial to do and something that you'd want to do a part of lowering later on anyway?.

I want to avoid doing optimization which I will undo later.
In our downstream pipeline repeated cycles of simplifycfg + loopsimplify (which undoes this transform, too) finally triggers opt blowup (which is different problem, yes).

dantrushin marked an inline comment as done.Feb 8 2022, 11:16 AM
dantrushin added inline comments.
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
6659

Mainly because I anticipated this question.
If I'd checked all predecessor, I'd been asked why I check all of them.

Initially we start with unique landingpads, so it has single predecessor. If we do not merge them, then it will stay that way.

6660

For the problem I'm interested in, no

dantrushin marked an inline comment as done.

Update test checks

Hot take: then the deopt is simply misdesigned.
The landingpad should simply be non-empty, it should contain a call to some intrinsic with nomerge attribute, so it stays unique.
(It sounds quite similar to the hasaddresstaken brokenness.)

More realistically, then we need to add the opposite transform into simplifycfg.

Reading through the review, I see what look like two related issues.

  1. RS4GC expects unique landing pads for calls being wrapped in statepoints. I don't get why this review phrases this as a property of deopt bundles; this seems like either a) a bug in RS4GC we should just fix or b) a restriction of the abstract machine model (i.e. a function of the GC attribute on the function.)

I'd also think this would be really easy to do in RS4GC as we already have all the utilities for splitting edges. Assuming there's not a deeper semantic issue I'm missing on first glance, I'd strongly prefer fixing RS4GC.

  1. There's a reported infinite loop bug that sounds completely unrelated. A reproducer for that should be filed as it's own bug asap.

RS4GC knows how to split edges. so it can do it.
What I've been trying to do is to avoid repeatable merging (performed by SimplifyCFG) and splitting (performed by LoopSimplify) of landingpads.
Since these passes are run before RS4GC, we do not have statepoints in IR yet.

As for opt blowup I mentioned, it is not infinite loop, but an IR produced by repeatable application of above simplifyCFG + LoopSimplify.
When splitting landingpads, LoopSimplify adds '.split-lp' suffix to block name. After several repetitions, we get an IR which is cannot be read back by LLVM (fails verification), but which is correct by eye inspection.
Presumably, length of generated labels leads to such behavior. Unfortunately, I was unable to prepare test case which I can publish, so let's ignore that part for now.

dantrushin abandoned this revision.Mar 4 2022, 8:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2022, 8:22 AM