Re-submit: Enable cast optimizations as a guaranteed optimization.

Fix a few places in diagnose unreachable, which were emitting false diagnostics after enabling this optimization.

This commit does not disable and remove the special-casing for bridging conversions in the CSApply yet. Let's wait a bit and see that everything works properly after my recent cast optimizations changes. If everything is OK, we can remove the code from CSApply.

This time it does not break the Alamofire external project (rdar://20579035).

rdar://20467603

Swift SVN r27513
This commit is contained in:
Roman Levenstein
2015-04-21 00:54:43 +00:00
parent 750566b249
commit 77580edea5
3 changed files with 65 additions and 12 deletions

View File

@@ -791,10 +791,20 @@ static bool CCPFunctionBody(SILFunction &F, bool EnableDiagnostics,
WorkList.insert(&I);
else if (isApplyOfStringConcat(I))
WorkList.insert(&I);
else if (isa<CheckedCastBranchInst>(&I) || isa<CheckedCastAddrBranchInst>(&I) ||
isa<UnconditionalCheckedCastInst>(&I) ||
isa<UnconditionalCheckedCastAddrInst>(&I))
WorkList.insert(&I);
}
}
llvm::SetVector<SILInstruction *> FoldedUsers;
CastOptimizer CastOpt(/* ReplaceInstUsesAction */
[&](SILInstruction *I, ValueBase * V) {
SILValue(I).replaceAllUsesWith(V);
},
/* EraseAction */
[&](SILInstruction *I) { WorkList.remove(I); I->eraseFromParent(); });
while (!WorkList.empty()) {
SILInstruction *I = WorkList.pop_back_val();
@@ -834,6 +844,38 @@ static bool CCPFunctionBody(SILFunction &F, bool EnableDiagnostics,
continue;
}
if (isa<CheckedCastBranchInst>(I) || isa<CheckedCastAddrBranchInst>(I) ||
isa<UnconditionalCheckedCastInst>(I) ||
isa<UnconditionalCheckedCastAddrInst>(I)) {
// Try to perform cast optimizations.
SILInstruction *Result = nullptr;
switch(I->getKind()) {
default:
llvm_unreachable("Unexpected instruction for cast optimizations");
case ValueKind::CheckedCastBranchInst:
Result = CastOpt.simplifyCheckedCastBranchInst(cast<CheckedCastBranchInst>(I));
break;
case ValueKind::CheckedCastAddrBranchInst:
Result = CastOpt.simplifyCheckedCastAddrBranchInst(cast<CheckedCastAddrBranchInst>(I));
break;
case ValueKind::UnconditionalCheckedCastInst:
Result = CastOpt.optimizeUnconditionalCheckedCastInst(cast<UnconditionalCheckedCastInst>(I));
break;
case ValueKind::UnconditionalCheckedCastAddrInst:
Result = CastOpt.optimizeUnconditionalCheckedCastAddrInst(cast<UnconditionalCheckedCastAddrInst>(I));
break;
}
if (Result) {
if (isa<CheckedCastBranchInst>(Result) || isa<CheckedCastAddrBranchInst>(Result) ||
isa<UnconditionalCheckedCastInst>(Result) ||
isa<UnconditionalCheckedCastAddrInst>(Result))
WorkList.insert(Result);
}
continue;
}
// Go through all users of the constant and try to fold them.
FoldedUsers.clear();
for (auto Use : I->getUses()) {