Skip to content

Commit eac6456

Browse files
committed
debug_value instructions should not block analysis of static initializers.
The analyzeStaticInitializer function has a list of specific SIL instructions that it expects to see in static initializers. Anything unexpected blocks the analysis and inhibits optimizations, such as propagating global let variables. Add debug_value instructions to that list so that they do not inhibit optimizations. rdar://problem/26411312
1 parent 21413d3 commit eac6456

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/SIL/SILGlobalVariable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ static bool analyzeStaticInitializer(SILFunction *F, SILInstruction *&Val,
129129
if (I.getKind() != ValueKind::ReturnInst &&
130130
I.getKind() != ValueKind::StructInst &&
131131
I.getKind() != ValueKind::TupleInst &&
132+
I.getKind() != ValueKind::DebugValueInst &&
132133
I.getKind() != ValueKind::IntegerLiteralInst &&
133134
I.getKind() != ValueKind::FloatLiteralInst)
134135
return false;

test/SILOptimizer/globalopt_let_propagation.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ struct IntWrapper4 {
3636
let val2: IntWrapper1
3737
}
3838

39+
// Test with an initializer, where a SIL debug_value instruction might block
40+
// analysis of the initializer and inhibit optimization of the let.
41+
struct IntWrapper5 {
42+
let val: Int
43+
init(val: Int) { self.val = val }
44+
static let Five = IntWrapper5(val: 5)
45+
}
3946

4047
var PROP1: Double {
4148
return PI
@@ -307,11 +314,12 @@ public func test_static_struct_let_wrapped_int() -> Int {
307314
// CHECK: bb0:
308315
// CHECK-NOT: global_addr
309316
// CHECK: integer_literal
317+
// CHECK-NOT: global_addr
310318
// CHECK: struct
311319
// CHECK: return
312320
@inline(never)
313321
public func test_static_struct_let_struct_wrapped_multiple_ints() -> Int {
314-
return B.IW4.val.val.val + B.IW4.val2.val + 1
322+
return B.IW4.val.val.val + B.IW4.val2.val + IntWrapper5.Five.val + 1
315323
}
316324

317325
// Test accessing multiple Int fields wrapped into multiple structs, where each struct may have
@@ -320,11 +328,12 @@ public func test_static_struct_let_struct_wrapped_multiple_ints() -> Int {
320328
// CHECK: bb0:
321329
// CHECK-NOT: global_addr
322330
// CHECK: integer_literal
331+
// CHECK-NOT: global_addr
323332
// CHECK: struct
324333
// CHECK: return
325334
@inline(never)
326335
public func test_static_class_let_struct_wrapped_multiple_ints() -> Int {
327-
return C.IW4.val.val.val + C.IW4.val2.val + 1
336+
return C.IW4.val.val.val + C.IW4.val2.val + IntWrapper5.Five.val + 1
328337
}
329338

330339
// Test accessing multiple Int fields wrapped into multiple tuples, where each tuple may have

0 commit comments

Comments
 (0)