<div dir="ltr">A bug and a repro would be good, even if it's not consistent. I can take a look, having worked with new PM caches/proxies a bit.<div>llvm-reduce'ing the IR with a test that runs the pipeline multiple times would be nice.</div><div><br></div><div>Perhaps wherever the loop is being deleted, it's not calling LPMUpdater::markLoopAsDeleted()? LPMUpdater::markLoopAsDeleted() deletes analysis cache entries for the deleted loop.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 2, 2021 at 3:29 PM Björn Pettersson A via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi!<br>
<br>
Spent lots of time today trying to debug a problem where I end up with sporadic crashes, asserts, etc.<br>
It happens occasionally if I run the same opt test case over and over again, and I see the failures when LoopDistribution is running.<br>
<br>
In the IR there are 2 functions, "f" and "g". Function "f" has several loops, and function "g" has one loop.<br>
<br>
My command line is basically "opt -O3 -enable-loop-distribute -debug-pass-manager=verbose -debug-only=loop-distribute,loop-accesses", but it seems to fail more often (or more seldom) if adding some other parameters as well.<br>
<br>
I've added some debug printouts in LoopDistributeForLoop::processLoop to print the Loop* L variable, and in LoopBase c'tor/d'tor, as that seemed to be relevant.<br>
<br>
<br>
What I've found out is that when it goes bad the output is like this:<br>
<br>
......................<br>
<cut><br>
Running pass: LoopSimplifyPass on f<br>
Running analysis: LoopAnalysis on f<br>
*ADDED-DEBUG* Loop is created: 0x891cc60<br>
<br>
<cut><br>
Running pass: LoopDistributePass on f<br>
<br>
LDist: In "f" checking Loop at depth 3 containing: %<a href="http://for.body10.us.us" rel="noreferrer" target="_blank">for.body10.us.us</a><header><latch><exiting><br>
*ADDED-DEBUG* L used when requesting LAA: 0x891cd08<br>
Running analysis: LoopAccessAnalysis on Loop at depth 3 containing: %<a href="http://for.body10.us.us" rel="noreferrer" target="_blank">for.body10.us.us</a><header><latch><exiting><br>
<br>
LDist: In "f" checking Loop at depth 3 containing: %for.body89<header><latch><exiting><br>
*ADDED-DEBUG* L used when requesting LAA: 0x891cc60<br>
Running analysis: LoopAccessAnalysis on Loop at depth 3 containing: %for.body89<header><latch><exiting><br>
<br>
<cut><br>
Running pass: SimpleLoopUnswitchPass on Loop at depth 2 containing: %for.cond1.preheader<header><exiting>,%<a href="http://for.body10.us.us" rel="noreferrer" target="_blank">for.body10.us.us</a>,%<a href="http://cleanup.thread.split.us.us" rel="noreferrer" target="_blank">cleanup.thread.split.us.us</a>,%for.body89,%crit_edge,%for.inc100<latch><exiting>,%for.body89.preheader,%<a href="http://for.body10.us.us" target="_blank">for.body10.us.us</a>.preheader<br>
*ADDED-DEBUG* Loop is deleted: 0x891cc60<br>
<br>
<cut><br>
Running pass: LoopSimplifyPass on g<br>
Running analysis: LoopAnalysis on g<br>
*ADDED-DEBUG* Loop is created: 0x891cc60<br>
<br>
<cut><br>
Running pass: LoopDistributePass on g<br>
<br>
LDist: In "g" checking Loop at depth 1 containing: %for.cond<header><latch><exiting><br>
*ADDED-DEBUG* L used when requesting LAA: 0x891cc60<br>
<br>
<cut><br>
......................<br>
<br>
And then the pass manager will return the LoopAccessInfo cached for the Loop in function "f".<br>
(Notice that the Loop object happened to reuse the same address for the Loop object used earlier.)<br>
<br>
I don't know if the using object pointers as key to the cached analysis like this is safe in general.<br>
But I guess the problem here is that the cache should have been cleared earlier (when the original Loop was deleted), right?<br>
<br>
Trying to track when LoopBase objects are created and deleted kind of points at that the first Loop object at 0x891cc60 is deleted when doing loop unswitch on a loop at lower depth in function "f". But I'm not sure exactly how the LoopAnalysisManagerFunctionProxy holding the cached LoopAccessAnalysis based on that pointer is supposed to be informed about that. But I suspect that maybe SimpleLoopUnswitchPass is to blame here? (or something in the pass manager framework)<br>
<br>
<br>
I guess I'll need to write a PR for this, but kind of messy since getting the crashes is kind of sporadic. So I might need to find a better way to detect that there is a stale analysis (but a few hours ago I did not know much about how these analyses are cached in the new PM at all, so I haven't really known what to look for).<br>
<br>
If anyone got some ideas how to debug this further, or what to look for, I'm interested to get some guidance how to continue debugging this (or I'll just have to keep banging my head on the wall trying to understand analysis caches and proxies in new PM tomorrow).<br>
<br>
Regards,<br>
Björn<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>