[PATCH] D15931: [LoopUnswitch] Create a PHINode for the original landingpad only if it has some uses
Chen Li via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 6 11:32:34 PST 2016
chenli created this revision.
chenli added a reviewer: reames.
chenli added a subscriber: llvm-commits.
This patch adds a check in UnswitchNontrivialCondition to see if the original landingpad instruction has any uses. If not, we don't need to create a PHINode for it after SplitExitEdges. Please refer to D15835 for the motivation.
http://reviews.llvm.org/D15931
Files:
lib/Transforms/Scalar/LoopUnswitch.cpp
test/Transforms/LoopUnswitch/token.ll
Index: test/Transforms/LoopUnswitch/token.ll
===================================================================
--- /dev/null
+++ test/Transforms/LoopUnswitch/token.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -loop-unswitch -S 2>&1 | FileCheck %s
+
+define void @test1(i1 %cond) personality i32 ()* @"dummy_personality" {
+entry:
+ br label %for.cond
+
+for.cond:
+ call void @dummy_call()
+ br i1 %cond, label %for.body, label %for.end
+
+for.body:
+ invoke void @dummy_invoke()
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont:
+ br label %for.inc
+
+lpad:
+ %a = landingpad token
+ cleanup
+ unreachable
+
+for.inc:
+ br label %for.cond
+
+for.end:
+ ret void
+}
+
+; CHECK: lpad.us-lcssa.us: ; preds = %for.body.us
+; CHECK-NEXT: %lpad.us-lcssa1.us = landingpad token
+
+; CHECK: lpad.us-lcssa: ; preds = %for.body
+; CHECK-NEXT: %lpad.us-lcssa1 = landingpad token
+
+; CHECK: lpad: ; preds = %lpad.us-lcssa.us, %lpad.us-lcssa
+; CHECK-NOT: phi token
+
+declare void @dummy_call()
+
+declare void @dummy_invoke()
+
+declare i32 @"dummy_personality"()
Index: lib/Transforms/Scalar/LoopUnswitch.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnswitch.cpp
+++ lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -1060,15 +1060,21 @@
}
if (LandingPadInst *LPad = NewExit->getLandingPadInst()) {
- PHINode *PN = PHINode::Create(LPad->getType(), 0, "",
- &*ExitSucc->getFirstInsertionPt());
-
- for (pred_iterator I = pred_begin(ExitSucc), E = pred_end(ExitSucc);
- I != E; ++I) {
- BasicBlock *BB = *I;
- LandingPadInst *LPI = BB->getLandingPadInst();
- LPI->replaceAllUsesWith(PN);
- PN->addIncoming(LPI, BB);
+ auto *OriginalLPad = ExitBlocks[i]->getLandingPadInst();
+ if (!OriginalLPad->use_empty()) {
+ assert(!LPad->getType()->isTokenTy() &&
+ "Loop unswitch cannot be applied if LPad is token type. "
+ "Otherwise an invalid PHINode of token type would be created.");
+ PHINode *PN = PHINode::Create(LPad->getType(), 0, "",
+ &*ExitSucc->getFirstInsertionPt());
+
+ for (pred_iterator I = pred_begin(ExitSucc), E = pred_end(ExitSucc);
+ I != E; ++I) {
+ BasicBlock *BB = *I;
+ LandingPadInst *LPI = BB->getLandingPadInst();
+ LPI->replaceAllUsesWith(PN);
+ PN->addIncoming(LPI, BB);
+ }
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15931.44138.patch
Type: text/x-patch
Size: 2860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160106/855b4ec5/attachment.bin>
More information about the llvm-commits
mailing list