Skip to content

Commit f963b5c

Browse files
committed
AliasAnalysis: conservatively assume @inout may alias, part 2
Use the new swift::isNotAliasingArgument utility function to check for a not-aliased arguments.
1 parent 9af439b commit f963b5c

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

lib/SILOptimizer/Analysis/AliasAnalysis.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,12 @@ static bool isFunctionArgument(SILValue V) {
112112
return Arg->isFunctionArg();
113113
}
114114

115-
/// A no alias argument is an argument that is an address type of the entry
116-
/// basic block of a function.
117-
static bool isNoAliasArgument(SILValue V) {
118-
return isFunctionArgument(V) && V.getType().isAddress();
119-
}
120-
121115
/// Return true if V is an object that at compile time can be uniquely
122116
/// identified.
123117
static bool isIdentifiableObject(SILValue V) {
124118
if (isa<AllocationInst>(V) || isa<LiteralInst>(V))
125119
return true;
126-
if (isNoAliasArgument(V))
120+
if (isNotAliasingArgument(V))
127121
return true;
128122
return false;
129123
}
@@ -173,7 +167,8 @@ static bool isLocalLiteral(SILValue V) {
173167
/// Is this a value that can be unambiguously identified as being defined at the
174168
/// function level.
175169
static bool isIdentifiedFunctionLocal(SILValue V) {
176-
return isa<AllocationInst>(*V) || isNoAliasArgument(V) || isLocalLiteral(V);
170+
return isa<AllocationInst>(*V) || isNotAliasingArgument(V) ||
171+
isLocalLiteral(V);
177172
}
178173

179174
/// Returns true if we can prove that the two input SILValues which do not equal

test/SILOptimizer/basic-aa.sil

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Swift
1616
// CHECK-NEXT: %0 = argument of bb0
1717
// CHECK-NEXT: %1 = argument of bb0
1818
// CHECK-NEXT: NoAlias
19-
sil @address_args_dont_alias_in_first_bb : $@convention(thin) (@inout Builtin.NativeObject, @inout Builtin.NativeObject) -> () {
19+
sil @address_args_dont_alias_in_first_bb : $@convention(thin) (@in Builtin.NativeObject, @in Builtin.NativeObject) -> () {
2020
bb0(%0 : $*Builtin.NativeObject, %1 : $*Builtin.NativeObject):
2121
%2 = tuple()
2222
return %2 : $()
@@ -37,6 +37,19 @@ bb1(%1 : $*Builtin.NativeObject, %2 : $*Builtin.NativeObject):
3737
return %3 : $()
3838
}
3939

40+
// Assume that inout arguments alias to preserve memory safety.
41+
//
42+
// CHECK-LABEL: @inout_args_may_alias
43+
// CHECK: PAIR #1.
44+
// CHECK-NEXT: %0 = argument of bb0
45+
// CHECK-NEXT: %1 = argument of bb0
46+
// CHECK-NEXT: MayAlias
47+
sil @inout_args_may_alias: $@convention(thin) (@inout Builtin.NativeObject, @inout Builtin.NativeObject) -> () {
48+
bb0(%0 : $*Builtin.NativeObject, %1 : $*Builtin.NativeObject):
49+
%2 = tuple()
50+
return %2 : $()
51+
}
52+
4053
struct StructLvl2 {
4154
var tup : (Builtin.Int64, Builtin.Int32)
4255
}
@@ -200,7 +213,7 @@ sil @different_alloc_stack_dont_alias : $@convention(thin) () -> () {
200213
// CHECK-NEXT: (0): %2 = argument of bb0 : $*Builtin.NativeObject
201214
// CHECK-NEXT: (1): %3 = alloc_stack $Builtin.NativeObject
202215
// CHECK-NEXT: NoAlias
203-
sil @args_dont_alias_with_identified_function_locals : $@convention(thin) (Builtin.NativeObject, Builtin.NativeObject, @inout Builtin.NativeObject) -> () {
216+
sil @args_dont_alias_with_identified_function_locals : $@convention(thin) (Builtin.NativeObject, Builtin.NativeObject, @in Builtin.NativeObject) -> () {
204217
bb0(%0 : $Builtin.NativeObject, %1 : $Builtin.NativeObject, %2 : $*Builtin.NativeObject):
205218
%3 = alloc_stack $Builtin.NativeObject
206219
dealloc_stack %3#0 : $*@local_storage Builtin.NativeObject

test/SILOptimizer/mem-behavior.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bb0(%0 : $Int32, %1 : $*Int32, %2 : $*Int32):
5858
// CHECK-NEXT: (0): %4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()
5959
// CHECK-NEXT: (0): %2 = argument of bb0 : $*Int32
6060
// CHECK-NEXT: r=0,w=0,se=0
61-
sil @call_store_to_int_not_aliased : $@convention(thin) (Int32, @inout Int32, @inout Int32) -> () {
61+
sil @call_store_to_int_not_aliased : $@convention(thin) (Int32, @inout Int32, @in Int32) -> () {
6262
bb0(%0 : $Int32, %1 : $*Int32, %2 : $*Int32):
6363
%3 = function_ref @store_to_int : $@convention(thin) (Int32, @inout Int32) -> ()
6464
%4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()

0 commit comments

Comments
 (0)