Skip to content

Commit 8f34d9c

Browse files
committed
Add a comment regarding an optimizer rule for self-loops.
1 parent 98b6e09 commit 8f34d9c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
///
13+
/// Note: Unreachable blocks must always be eliminated before simplifying
14+
/// useless phis. Otherwise self-loops will result in invalid SIL:
15+
///
16+
/// bb1(%phi):
17+
/// apply %use(%phi)
18+
/// %def = apply %getValue()
19+
/// br bb1(%def)
20+
///
21+
/// When bb1 is unreachable, %phi will be removed as useless:
22+
/// bb1:
23+
/// apply %use(%def)
24+
/// %def = apply %getValue()
25+
/// br bb1(%def)
26+
///
27+
/// This is considered invalid SIL because SIL has a special SSA dominance rule
28+
/// that does not allow a use above a def in the same block.
29+
//===----------------------------------------------------------------------===//
1230

1331
#define DEBUG_TYPE "sil-simplify-cfg"
1432

0 commit comments

Comments
 (0)