[PATCH] [Jump-Threading] Fixed jump threading hang issues (PR15386, PR15851)
Dinesh Dwivedi
dinesh.d at samsung.com
Mon Jun 2 07:50:51 PDT 2014
Forgot to add RUN line in 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
===================================================================
--- test/Transforms/JumpThreading/pr15851_hang.ll
+++ test/Transforms/JumpThreading/pr15851_hang.ll
@@ -0,0 +1,29 @@
+; RUN: opt -S -jump-threading < %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+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.10018.patch
Type: text/x-patch
Size: 2403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140602/08e4a455/attachment.bin>
More information about the llvm-commits
mailing list