Skip to content

Fix use of MemAcessUtils in LICM #38784

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
merged 1 commit into from
Aug 7, 2021
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
3 changes: 2 additions & 1 deletion lib/SIL/Utils/MemAccessUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,8 @@ LLVM_ATTRIBUTE_USED void AccessPath::dump() const { print(llvm::dbgs()); }
void AccessPathWithBase::print(raw_ostream &os) const {
if (base)
os << "Base: " << base;

else
os << "Base: unidentified\n";
accessPath.print(os);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/SILOptimizer/LoopTransforms/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@ void LoopTreeOptimization::analyzeCurrentLoop(
// how to rematerialize global_addr, then we don't need this base.
auto access = AccessPathWithBase::compute(SI->getDest());
auto accessPath = access.accessPath;
if (accessPath.isValid() && isLoopInvariant(access.base, Loop)) {
if (accessPath.isValid() &&
(access.base && isLoopInvariant(access.base, Loop))) {
if (isOnlyLoadedAndStored(AA, sideEffects, Loads, Stores, SI->getDest(),
accessPath)) {
if (!LoadAndStoreAddrs.count(accessPath)) {
Expand Down
79 changes: 79 additions & 0 deletions test/SILOptimizer/licm.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1318,3 +1318,82 @@ bb3:
%outer = tuple (%extract0 : $Int64, %inner: $(Int64, Int64))
return %outer : $(Int64, (Int64, Int64))
}

class C {}

// This won't be hoisted because we can't find a base to check if it is invariant
// CHECK-LABEL: sil @testLoopInvariantStoreNoBase1 :
// CHECK: bb6:
// CHECK-NOT: store
// CHECK-LABEL: } // end sil function 'testLoopInvariantStoreNoBase1'
sil @testLoopInvariantStoreNoBase1 : $@convention(thin) (Builtin.BridgeObject, Double) -> () {
bb0(%0 : $Builtin.BridgeObject, %1 : $Double):
cond_br undef, bb1, bb2

bb1:
%2 = unchecked_ref_cast %0 : $Builtin.BridgeObject to $C
%3 = ref_tail_addr [immutable] %2 : $C, $Double
%4 = address_to_pointer %3 : $*Double to $Builtin.RawPointer
br bb3(%4 : $Builtin.RawPointer)

bb2:
%6 = unchecked_ref_cast %0 : $Builtin.BridgeObject to $C
%7 = ref_tail_addr [immutable] %6 : $C, $Double
%8 = address_to_pointer %7 : $*Double to $Builtin.RawPointer
br bb3(%8 : $Builtin.RawPointer)

bb3(%9 : $Builtin.RawPointer):
br bb4

bb4:
%11 = pointer_to_address %9 : $Builtin.RawPointer to [strict] $*Double
store %1 to %11 : $*Double
cond_br undef, bb5, bb6

bb5:
br bb4

bb6:
%15 = tuple ()
return %15 : $()
}

// This won't be hoisted because we can't find a base to check if it is invariant
// CHECK-LABEL: sil @testLoopInvariantStoreNoBase2 :
// CHECK: bb6:
// CHECK-NOT: store
// CHECK-LABEL: } // end sil function 'testLoopInvariantStoreNoBase2'
sil @testLoopInvariantStoreNoBase2 : $@convention(thin) (Builtin.BridgeObject, Double) -> () {
bb0(%0 : $Builtin.BridgeObject, %1 : $Double):
cond_br undef, bb1, bb2

bb1:
%2 = unchecked_ref_cast %0 : $Builtin.BridgeObject to $C
%3 = ref_tail_addr [immutable] %2 : $C, $Double
%4 = address_to_pointer %3 : $*Double to $Builtin.RawPointer
br bb3(%4 : $Builtin.RawPointer)

bb2:
%6 = unchecked_ref_cast %0 : $Builtin.BridgeObject to $C
%7 = ref_tail_addr [immutable] %6 : $C, $Double
%8 = address_to_pointer %7 : $*Double to $Builtin.RawPointer
br bb3(%8 : $Builtin.RawPointer)

bb3(%9 : $Builtin.RawPointer):
br bb4

bb4:
%11 = pointer_to_address %9 : $Builtin.RawPointer to [strict] $*Double
%12 = integer_literal $Builtin.Word, 1
%13 = index_addr %11 : $*Double, %12 : $Builtin.Word
store %1 to %13 : $*Double
cond_br undef, bb5, bb6

bb5:
br bb4

bb6:
%15 = tuple ()
return %15 : $()
}