Skip to content

SIL: fix memory behavior of bind_memory and rebind_memory #67330

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
Jul 18, 2023
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
6 changes: 3 additions & 3 deletions include/swift/SIL/SILNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,12 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)

// BindMemory and RebindMemory have no physical side effect. Semantically they
// write to their affected memory region because any reads or writes accessing
// access their affected memory region because any reads or writes accessing
// that memory must be dependent on the bind operation.
SINGLE_VALUE_INST(BindMemoryInst, bind_memory,
SILInstruction, MayWrite, DoesNotRelease)
SILInstruction, MayReadWrite, DoesNotRelease)
SINGLE_VALUE_INST(RebindMemoryInst, rebind_memory,
SILInstruction, MayWrite, DoesNotRelease)
SILInstruction, MayReadWrite, DoesNotRelease)

SINGLE_VALUE_INST_RANGE(SingleValueInstruction, AllocStackInst, RebindMemoryInst)
NODE_RANGE(ValueBase, SILPhiArgument, RebindMemoryInst)
Expand Down
18 changes: 18 additions & 0 deletions test/SILOptimizer/dead_store_elim.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1613,3 +1613,21 @@ bb0(%0 : $Int, %1 : @owned $IntAndFoo, %2 : $*IntAndFoo):
%r = tuple ()
return %r : $()
}

// CHECK-LABEL: sil @test_bind_memory :
// CHECK: store %0
// CHECK: end sil function 'test_bind_memory'
sil @test_bind_memory : $@convention(thin) (UInt64, Builtin.Word) -> Builtin.Int8 {
bb0(%0 : $UInt64, %1 : $Builtin.Word):
%35 = alloc_stack $(UInt64, UInt64)
%36 = tuple_element_addr %35 : $*(UInt64, UInt64), 0
store %0 to %36 : $*UInt64
%50 = address_to_pointer %35 : $*(UInt64, UInt64) to $Builtin.RawPointer
%52 = bind_memory %50 : $Builtin.RawPointer, %1 : $Builtin.Word to $*UInt8
%72 = pointer_to_address %50 : $Builtin.RawPointer to [strict] $*UInt8
%75 = struct_element_addr %72 : $*UInt8, #UInt8._value
%76 = load %75 : $*Builtin.Int8
dealloc_stack %35 : $*(UInt64, UInt64)
return %76 : $Builtin.Int8
}