1
- // RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation 2>&1 %s | %FileCheck %s
1
+ // RUN: %target-swift-emit-sil -verify - Xllvm -debug-only=differentiation 2>&1 %s | %FileCheck %s
2
2
3
3
// Check that `@noDerivative` struct projections have "NONE" activity.
4
4
@@ -72,9 +72,9 @@ func testArrayUninitializedIntrinsic(_ x: Float, _ y: Float) -> [Float] {
72
72
// CHECK: [ACTIVE] %6 = apply %5<Float>(%4) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
73
73
// CHECK: [ACTIVE] (**%7**, %8) = destructure_tuple %6 : $(Array<Float>, Builtin.RawPointer)
74
74
// CHECK: [VARIED] (%7, **%8**) = destructure_tuple %6 : $(Array<Float>, Builtin.RawPointer)
75
- // CHECK: [VARIED ] %9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*Float
75
+ // CHECK: [ACTIVE ] %9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*Float
76
76
// CHECK: [VARIED] %11 = integer_literal $Builtin.Word, 1
77
- // CHECK: [VARIED ] %12 = index_addr %9 : $*Float, %11 : $Builtin.Word
77
+ // CHECK: [ACTIVE ] %12 = index_addr %9 : $*Float, %11 : $Builtin.Word
78
78
79
79
@differentiable ( where T: Differentiable)
80
80
func testArrayUninitializedIntrinsicGeneric< T> ( _ x: T , _ y: T ) -> [ T ] {
@@ -89,9 +89,9 @@ func testArrayUninitializedIntrinsicGeneric<T>(_ x: T, _ y: T) -> [T] {
89
89
// CHECK: [ACTIVE] %6 = apply %5<T>(%4) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
90
90
// CHECK: [ACTIVE] (**%7**, %8) = destructure_tuple %6 : $(Array<T>, Builtin.RawPointer)
91
91
// CHECK: [VARIED] (%7, **%8**) = destructure_tuple %6 : $(Array<T>, Builtin.RawPointer)
92
- // CHECK: [VARIED ] %9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*T
92
+ // CHECK: [ACTIVE ] %9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*T
93
93
// CHECK: [VARIED] %11 = integer_literal $Builtin.Word, 1
94
- // CHECK: [VARIED ] %12 = index_addr %9 : $*T, %11 : $Builtin.Word
94
+ // CHECK: [ACTIVE ] %12 = index_addr %9 : $*T, %11 : $Builtin.Word
95
95
96
96
// TF-952: Test array literal initialized from an address (e.g. `var`).
97
97
@differentiable
@@ -114,10 +114,10 @@ func testArrayUninitializedIntrinsicAddress(_ x: Float, _ y: Float) -> [Float] {
114
114
// CHECK: [ACTIVE] %17 = apply %16<Float>(%15) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
115
115
// CHECK: [ACTIVE] (**%18**, %19) = destructure_tuple %17 : $(Array<Float>, Builtin.RawPointer)
116
116
// CHECK: [VARIED] (%18, **%19**) = destructure_tuple %17 : $(Array<Float>, Builtin.RawPointer)
117
- // CHECK: [VARIED ] %20 = pointer_to_address %19 : $Builtin.RawPointer to [strict] $*Float
117
+ // CHECK: [ACTIVE ] %20 = pointer_to_address %19 : $Builtin.RawPointer to [strict] $*Float
118
118
// CHECK: [ACTIVE] %21 = begin_access [read] [static] %4 : $*Float
119
119
// CHECK: [VARIED] %24 = integer_literal $Builtin.Word, 1
120
- // CHECK: [VARIED ] %25 = index_addr %20 : $*Float, %24 : $Builtin.Word
120
+ // CHECK: [ACTIVE ] %25 = index_addr %20 : $*Float, %24 : $Builtin.Word
121
121
// CHECK: [ACTIVE] %26 = begin_access [read] [static] %4 : $*Float
122
122
123
123
// TF-952: Test array literal initialized with function call results.
@@ -133,11 +133,11 @@ func testArrayUninitializedIntrinsicFunctionResult(_ x: Float, _ y: Float) -> [F
133
133
// [ACTIVE] %6 = apply %5<Float>(%4) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
134
134
// [ACTIVE] (**%7**, %8) = destructure_tuple %6 : $(Array<Float>, Builtin.RawPointer)
135
135
// [VARIED] (%7, **%8**) = destructure_tuple %6 : $(Array<Float>, Builtin.RawPointer)
136
- // [VARIED ] %9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*Float
136
+ // [ACTIVE ] %9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*Float
137
137
// [NONE] // function_ref static Float.* infix(_:_:)
138
138
// [ACTIVE] %12 = apply %11(%0, %1, %10) : $@convention(method) (Float, Float, @thin Float.Type) -> Float
139
139
// [VARIED] %14 = integer_literal $Builtin.Word, 1
140
- // [VARIED ] %15 = index_addr %9 : $*Float, %14 : $Builtin.Word
140
+ // [ACTIVE ] %15 = index_addr %9 : $*Float, %14 : $Builtin.Word
141
141
// [USEFUL] %16 = metatype $@thin Float.Type
142
142
// [NONE] // function_ref static Float.* infix(_:_:)
143
143
// [ACTIVE] %18 = apply %17(%0, %1, %16) : $@convention(method) (Float, Float, @thin Float.Type) -> Float
@@ -203,3 +203,50 @@ func TF_954(_ x: Float) -> Float {
203
203
// CHECK: bb5:
204
204
// CHECK: [ACTIVE] %40 = begin_access [read] [static] %2 : $*Float
205
205
// CHECK: [ACTIVE] %41 = load [trivial] %40 : $*Float
206
+
207
+ //===----------------------------------------------------------------------===//
208
+ // Non-differentiable functions
209
+ //===----------------------------------------------------------------------===//
210
+
211
+ // Check `inout` arguments.
212
+
213
+ // expected-error @+1 {{function is not differentiable}}
214
+ @differentiable
215
+ // expected-note @+1 {{when differentiating this function definition}}
216
+ func activeInoutArg( _ x: Float ) -> Float {
217
+ var result = x
218
+ // expected-note @+1 {{cannot differentiate through 'inout' arguments}}
219
+ result += x
220
+ return result
221
+ }
222
+
223
+ // CHECK-LABEL: [AD] Activity info for ${{.*}}activeInoutArg{{.*}} at (source=0 parameters=(0))
224
+ // CHECK: [ACTIVE] %0 = argument of bb0 : $Float
225
+ // CHECK: [ACTIVE] %2 = alloc_stack $Float, var, name "result"
226
+ // CHECK: [ACTIVE] %5 = begin_access [modify] [static] %2 : $*Float
227
+ // CHECK: [NONE] // function_ref static Float.+= infix(_:_:)
228
+ // CHECK: [NONE] %7 = apply %6(%5, %0, %4) : $@convention(method) (@inout Float, Float, @thin Float.Type) -> ()
229
+ // CHECK: [ACTIVE] %9 = begin_access [read] [static] %2 : $*Float
230
+ // CHECK: [ACTIVE] %10 = load [trivial] %9 : $*Float
231
+
232
+ // expected-error @+1 {{function is not differentiable}}
233
+ @differentiable
234
+ // expected-note @+1 {{when differentiating this function definition}}
235
+ func activeInoutArgNonactiveInitialResult( _ x: Float ) -> Float {
236
+ var result : Float = 1
237
+ // expected-note @+1 {{cannot differentiate through 'inout' arguments}}
238
+ result += x
239
+ return result
240
+ }
241
+
242
+ // CHECK-LABEL: [AD] Activity info for ${{.*}}activeInoutArgNonactiveInitialResult{{.*}} at (source=0 parameters=(0))
243
+ // CHECK-LABEL: [ACTIVE] %0 = argument of bb0 : $Float
244
+ // CHECK-LABEL: [ACTIVE] %2 = alloc_stack $Float, var, name "result"
245
+ // CHECK-LABEL: [NONE] // function_ref Float.init(_builtinIntegerLiteral:)
246
+ // CHECK-LABEL: [USEFUL] %6 = apply %5(%3, %4) : $@convention(method) (Builtin.IntLiteral, @thin Float.Type) -> Float
247
+ // CHECK-LABEL: [USEFUL] %8 = metatype $@thin Float.Type
248
+ // CHECK-LABEL: [ACTIVE] %9 = begin_access [modify] [static] %2 : $*Float
249
+ // CHECK-LABEL: [NONE] // function_ref static Float.+= infix(_:_:)
250
+ // CHECK-LABEL: [NONE] %11 = apply %10(%9, %0, %8) : $@convention(method) (@inout Float, Float, @thin Float.Type) -> ()
251
+ // CHECK-LABEL: [ACTIVE] %13 = begin_access [read] [static] %2 : $*Float
252
+ // CHECK-LABEL: [ACTIVE] %14 = load [trivial] %13 : $*Float
0 commit comments