This is an archive of the discontinued LLVM Phabricator instance.

[JumpThreading] Fix infinite loop (PR44611)
ClosedPublic

Authored by kazu on Mar 18 2020, 3:09 PM.

Details

Summary

This patch fixes https://bugs.llvm.org/show_bug.cgi?id=44611 by
preventing an infinite loop in the jump threading pass when
-jump-threading-across-loop-headers is on. Specifically, without this
patch, jump threading through two basic blocks would trigger on the
same area of the CFG over and over, resulting in an infinite loop.

Consider testcase PR44611-across-header-hang.ll in this patch. The
first opportunity to thread through two basic blocks is:

from bb_body2 through bb_header and bb_body1 to bb_body2.

The pass duplicates bb_header and bb_body1 as, say, bb_header.thread1
and bb_body1.thread1. Since bb_header contains a successor edge back
to itself, bb_header.thread1 also contains a successor edge to
bb_header, immediately giving rise to the next jump threading
opportunity:

from bb_header.thread1 through bb_header and bb_body1 to bb_body2.

After that, we repeatedly thread an incoming edge into bb_header
through bb_header and bb_body1 to bb_body2. In other words, we keep
peeling one iteration from bb_header's self loop.

The patch fixes the problem by preventing the pass from duplicating a
basic block containing a self loop.

Diff Detail

Event Timeline

kazu created this revision.Mar 18 2020, 3:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2020, 3:09 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
efriedma accepted this revision.Mar 19 2020, 12:01 PM

LGTM with one minor change

llvm/lib/Transforms/Scalar/JumpThreading.cpp
2137

llvm::is_contained

This revision is now accepted and ready to land.Mar 19 2020, 12:01 PM
kazu updated this revision to Diff 251455.Mar 19 2020, 12:58 PM

Incorporated feedback from efriedma to use llvm::is_contained instead
of llvm::find.

kazu marked an inline comment as done.Mar 19 2020, 12:59 PM
This revision was automatically updated to reflect the committed changes.