[llvm] r251442 - [ScalarEvolutionExpander] PHI on a catchpad can be used on both edges
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 12:48:29 PDT 2015
Author: majnemer
Date: Tue Oct 27 14:48:28 2015
New Revision: 251442
URL: http://llvm.org/viewvc/llvm-project?rev=251442&view=rev
Log:
[ScalarEvolutionExpander] PHI on a catchpad can be used on both edges
A PHI on a catchpad might be used by both edges out of the catchpad,
feeding back into a loop. In this case, just use the insertion point.
Anything more clever would require new basic blocks or PHI placement.
Modified:
llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll
Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=251442&r1=251441&r2=251442&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Tue Oct 27 14:48:28 2015
@@ -87,7 +87,6 @@ Value *SCEVExpander::ReuseOrCreateCast(V
}
static BasicBlock::iterator findInsertPointAfter(Instruction *I,
- DominatorTree &DT,
BasicBlock *MustDominate) {
BasicBlock::iterator IP = ++I->getIterator();
if (auto *II = dyn_cast<InvokeInst>(I))
@@ -107,12 +106,8 @@ static BasicBlock::iterator findInsertPo
IP = CEPI->getUnwindDest()->getFirstNonPHI();
} else if (auto *CEPI = dyn_cast<CleanupEndPadInst>(IP)) {
IP = CEPI->getUnwindDest()->getFirstNonPHI();
- } else if (auto *CPI = dyn_cast<CatchPadInst>(IP)) {
- BasicBlock *NormalDest = CPI->getNormalDest();
- if (NormalDest == MustDominate || DT.dominates(NormalDest, MustDominate))
- IP = NormalDest->getFirstNonPHI();
- else
- IP = CPI->getUnwindDest()->getFirstNonPHI();
+ } else if (isa<CatchPadInst>(IP)) {
+ IP = MustDominate->getFirstInsertionPt();
} else {
llvm_unreachable("unexpected eh pad!");
}
@@ -177,8 +172,7 @@ Value *SCEVExpander::InsertNoopCastOfTo(
// Cast the instruction immediately after the instruction.
Instruction *I = cast<Instruction>(V);
- BasicBlock::iterator IP =
- findInsertPointAfter(I, SE.DT, Builder.GetInsertBlock());
+ BasicBlock::iterator IP = findInsertPointAfter(I, Builder.GetInsertBlock());
return ReuseOrCreateCast(I, Ty, Op, IP);
}
@@ -1423,8 +1417,8 @@ Value *SCEVExpander::visitAddRecExpr(con
NewOps[i] = SE.getAnyExtendExpr(S->op_begin()[i], CanonicalIV->getType());
Value *V = expand(SE.getAddRecExpr(NewOps, S->getLoop(),
S->getNoWrapFlags(SCEV::FlagNW)));
- BasicBlock::iterator NewInsertPt = findInsertPointAfter(
- cast<Instruction>(V), SE.DT, Builder.GetInsertBlock());
+ BasicBlock::iterator NewInsertPt =
+ findInsertPointAfter(cast<Instruction>(V), Builder.GetInsertBlock());
V = expandCodeFor(SE.getTruncateExpr(SE.getUnknown(V), Ty), nullptr,
&*NewInsertPt);
return V;
Modified: llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll?rev=251442&r1=251441&r2=251442&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll (original)
+++ llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll Tue Oct 27 14:48:28 2015
@@ -146,3 +146,45 @@ iter:
; CHECK: blah2:
; CHECK-NEXT: ptrtoint i8* %phi2 to i32
+
+define void @i() personality i32 (...)* @_except_handler3 {
+entry:
+ br label %throw
+
+throw: ; preds = %throw, %entry
+ %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
+ invoke void @reserve()
+ to label %throw unwind label %catchpad
+
+catchpad: ; preds = %throw
+ %phi2 = phi i8* [ %tmp96, %throw ]
+ catchpad [] to label %cp_body unwind label %catchendpad
+
+cp_body:
+ br label %loop_head
+
+catchendpad:
+ catchendpad unwind label %cleanuppad
+
+cleanuppad:
+ cleanuppad []
+ br label %loop_head
+
+loop_head:
+ br label %loop_body
+
+loop_body: ; preds = %iter, %catchpad
+ %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %loop_head ]
+ %tmp100 = icmp eq i8* %tmp99, undef
+ br i1 %tmp100, label %unwind_out, label %iter
+
+iter: ; preds = %loop_body
+ %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
+ br i1 undef, label %unwind_out, label %loop_body
+
+unwind_out: ; preds = %iter, %loop_body
+ unreachable
+}
+
+; CHECK-LABEL: define void @i(
+; CHECK: ptrtoint i8* %phi2 to i32
More information about the llvm-commits
mailing list