[PATCH] D89166: Sink: Handle instruction sink when a user is dead
Changpeng Fang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 9 15:49:45 PDT 2020
cfang updated this revision to Diff 297349.
cfang added a comment.
remove checking for findNearestCommonDominator failures.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89166/new/
https://reviews.llvm.org/D89166
Files:
llvm/lib/Transforms/Scalar/Sink.cpp
llvm/test/Transforms/Sink/dead-user.ll
Index: llvm/test/Transforms/Sink/dead-user.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Sink/dead-user.ll
@@ -0,0 +1,42 @@
+; Compiler should not be broken with a dead user.
+; RUN: opt -sink -S < %s | FileCheck %s
+
+; CHECK-LABEL: @test(
+; CHECK: bb.0:
+; CHECK-NEXT: %conv = sext i16 %p1 to i32
+; CHECK-NEXT: br i1 undef, label %bb.1, label %bb.3
+
+; CHECK: bb.1: ; preds = %bb.0
+; CHECK-NEXT: br label %bb.2
+
+; CHECK: bb.2: ; preds = %bb.2, %bb.1
+; CHECK-NEXT: %and.2 = and i32 undef, %conv
+; CHECK-NEXT: br label %bb.2
+
+; CHECK: bb.3: ; preds = %bb.3, %bb.0
+; CHECK-NEXT: %and.3 = and i32 undef, %conv
+; CHECK-NEXT: br label %bb.3
+
+; CHECK: dead: ; preds = %dead
+; CHECK-NEXT: %and.dead = and i32 undef, %conv
+; CHECK-NEXT: br label %dead
+define void @test(i16 %p1) {
+bb.0:
+ %conv = sext i16 %p1 to i32
+ br i1 undef, label %bb.1, label %bb.3
+
+bb.1: ; preds = %bb.0
+ br label %bb.2
+
+bb.2: ; preds = %bb.2, %bb.1
+ %and.2 = and i32 undef, %conv
+ br label %bb.2
+
+bb.3: ; preds = %bb.3, %bb.0
+ %and.3 = and i32 undef, %conv
+ br label %bb.3
+
+dead: ; preds = %dead
+ %and.dead = and i32 undef, %conv
+ br label %dead
+}
Index: llvm/lib/Transforms/Scalar/Sink.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/Sink.cpp
+++ llvm/lib/Transforms/Scalar/Sink.cpp
@@ -135,6 +135,9 @@
for (Use &U : Inst->uses()) {
Instruction *UseInst = cast<Instruction>(U.getUser());
BasicBlock *UseBlock = UseInst->getParent();
+ // Don't worry about dead users.
+ if (!DT.isReachableFromEntry(UseBlock))
+ continue;
if (PHINode *PN = dyn_cast<PHINode>(UseInst)) {
// PHI nodes use the operand in the predecessor block, not the block with
// the PHI.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89166.297349.patch
Type: text/x-patch
Size: 2241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201009/3755971a/attachment.bin>
More information about the llvm-commits
mailing list