@@ -375,6 +375,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
375375 // Mark live arguments in the regions of `regionBranchOp` in `liveArgs`.
376376 auto markLiveArgs = [&](DenseMap<Region *, BitVector> &liveArgs) {
377377 for (Region ®ion : regionBranchOp->getRegions ()) {
378+ if (region.empty ())
379+ continue ;
378380 SmallVector<Value> arguments (region.front ().getArguments ());
379381 BitVector regionLiveArgs = markLives (arguments, nonLiveSet, la);
380382 liveArgs[®ion] = regionLiveArgs;
@@ -420,6 +422,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
420422 auto markNonForwardedReturnValues =
421423 [&](DenseMap<Operation *, BitVector> &nonForwardedRets) {
422424 for (Region ®ion : regionBranchOp->getRegions ()) {
425+ if (region.empty ())
426+ continue ;
423427 Operation *terminator = region.front ().getTerminator ();
424428 nonForwardedRets[terminator] =
425429 BitVector (terminator->getNumOperands (), true );
@@ -499,6 +503,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
499503 // Recompute `resultsToKeep` and `argsToKeep` based on
500504 // `terminatorOperandsToKeep`.
501505 for (Region ®ion : regionBranchOp->getRegions ()) {
506+ if (region.empty ())
507+ continue ;
502508 Operation *terminator = region.front ().getTerminator ();
503509 for (const RegionSuccessor &successor : getSuccessors (®ion)) {
504510 Region *successorRegion = successor.getSuccessor ();
@@ -547,6 +553,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
547553
548554 // Update the terminator operands that need to be kept.
549555 for (Region ®ion : regionBranchOp->getRegions ()) {
556+ if (region.empty ())
557+ continue ;
550558 updateOperandsOrTerminatorOperandsToKeep (
551559 terminatorOperandsToKeep[region.back ().getTerminator ()],
552560 resultsToKeep, argsToKeep, ®ion);
@@ -611,8 +619,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
611619
612620 // Do (2.a) and (2.b).
613621 for (Region ®ion : regionBranchOp->getRegions ()) {
614- assert (! region.empty () && " expected a non-empty region in an op "
615- " implementing `RegionBranchOpInterface` " ) ;
622+ if ( region.empty ())
623+ continue ;
616624 BitVector argsToRemove = argsToKeep[®ion].flip ();
617625 cl.blocks .push_back ({®ion.front (), argsToRemove});
618626 collectNonLiveValues (nonLiveSet, region.front ().getArguments (),
@@ -621,6 +629,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
621629
622630 // Do (2.c).
623631 for (Region ®ion : regionBranchOp->getRegions ()) {
632+ if (region.empty ())
633+ continue ;
624634 Operation *terminator = region.front ().getTerminator ();
625635 cl.operands .push_back (
626636 {terminator, terminatorOperandsToKeep[terminator].flip ()});
0 commit comments