Skip to content

Commit 021bd4a

Browse files
authored
Merge pull request #81684 from eeckstein/fix-mark-dependence-addr
SIL: define `mark_dependence_addr` to read and write to its address operand
2 parents 8e40f0b + e0f5888 commit 021bd4a

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

SwiftCompilerSources/Sources/Optimizer/Analysis/AliasAnalysis.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,21 @@ struct AliasAnalysis {
253253
case let storeBorrow as StoreBorrowInst:
254254
return memLoc.mayAlias(with: storeBorrow.destination, self) ? .init(write: true) : .noEffects
255255

256-
case let mdi as MarkDependenceInstruction:
256+
case let mdi as MarkDependenceInst:
257257
if mdi.base.type.isAddress && memLoc.mayAlias(with: mdi.base, self) {
258258
return .init(read: true)
259259
}
260260
return .noEffects
261261

262+
case let mdai as MarkDependenceAddrInst:
263+
if memLoc.mayAlias(with: mdai.address, self) {
264+
return .init(read: true, write: true)
265+
}
266+
if mdai.base.type.isAddress && memLoc.mayAlias(with: mdai.base, self) {
267+
return .init(read: true)
268+
}
269+
return .noEffects
270+
262271
case let copy as SourceDestAddrInstruction:
263272
let mayRead = memLoc.mayAlias(with: copy.source, self)
264273
let mayWrite = memLoc.mayAlias(with: copy.destination, self)

include/swift/SIL/SILNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ NON_VALUE_INST(IncrementProfilerCounterInst, increment_profiler_counter,
907907
// MarkDependenceAddrInst has read effects for the base operand. See
908908
// getMemoryBehavior().
909909
NON_VALUE_INST(MarkDependenceAddrInst, mark_dependence_addr,
910-
SILInstruction, None, DoesNotRelease)
910+
SILInstruction, MayReadWrite, DoesNotRelease)
911911

912912
NON_VALUE_INST(EndCOWMutationAddrInst, end_cow_mutation_addr,
913913
SILInstruction, MayHaveSideEffects, DoesNotRelease)

lib/SIL/IR/SILInstruction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,8 +1097,8 @@ MemoryBehavior SILInstruction::getMemoryBehavior() const {
10971097
llvm_unreachable("Covered switch isn't covered?!");
10981098
}
10991099

1100-
if (auto mdi = MarkDependenceInstruction(this)) {
1101-
if (mdi.getBase()->getType().isAddress())
1100+
if (auto *mdi = dyn_cast<MarkDependenceInst>(this)) {
1101+
if (mdi->getBase()->getType().isAddress())
11021102
return MemoryBehavior::MayRead;
11031103
return MemoryBehavior::None;
11041104
}

lib/SILOptimizer/Mandatory/MoveOnlyUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ bool noncopyable::memInstMustReinitialize(Operand *memOper) {
253253
auto *CAI = cast<ExplicitCopyAddrInst>(memInst);
254254
return CAI->getDest() == address && !CAI->isInitializationOfDest();
255255
}
256+
case SILInstructionKind::MarkDependenceAddrInst: {
257+
return true;
258+
}
256259
case SILInstructionKind::YieldInst: {
257260
auto *yield = cast<YieldInst>(memInst);
258261
return yield->getYieldInfoForOperand(*memOper).isIndirectInOut();

test/SILOptimizer/mem-behavior.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,16 +1925,16 @@ bb0(%0 : $*C, %1 : $*C, %2 : @owned $C):
19251925
// CHECK: PAIR #1.
19261926
// CHECK-NEXT: mark_dependence_addr %1 : $*C on %2 : $C
19271927
// CHECK-NEXT: %1 = argument of bb0 : $*C
1928-
// CHECK-NEXT: r=0,w=0
1928+
// CHECK-NEXT: r=1,w=1
19291929
// CHECK: PAIR #2.
19301930
// CHECK-NEXT: mark_dependence_addr %1 : $*C on %0 : $*C
19311931
// CHECK-NEXT: %0 = argument of bb0 : $*C
19321932
// CHECK-NEXT: r=1,w=0
19331933
// CHECK: PAIR #3.
19341934
// CHECK-NEXT: mark_dependence_addr %1 : $*C on %0 : $*C
19351935
// CHECK-NEXT: %1 = argument of bb0 : $*C
1936-
// CHECK-NEXT: r=0,w=0
1937-
sil [ossa] @test_mark_dependence_addr : $@convention(thin) (@in_guaranteed C, @in_guaranteed C, @guaranteed C) -> () {
1936+
// CHECK-NEXT: r=1,w=1
1937+
sil [ossa] @test_mark_dependence_addr : $@convention(thin) (@in_guaranteed C, @inout C, @guaranteed C) -> () {
19381938
bb0(%0 : $*C, %1 : $*C, %2 : @guaranteed $C):
19391939
mark_dependence_addr %1 on %2
19401940
mark_dependence_addr %1 on %0

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5411,6 +5411,16 @@ bb1(%10 : @owned $Optional<@callee_guaranteed () -> ()>, %11 : @guaranteed $Opti
54115411
return %12 : $()
54125412
}
54135413

5414+
// CHECK-LABEL: sil [ossa] @not_dead_mark_dependence_addr :
5415+
// CHECK: mark_dependence_addr %0 : $*B on %1
5416+
// CHECK-LABEL: } // end sil function 'not_dead_mark_dependence_addr'
5417+
sil [ossa] @not_dead_mark_dependence_addr : $@convention(thin) (@inout B, @in_guaranteed B) -> @owned B {
5418+
bb0(%0 : $*B, %1 : $*B):
5419+
mark_dependence_addr %0 on %1
5420+
%3 = load [copy] %0
5421+
return %3
5422+
}
5423+
54145424
// CHECK-LABEL: sil [ossa] @remove_borrow_of_thin_function :
54155425
// CHECK: [[F:%.*]] = function_ref @unknown
54165426
// CHECK: [[T:%.*]] = thin_to_thick_function [[F]]

0 commit comments

Comments
 (0)