@@ -87,6 +87,10 @@ struct InteriorLivenessVisitor :
87
87
public OwnershipUseVisitor<InteriorLivenessVisitor> {
88
88
89
89
InteriorLiveness &interiorLiveness;
90
+
91
+ // If domInfo is nullptr, then InteriorLiveness never assumes dominance. As a
92
+ // result it may report extra unenclosedPhis. In that case, any attempt to
93
+ // create a new phi would result in an immediately redundant phi.
90
94
const DominanceInfo *domInfo = nullptr ;
91
95
92
96
// / handleInnerScopeCallback may add uses to the inner scope, but it may not
@@ -224,10 +228,14 @@ recursivelyVisitInnerGuaranteedPhi(PhiOperand phiOper, bool isReborrow) {
224
228
// other enclosing defs do not have an outer adjacent reborrow.
225
229
return true ;
226
230
})) {
231
+ // TODO: instead of relying on Dominance, we can reformulate this algorithm
232
+ // to detect redundant phis, similar to the SSAUpdater.
233
+ //
227
234
// At least one enclosing def is ownershipDef. If ownershipDef dominates
228
235
// phiValue, then this is consistent with a well-formed linear lifetime, and
229
236
// the phi's uses directly contribute to ownershipDef's liveness.
230
- if (domInfo->dominates (interiorLiveness.ownershipDef ->getParentBlock (),
237
+ if (domInfo &&
238
+ domInfo->dominates (interiorLiveness.ownershipDef ->getParentBlock (),
231
239
phiValue->getParentBlock ())) {
232
240
if (isReborrow) {
233
241
visitInnerBorrow (phiOper.getOperand ());
0 commit comments