@@ -1323,11 +1323,21 @@ class FieldSensitiveMultiDefPrunedLiveRange
13231323 defBlocks.insert (defBlock, span);
13241324 initializeDefBlock (defBlock, span);
13251325
1326- if (auto ta = dyn_cast<TryApplyInst>(node)) {
1327- // The value becomes live on the success edge.
1328- // Mark the basic block the try_apply terminates as a dead-to-live
1329- // edge.
1330- initializeDefBlock (ta->getParent (), span,
1326+ if (defBlock != node->getParentBlock ()) {
1327+ // If the block the value becomes defined in is different from the
1328+ // defining instruction, then the def notionally occurs "on the edge"
1329+ // between the instruction (which must be a terminator) and the defined-in
1330+ // successor block. Mark the original block as a dead-to-live edge.
1331+ auto ti = cast<TermInst>(node);
1332+
1333+ assert (std::find (ti->getSuccessorBlocks ().begin (),
1334+ ti->getSuccessorBlocks ().end (),
1335+ defBlock) != ti->getSuccessorBlocks ().end ()
1336+ && " defined-in block should be either the same block as the "
1337+ " defining instruction or a successor of the "
1338+ " defining terminator" );
1339+
1340+ initializeDefBlock (ti->getParent (), span,
13311341 FieldSensitivePrunedLiveBlocks::DeadToLiveEdge);
13321342 }
13331343 }
0 commit comments