Skip to content
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
15 changes: 9 additions & 6 deletions lib/SILOptimizer/Transforms/StringOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ isStringStoreToIdentifyableObject(SILInstruction *inst) {
case SILInstructionKind::DeallocStackInst:
case SILInstructionKind::LoadInst:
break;
case SILInstructionKind::LoadBorrowInst:
break;
case SILInstructionKind::DebugValueInst:
if (DebugValueInst::hasAddrVal(user))
break;
Expand Down Expand Up @@ -579,12 +581,13 @@ StringOptimization::getStringFromStaticLet(SILValue value) {
// %ptr_to_global = apply %addressor()
// %global_addr = pointer_to_address %ptr_to_global
// %value = load %global_addr
auto *load = dyn_cast<LoadInst>(value);
if (!load)
return StringInfo::unknown();
if (!isa<LoadInst>(value) && !isa<LoadBorrowInst>(value)) {
return StringInfo::unknown();
}
auto *load = value->getDefiningInstruction();

SILFunction *initializer = nullptr;
auto *globalAddr = dyn_cast<GlobalAddrInst>(load->getOperand());
auto *globalAddr = dyn_cast<GlobalAddrInst>(load->getOperand(0));
if (globalAddr) {
// The global accessor is inlined.

Expand All @@ -600,7 +603,7 @@ StringOptimization::getStringFromStaticLet(SILValue value) {
} else {
// The global accessor is not inlined, yet.

auto *pta = dyn_cast<PointerToAddressInst>(load->getOperand());
auto *pta = dyn_cast<PointerToAddressInst>(load->getOperand(0));
if (!pta)
return StringInfo::unknown();

Expand Down Expand Up @@ -651,7 +654,7 @@ StringOptimization::getStringFromStaticLet(SILValue value) {
// This check is probably not needed, but let's be on the safe side:
// it prevents an infinite recursion if the initializer of the global is
// itself a load of another global, and so on.
if (isa<LoadInst>(initVal))
if (isa<LoadInst>(initVal) || isa<LoadBorrowInst>(initVal))
return StringInfo::unknown();

return getStringInfo(initVal);
Expand Down
1 change: 1 addition & 0 deletions test/SILOptimizer/string_optimization.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-build-swift -O %s -module-name=test -Xfrontend -sil-verify-all -emit-sil | %FileCheck %s
// RUN: %target-build-swift -O %s -module-name=test -Xfrontend -sil-verify-all -emit-sil -Xfrontend -enable-ossa-modules | %FileCheck %s

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O -module-name=test %s -o %t/a.out
Expand Down