Skip to content

Commit 0dbd5c6

Browse files
committed
MemBehavior: correctly handle debug_value
debug_value just "reads" the operand if it is an address.
1 parent df7b677 commit 0dbd5c6

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/TestPasses/MemBehaviorDumper.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ private extension Instruction {
7171
is LoadInst,
7272
is StoreInst,
7373
is CopyAddrInst,
74-
is BuiltinInst:
74+
is BuiltinInst,
75+
is DebugValueInst:
7576
return true
7677
default:
7778
return false

lib/SILOptimizer/Analysis/MemoryBehavior.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class MemoryBehaviorVisitor
176176
MemBehavior visitDestroyValueInst(DestroyValueInst *DVI);
177177
MemBehavior visitSetDeallocatingInst(SetDeallocatingInst *BI);
178178
MemBehavior visitBeginCOWMutationInst(BeginCOWMutationInst *BCMI);
179+
MemBehavior visitDebugValueInst(DebugValueInst *dv);
179180
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
180181
MemBehavior visit##Name##ReleaseInst(Name##ReleaseInst *BI);
181182
#include "swift/AST/ReferenceStorage.def"
@@ -374,6 +375,15 @@ visitBeginCOWMutationInst(BeginCOWMutationInst *BCMI) {
374375
return MemBehavior::None;
375376
}
376377

378+
MemBehavior MemoryBehaviorVisitor::
379+
visitDebugValueInst(DebugValueInst *dv) {
380+
SILValue op = dv->getOperand();
381+
if (op->getType().isAddress() && mayAlias(op)) {
382+
return MemBehavior::MayRead;
383+
}
384+
return MemBehavior::None;
385+
}
386+
377387
//===----------------------------------------------------------------------===//
378388
// Top Level Entrypoint
379389
//===----------------------------------------------------------------------===//

test/SILOptimizer/mem-behavior.sil

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,3 +1002,25 @@ bb0(%0 : $Builtin.RawPointer):
10021002
%6 = tuple ()
10031003
return %6 : $()
10041004
}
1005+
1006+
1007+
// CHECK-LABEL: @test_debug_value
1008+
// CHECK: PAIR #0.
1009+
// CHECK-NEXT: debug_value %0 : $*Int, let, name "x"
1010+
// CHECK-NEXT: %0 = alloc_stack $Int
1011+
// CHECK-NEXT: r=1,w=0
1012+
// CHECK: PAIR #1.
1013+
// CHECK-NEXT: debug_value %0 : $*Int, let, name "x"
1014+
// CHECK-NEXT: %1 = alloc_stack $Int
1015+
// CHECK-NEXT: r=0,w=0
1016+
sil @test_debug_value : $@convention(thin) () -> () {
1017+
bb0:
1018+
%0 = alloc_stack $Int
1019+
%1 = alloc_stack $Int
1020+
debug_value %0 : $*Int, let, name "x"
1021+
dealloc_stack %1 : $*Int
1022+
dealloc_stack %0 : $*Int
1023+
%r = tuple ()
1024+
return %r : $()
1025+
}
1026+

0 commit comments

Comments
 (0)