[PATCH] [Jump-Threading] Fixed jump threading hang issues (PR15386, PR15851)
Dinesh Dwivedi
dinesh.d at samsung.com
Tue Jun 10 05:57:07 PDT 2014
updated test case
http://reviews.llvm.org/D3991
Files:
lib/Transforms/Scalar/JumpThreading.cpp
test/Transforms/JumpThreading/pr15851_hang.ll
Index: lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- lib/Transforms/Scalar/JumpThreading.cpp
+++ lib/Transforms/Scalar/JumpThreading.cpp
@@ -160,10 +160,12 @@
FindLoopHeaders(F);
- bool Changed, EverChanged = false;
+ unsigned UpdatedBBCount;
+ SmallPtrSet<BasicBlock *, 16> UpdatedBB;
do {
- Changed = false;
+ UpdatedBBCount = UpdatedBB.size();
for (Function::iterator I = F.begin(), E = F.end(); I != E;) {
+ bool Changed = false;
BasicBlock *BB = I;
// Thread all of the branches we can over this block.
while (ProcessBlock(BB))
@@ -180,7 +182,7 @@
LoopHeaders.erase(BB);
LVI->eraseBlock(BB);
DeleteDeadBlock(BB);
- Changed = true;
+ UpdatedBB.insert(BB);
continue;
}
@@ -214,12 +216,13 @@
if (ErasedFromLoopHeaders)
LoopHeaders.insert(BB);
}
+ if (Changed)
+ UpdatedBB.insert(BB);
}
- EverChanged |= Changed;
- } while (Changed);
+ } while (UpdatedBBCount < UpdatedBB.size());
LoopHeaders.clear();
- return EverChanged;
+ return UpdatedBBCount > 0;
}
/// getJumpThreadDuplicationCost - Return the cost of duplicating this block to
Index: test/Transforms/JumpThreading/pr15851_hang.ll
===================================================================
--- /dev/null
+++ test/Transforms/JumpThreading/pr15851_hang.ll
@@ -0,0 +1,38 @@
+; RUN: timeout 10s opt -S -jump-threading < %s | FileCheck %s
+
+; CHECK-LABEL: @f(
+; CHECK-LABEL: for.cond1
+; CHECK: phi i32 [ %div, %for.body ], [ %div, %land.rhs ], [ 0, %for.body.thread ]
+; CHECK: br i1 %cmp, label %for.body, label %for.cond1.thread
+; CHECK: for.cond1.thread
+; CHECK-NEXT: br label %for.body.thread
+; CHECK: for.body.thread
+; CHECK-NEXT: br label %for.cond1
+; CHECK: for.body
+; CHECK: phi i32 [ %inc, %for.cond1 ]
+; CHECK-NOT: for.inc
+
+define void @f() {
+entry:
+ call void @f()
+ unreachable
+
+for.cond1: ; preds = %for.cond1, %for.inc
+ %i.0 = phi i32 [ %inc, %for.inc ], [ 0, %for.cond1 ]
+ %cmp = icmp slt i32 %i.0, 2
+ br i1 %cmp, label %for.body, label %for.cond1
+
+for.body: ; preds = %for.cond1
+ %div = sdiv i32 %i.0, 2
+ %i.0.off = add i32 %i.0, 1
+ %0 = icmp ugt i32 %i.0.off, 2
+ br i1 %0, label %land.rhs, label %for.inc
+
+land.rhs: ; preds = %for.body
+ store i32 0, i32* undef, align 4
+ br label %for.inc
+
+for.inc: ; preds = %for.body
+ %inc = add nsw i32 %div, 1
+ br label %for.cond1
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3991.10272.patch
Type: text/x-patch
Size: 2518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140610/85fcb9cf/attachment.bin>
More information about the llvm-commits
mailing list