Skip to content

Commit 07d4655

Browse files
committed
Fix an assert in MultiDefPrunedLiveness
Fixes an assert that was meant for a narrow case and accidentally applied too broadly. This variation of the liveness utilities wasn't being exercised widely, and is difficult to test with valid OSSA.
1 parent c7b3870 commit 07d4655

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ void MultiDefPrunedLiveness::findBoundariesInBlock(
579579
}
580580
}
581581
}
582-
assert(prevCount < boundary.deadDefs.size() + boundary.lastUsers.size()
582+
// All live-within blocks must contain a boundary.
583+
assert(isLiveOut
584+
|| (prevCount < boundary.deadDefs.size() + boundary.lastUsers.size())
583585
&& "findBoundariesInBlock must be called on a live block");
584586
}
585587

test/SILOptimizer/ossa_lifetime_analysis.sil

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,46 @@ bb0(%0 : @guaranteed $D):
175175
%99 = tuple()
176176
return %99 : $()
177177
}
178+
179+
// CHECK-LABEL: @testMultiDef
180+
// CHECK: MultiDef lifetime analysis:
181+
// CHECK: def: [[CP0:%.*]] = copy_value %0 : $C
182+
// CHECK: def: %{{.*}} = copy_value %0 : $C
183+
// CHECK: def: %{{.*}} = move_value [[CP0]] : $C
184+
// CHECK: def: %{{.*}} = argument of bb4 : $C
185+
// CHECK: bb0: LiveOut,
186+
// CHECK: bb2: LiveWithin,
187+
// CHECK: bb3: LiveWithin,
188+
// CHECK: bb4: LiveWithin,
189+
// CHECK: bb1: LiveWithin,
190+
// CHECK: lifetime-ending user: %{{.*}} = move_value [[CP0]] : $C
191+
// CHECK: lifetime-ending user: destroy_value [[CP0]] : $C
192+
// CHECK: lifetime-ending user: br bb4(%5 : $C)
193+
// CHECK: lifetime-ending user: br bb4(%7 : $C)
194+
// CHECK: lifetime-ending user: destroy_value %9 : $C
195+
sil [ossa] @testMultiDef : $@convention(thin) (@guaranteed C) -> () {
196+
bb0(%0 : @guaranteed $C):
197+
%copy0 = copy_value %0 : $C
198+
debug_value [trace] %copy0 : $C
199+
cond_br undef, bb1, bb3
200+
201+
bb1:
202+
destroy_value %copy0 : $C
203+
br bb2
204+
205+
bb2:
206+
%copy2 = copy_value %0 : $C
207+
debug_value [trace] %copy2 : $C
208+
br bb4(%copy2 : $C)
209+
210+
bb3:
211+
%copy3 = move_value %copy0 : $C
212+
debug_value [trace] %copy3 : $C
213+
br bb4(%copy3 : $C)
214+
215+
bb4(%phi : @owned $C):
216+
debug_value [trace] %phi : $C
217+
destroy_value %phi : $C
218+
%99 = tuple()
219+
return %99 : $()
220+
}

0 commit comments

Comments
 (0)