Skip to content

Commit a9dc5fe

Browse files
author
git apple-llvm automerger
committed
Merge commit '08efc2e68d5f' from llvm.org/main into next
2 parents 7c20f2d + 08efc2e commit a9dc5fe

File tree

1 file changed

+0
-131
lines changed

1 file changed

+0
-131
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class SimplifyCFGOpt {
234234
bool FoldValueComparisonIntoPredecessors(Instruction *TI,
235235
IRBuilder<> &Builder);
236236

237-
bool simplifyReturn(ReturnInst *RI, IRBuilder<> &Builder);
238237
bool simplifyResume(ResumeInst *RI, IRBuilder<> &Builder);
239238
bool simplifySingleResume(ResumeInst *RI);
240239
bool simplifyCommonResume(ResumeInst *RI);
@@ -245,7 +244,6 @@ class SimplifyCFGOpt {
245244
bool simplifyBranch(BranchInst *Branch, IRBuilder<> &Builder);
246245
bool simplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder);
247246
bool simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder);
248-
bool SimplifyCondBranchToTwoReturns(BranchInst *BI, IRBuilder<> &Builder);
249247

250248
bool tryToSimplifyUncondBranchWithICmpInIt(ICmpInst *ICI,
251249
IRBuilder<> &Builder);
@@ -2903,103 +2901,6 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
29032901
return true;
29042902
}
29052903

2906-
/// If we found a conditional branch that goes to two returning blocks,
2907-
/// try to merge them together into one return,
2908-
/// introducing a select if the return values disagree.
2909-
bool SimplifyCFGOpt::SimplifyCondBranchToTwoReturns(BranchInst *BI,
2910-
IRBuilder<> &Builder) {
2911-
auto *BB = BI->getParent();
2912-
assert(BI->isConditional() && "Must be a conditional branch");
2913-
BasicBlock *TrueSucc = BI->getSuccessor(0);
2914-
BasicBlock *FalseSucc = BI->getSuccessor(1);
2915-
if (TrueSucc == FalseSucc)
2916-
return false;
2917-
ReturnInst *TrueRet = cast<ReturnInst>(TrueSucc->getTerminator());
2918-
ReturnInst *FalseRet = cast<ReturnInst>(FalseSucc->getTerminator());
2919-
2920-
// Check to ensure both blocks are empty (just a return) or optionally empty
2921-
// with PHI nodes. If there are other instructions, merging would cause extra
2922-
// computation on one path or the other.
2923-
if (!TrueSucc->getFirstNonPHIOrDbg()->isTerminator())
2924-
return false;
2925-
if (!FalseSucc->getFirstNonPHIOrDbg()->isTerminator())
2926-
return false;
2927-
2928-
Builder.SetInsertPoint(BI);
2929-
// Okay, we found a branch that is going to two return nodes. If
2930-
// there is no return value for this function, just change the
2931-
// branch into a return.
2932-
if (FalseRet->getNumOperands() == 0) {
2933-
TrueSucc->removePredecessor(BB);
2934-
FalseSucc->removePredecessor(BB);
2935-
Builder.CreateRetVoid();
2936-
EraseTerminatorAndDCECond(BI);
2937-
if (DTU)
2938-
DTU->applyUpdates({{DominatorTree::Delete, BB, TrueSucc},
2939-
{DominatorTree::Delete, BB, FalseSucc}});
2940-
return true;
2941-
}
2942-
2943-
// Otherwise, figure out what the true and false return values are
2944-
// so we can insert a new select instruction.
2945-
Value *TrueValue = TrueRet->getReturnValue();
2946-
Value *FalseValue = FalseRet->getReturnValue();
2947-
2948-
// Unwrap any PHI nodes in the return blocks.
2949-
if (PHINode *TVPN = dyn_cast_or_null<PHINode>(TrueValue))
2950-
if (TVPN->getParent() == TrueSucc)
2951-
TrueValue = TVPN->getIncomingValueForBlock(BB);
2952-
if (PHINode *FVPN = dyn_cast_or_null<PHINode>(FalseValue))
2953-
if (FVPN->getParent() == FalseSucc)
2954-
FalseValue = FVPN->getIncomingValueForBlock(BB);
2955-
2956-
// In order for this transformation to be safe, we must be able to
2957-
// unconditionally execute both operands to the return. This is
2958-
// normally the case, but we could have a potentially-trapping
2959-
// constant expression that prevents this transformation from being
2960-
// safe.
2961-
if (ConstantExpr *TCV = dyn_cast_or_null<ConstantExpr>(TrueValue))
2962-
if (TCV->canTrap())
2963-
return false;
2964-
if (ConstantExpr *FCV = dyn_cast_or_null<ConstantExpr>(FalseValue))
2965-
if (FCV->canTrap())
2966-
return false;
2967-
2968-
// Okay, we collected all the mapped values and checked them for sanity, and
2969-
// defined to really do this transformation. First, update the CFG.
2970-
TrueSucc->removePredecessor(BB);
2971-
FalseSucc->removePredecessor(BB);
2972-
2973-
// Insert select instructions where needed.
2974-
Value *BrCond = BI->getCondition();
2975-
if (TrueValue) {
2976-
// Insert a select if the results differ.
2977-
if (TrueValue == FalseValue || isa<UndefValue>(FalseValue)) {
2978-
} else if (isa<UndefValue>(TrueValue)) {
2979-
TrueValue = FalseValue;
2980-
} else {
2981-
TrueValue =
2982-
Builder.CreateSelect(BrCond, TrueValue, FalseValue, "retval", BI);
2983-
}
2984-
}
2985-
2986-
Value *RI =
2987-
!TrueValue ? Builder.CreateRetVoid() : Builder.CreateRet(TrueValue);
2988-
2989-
(void)RI;
2990-
2991-
LLVM_DEBUG(dbgs() << "\nCHANGING BRANCH TO TWO RETURNS INTO SELECT:"
2992-
<< "\n " << *BI << "\nNewRet = " << *RI << "\nTRUEBLOCK: "
2993-
<< *TrueSucc << "\nFALSEBLOCK: " << *FalseSucc);
2994-
2995-
EraseTerminatorAndDCECond(BI);
2996-
if (DTU)
2997-
DTU->applyUpdates({{DominatorTree::Delete, BB, TrueSucc},
2998-
{DominatorTree::Delete, BB, FalseSucc}});
2999-
3000-
return true;
3001-
}
3002-
30032904
static Value *createLogicalOp(IRBuilderBase &Builder,
30042905
Instruction::BinaryOps Opc, Value *LHS,
30052906
Value *RHS, const Twine &Name = "") {
@@ -4628,35 +4529,6 @@ bool SimplifyCFGOpt::simplifyCleanupReturn(CleanupReturnInst *RI) {
46284529
return false;
46294530
}
46304531

4631-
bool SimplifyCFGOpt::simplifyReturn(ReturnInst *RI, IRBuilder<> &Builder) {
4632-
BasicBlock *BB = RI->getParent();
4633-
if (!BB->getFirstNonPHIOrDbg()->isTerminator())
4634-
return false;
4635-
4636-
// Find predecessors that end with branches.
4637-
SmallVector<BranchInst *, 8> CondBranchPreds;
4638-
for (BasicBlock *P : predecessors(BB)) {
4639-
Instruction *PTI = P->getTerminator();
4640-
if (BranchInst *BI = dyn_cast<BranchInst>(PTI))
4641-
if (BI->isConditional())
4642-
CondBranchPreds.push_back(BI);
4643-
}
4644-
4645-
// Check out all of the conditional branches going to this return
4646-
// instruction. If any of them just select between returns, change the
4647-
// branch itself into a select/return pair.
4648-
while (!CondBranchPreds.empty()) {
4649-
BranchInst *BI = CondBranchPreds.pop_back_val();
4650-
4651-
// Check to see if the non-BB successor is also a return block.
4652-
if (isa<ReturnInst>(BI->getSuccessor(0)->getTerminator()) &&
4653-
isa<ReturnInst>(BI->getSuccessor(1)->getTerminator()) &&
4654-
SimplifyCondBranchToTwoReturns(BI, Builder))
4655-
return true;
4656-
}
4657-
return false;
4658-
}
4659-
46604532
// WARNING: keep in sync with InstCombinerImpl::visitUnreachableInst()!
46614533
bool SimplifyCFGOpt::simplifyUnreachable(UnreachableInst *UI) {
46624534
BasicBlock *BB = UI->getParent();
@@ -6747,9 +6619,6 @@ bool SimplifyCFGOpt::simplifyOnceImpl(BasicBlock *BB) {
67476619
case Instruction::Br:
67486620
Changed |= simplifyBranch(cast<BranchInst>(Terminator), Builder);
67496621
break;
6750-
case Instruction::Ret:
6751-
Changed |= simplifyReturn(cast<ReturnInst>(Terminator), Builder);
6752-
break;
67536622
case Instruction::Resume:
67546623
Changed |= simplifyResume(cast<ResumeInst>(Terminator), Builder);
67556624
break;

0 commit comments

Comments
 (0)