[PATCH] D34135: [JumpThreading] Use DT to avoid processing dead blocks
Mikael Holmén via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 04:50:36 PST 2018
uabelho updated this revision to Diff 130139.
uabelho retitled this revision from "[LVI] Add initial result to avoid infinite getValueFromCondition recursion" to "[JumpThreading] Use DT to avoid processing dead blocks".
uabelho edited the summary of this revision.
uabelho added a comment.
Use DT directly in JumpThreading instead of hacking LVI.
https://reviews.llvm.org/D34135
Files:
lib/Transforms/Scalar/JumpThreading.cpp
test/Transforms/JumpThreading/PR33357-lvi-recursion.ll
Index: test/Transforms/JumpThreading/PR33357-lvi-recursion.ll
===================================================================
--- /dev/null
+++ test/Transforms/JumpThreading/PR33357-lvi-recursion.ll
@@ -0,0 +1,44 @@
+; RUN: opt -S -jump-threading -verify -o - %s | FileCheck %s
+
+; Don't enter infinite recursion in LazyValueInfo.cpp
+
+ at a = external global i16, align 1
+
+define void @f(i32 %p1) {
+bb0:
+ %0 = icmp eq i32 %p1, 0
+ br i1 undef, label %bb6, label %bb1
+
+bb1: ; preds = %bb0
+ br label %bb2
+
+bb2: ; preds = %bb4, %bb1
+ %1 = phi i1 [ %0, %bb1 ], [ %2, %bb4 ]
+ %2 = and i1 %1, undef
+ br i1 %2, label %bb3, label %bb4
+
+bb3: ; preds = %bb2
+ store i16 undef, i16* @a, align 1
+ br label %bb4
+
+bb4: ; preds = %bb3, %bb2
+ br i1 %0, label %bb2, label %bb5
+
+bb5: ; preds = %bb4
+ unreachable
+
+bb6: ; preds = %bb0
+ ret void
+}
+
+; The
+; br i1 undef, label %bb6, label %bb1
+; is replaced by
+; br label %bb6
+; and the rest of the function is unreachable from entry and jump-threading
+; shouldn't even ask LazyValueInfo about things in the dead blocks.
+
+; CHECK: define void @f(i32 %p1) {
+; CHECK-NEXT: bb6:
+; CHECK-NEXT: %0 = icmp eq i32 %p1, 0
+; CHECK-NEXT: ret void
\ No newline at end of file
Index: lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- lib/Transforms/Scalar/JumpThreading.cpp
+++ lib/Transforms/Scalar/JumpThreading.cpp
@@ -946,10 +946,9 @@
/// ProcessBlock - If there are any predecessors whose control can be threaded
/// through to a successor, transform them now.
bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
- // If the block is trivially dead, just return and let the caller nuke it.
+ // If the block is dead, just return and let the caller nuke it.
// This simplifies other transformations.
- if (DDT->pendingDeletedBB(BB) ||
- (pred_empty(BB) && BB != &BB->getParent()->getEntryBlock()))
+ if (DDT->pendingDeletedBB(BB) || !DDT->flush().isReachableFromEntry(BB))
return false;
// If this block has a single predecessor, and if that pred has a single
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34135.130139.patch
Type: text/x-patch
Size: 2373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180117/a228bf2a/attachment.bin>
More information about the llvm-commits
mailing list