Skip to content

[gardening] Replace else-if with early returns and sink computation o… #12583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4031,8 +4031,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
auto mappedTy = F.mapTypeIntoContext(ty);
SILArgument *bbarg = *argI;
++argI;
auto ownershipkind = ValueOwnershipKind(
M, mappedTy, fnConv.getSILArgumentConvention(bbarg->getIndex()));
if (bbarg->getType() != mappedTy) {
llvm::errs() << what << " type mismatch!\n";
llvm::errs() << " argument: "; bbarg->dump();
Expand All @@ -4045,6 +4043,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
return;
}

auto ownershipkind = ValueOwnershipKind(
M, mappedTy, fnConv.getSILArgumentConvention(bbarg->getIndex()));

if (bbarg->getOwnershipKind() != ownershipkind) {
llvm::errs() << what << " ownership kind mismatch!\n";
llvm::errs() << " argument: " << bbarg->getOwnershipKind() << '\n';
Expand Down
20 changes: 13 additions & 7 deletions lib/SILOptimizer/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2887,7 +2887,9 @@ swift::analyzeStaticInitializer(SILValue V,
return false;
}
return true;
} else if (auto *TI = dyn_cast<TupleInst>(V)) {
}

if (auto *TI = dyn_cast<TupleInst>(V)) {
// If it is not a tuple which is a simple type, bail.
if (!isSimpleType(TI->getType(), TI->getModule()))
return false;
Expand All @@ -2898,7 +2900,9 @@ swift::analyzeStaticInitializer(SILValue V,
return false;
}
return true;
} else if (auto *bi = dyn_cast<BuiltinInst>(V)) {
}

if (auto *bi = dyn_cast<BuiltinInst>(V)) {
switch (bi->getBuiltinInfo().ID) {
case BuiltinValueKind::FPTrunc:
if (auto *LI = dyn_cast<LiteralInst>(bi->getArguments()[0])) {
Expand All @@ -2908,13 +2912,15 @@ swift::analyzeStaticInitializer(SILValue V,
default:
return false;
}
} else if (isa<IntegerLiteralInst>(V)
|| isa<FloatLiteralInst>(V)
|| isa<StringLiteralInst>(V)) {
}

if (isa<IntegerLiteralInst>(V)
|| isa<FloatLiteralInst>(V)
|| isa<StringLiteralInst>(V)) {
return true;
} else {
return false;
}

return false;
}

/// Replace load sequence which may contain
Expand Down