Skip to content

Commit d351623

Browse files
committed
Fix StringOptimization to handle load_borrow
rdar://140229560
1 parent 252a57a commit d351623

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/SILOptimizer/Transforms/StringOptimization.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ isStringStoreToIdentifyableObject(SILInstruction *inst) {
441441
case SILInstructionKind::DeallocStackInst:
442442
case SILInstructionKind::LoadInst:
443443
break;
444+
case SILInstructionKind::LoadBorrowInst:
445+
break;
444446
case SILInstructionKind::DebugValueInst:
445447
if (DebugValueInst::hasAddrVal(user))
446448
break;
@@ -579,12 +581,13 @@ StringOptimization::getStringFromStaticLet(SILValue value) {
579581
// %ptr_to_global = apply %addressor()
580582
// %global_addr = pointer_to_address %ptr_to_global
581583
// %value = load %global_addr
582-
auto *load = dyn_cast<LoadInst>(value);
583-
if (!load)
584-
return StringInfo::unknown();
584+
if (!isa<LoadInst>(value) && !isa<LoadBorrowInst>(value)) {
585+
return StringInfo::unknown();
586+
}
587+
auto *load = value->getDefiningInstruction();
585588

586589
SILFunction *initializer = nullptr;
587-
auto *globalAddr = dyn_cast<GlobalAddrInst>(load->getOperand());
590+
auto *globalAddr = dyn_cast<GlobalAddrInst>(load->getOperand(0));
588591
if (globalAddr) {
589592
// The global accessor is inlined.
590593

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

603-
auto *pta = dyn_cast<PointerToAddressInst>(load->getOperand());
606+
auto *pta = dyn_cast<PointerToAddressInst>(load->getOperand(0));
604607
if (!pta)
605608
return StringInfo::unknown();
606609

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

657660
return getStringInfo(initVal);

test/SILOptimizer/string_optimization.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-build-swift -O %s -module-name=test -Xfrontend -sil-verify-all -emit-sil | %FileCheck %s
2+
// RUN: %target-build-swift -O %s -module-name=test -Xfrontend -sil-verify-all -emit-sil -Xfrontend -enable-ossa-modules | %FileCheck %s
23

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

0 commit comments

Comments
 (0)