[PATCH] D76390: [JumpThreading] Fix infinite loop (PR44611)
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 19 13:09:24 PDT 2020
kazu updated this revision to Diff 251455.
kazu added a comment.
Incorporated feedback from efriedma to use llvm::is_contained instead
of llvm::find.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76390/new/
https://reviews.llvm.org/D76390
Files:
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/PR44611-across-header-hang.ll
Index: llvm/test/Transforms/JumpThreading/PR44611-across-header-hang.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/JumpThreading/PR44611-across-header-hang.ll
@@ -0,0 +1,22 @@
+; RUN: opt -S < %s -jump-threading -jump-threading-across-loop-headers | FileCheck %s
+
+; CHECK-LABEL: @foo
+; Just check that we don't hang on this test.
+
+define void @foo(i32 %a) {
+bb_entry:
+ br label %bb_header
+
+bb_header:
+ %b = phi i32 [ %c, %bb_header ], [ 0, %bb_body1 ], [ 2, %bb_body2 ], [ 0, %bb_entry ]
+ %c = add nuw nsw i32 %b, 1
+ %d = icmp ult i32 %c, 6
+ br i1 %d, label %bb_header, label %bb_body1
+
+bb_body1:
+ %e = icmp eq i32 %a, 0
+ br i1 %e, label %bb_body2, label %bb_header
+
+bb_body2:
+ br label %bb_header
+}
Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -2125,6 +2125,18 @@
if (PredBB->getSinglePredecessor())
return false;
+ // Don't thread through PredBB if it contains a successor edge to itself, in
+ // which case we would infinite loop. Suppose we are threading an edge from
+ // PredPredBB through PredBB and BB to SuccBB with PredBB containing a
+ // successor edge to itself. If we allowed jump threading in this case, we
+ // could duplicate PredBB and BB as, say, PredBB.thread and BB.thread. Since
+ // PredBB.thread has a successor edge to PredBB, we would immediately come up
+ // with another jump threading opportunity from PredBB.thread through PredBB
+ // and BB to SuccBB. This jump threading would repeatedly occur. That is, we
+ // would keep peeling one iteration from PredBB.
+ if (llvm::is_contained(successors(PredBB), PredBB))
+ return false;
+
// Don't thread across a loop header.
if (LoopHeaders.count(PredBB))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76390.251455.patch
Type: text/x-patch
Size: 1953 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200319/03e83b08/attachment.bin>
More information about the llvm-commits
mailing list