This is an archive of the discontinued LLVM Phabricator instance.

[JumpThreading] Fix PR44611
AbandonedPublic

Authored by junparser on Mar 11 2020, 1:58 AM.

Details

Reviewers
kazu
wmi
Summary

As title, this patch fixes hang (https://bugs.llvm.org/show_bug.cgi?id=44611) which caused by unreachable cycles inside cfg when build with jump-threading-across-loop-headers.

TestPlan: check-llvm

Diff Detail

Event Timeline

junparser created this revision.Mar 11 2020, 1:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2020, 1:58 AM
kazu added a comment.Mar 13 2020, 3:05 PM

Hi junparser, your main change in JumpThreading.cpp looks good. Now, could you explain your change in removed-use.ll? To be honest, I haven't understood the original intent of the testcase. Thanks!

efriedma added inline comments.
llvm/lib/Transforms/Scalar/JumpThreading.cpp
455

We've been trying to avoid calling getDomTree() in JumpThreading where possible because there's a performance cost: it actually flushes all the pending DomTree updates. Calling it for every basic block will likely cause performance issues. (You should be able to find some discussion of this in the review threads for the related JumpThreading patches.)

Hi junparser, your main change in JumpThreading.cpp looks good. Now, could you explain your change in removed-use.ll? To be honest, I haven't understood the original intent of the testcase. Thanks!

It's just that the testcase need to be updated after this patch, I just make some simplification since bb3 -> bb4 -> bb5 is an unreachable cycle and we do not need to handle them.

junparser marked an inline comment as done.Mar 15 2020, 6:05 PM
junparser added inline comments.
llvm/lib/Transforms/Scalar/JumpThreading.cpp
455

Yes, I have already know about that. That's why i add this check at the end of for statement after other checks. However, for unreachable cycles, I afraid maybe this is the only way to check (maybe I am wrong).

Btw, the condition can be update to:

if (Changed && !DTU->getDomTree().isReachableFromEntry(&BB))

which can reduce the performance cost.

efriedma added inline comments.Mar 16 2020, 11:55 AM
llvm/lib/Transforms/Scalar/JumpThreading.cpp
455

I'd like to see some actual numbers for the performance impact, similar to what was done in the past.

Where exactly is the infinite loop coming from? We already have some code which should guard the use of LazyValueInfo.

kazu added a comment.Mar 16 2020, 12:16 PM

Sorry, the infinite recursion seems to come from EvaluateOnPredecessorEdge, a function that I recently added to support jump threading across two basic blocks. EvaluateOnPredecessorEdge does not have a guard against infinite recursion while its close cousin ComputeValueKnownInPredecessors does.

The best thing to do is to get rid of the code duplication I introduced, namely EvaluateOnPredecessorEdge, but for now we can detect infinite recursion by maintaining RecursionSet much like ComputeValueKnownInPredecessors. Alternatively, we could pass a recursion depth and stop recursion when we reach a certain limit. We have a limit on the number of LLVM IR statements we duplicate, so we could use that as a starting point.

Anyway, let me try to come up with something.

Sorry, the infinite recursion seems to come from EvaluateOnPredecessorEdge, a function that I recently added to support jump threading across two basic blocks. EvaluateOnPredecessorEdge does not have a guard against infinite recursion while its close cousin ComputeValueKnownInPredecessors does.

The best thing to do is to get rid of the code duplication I introduced, namely EvaluateOnPredecessorEdge, but for now we can detect infinite recursion by maintaining RecursionSet much like ComputeValueKnownInPredecessors. Alternatively, we could pass a recursion depth and stop recursion when we reach a certain limit. We have a limit on the number of LLVM IR statements we duplicate, so we could use that as a starting point.

Anyway, let me try to come up with something.

Thanks for the clarification, I'll let you handle this:)