Index: llvm/lib/Transforms/Scalar/LoopDistribute.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopDistribute.cpp +++ llvm/lib/Transforms/Scalar/LoopDistribute.cpp @@ -785,6 +785,8 @@ return fail("HeuristicDisabled", "distribution heuristic disabled"); LLVM_DEBUG(dbgs() << "\nDistributing loop: " << *L << "\n"); + + bool Modified = false; // We're done forming the partitions set up the reverse mapping from // instructions to partitions. Partitions.setupPartitionIdOnInstructions(); @@ -792,8 +794,10 @@ // To keep things simple have an empty preheader before we version or clone // the loop. (Also split if this has no predecessor, i.e. entry, because we // rely on PH having a predecessor.) - if (!PH->getSinglePredecessor() || &*PH->begin() != PH->getTerminator()) + if (!PH->getSinglePredecessor() || &*PH->begin() != PH->getTerminator()) { + Modified = true; SplitBlock(PH, PH->getTerminator(), DT, LI); + } // If we need run-time checks, version the loop now. auto PtrToPartition = Partitions.computePartitionSetForPointers(*LAI); @@ -804,7 +808,8 @@ if (LAI->hasConvergentOp() && !Checks.empty()) { return fail("RuntimeCheckWithConvergent", - "may not insert runtime check with convergent operation"); + "may not insert runtime check with convergent operation", + Modified); } if (!Pred.isAlwaysTrue() || !Checks.empty()) { @@ -835,6 +840,7 @@ // Create identical copies of the original loop for each partition and hook // them up sequentially. Partitions.cloneLoops(); + Modified = true; // Now, we remove the instruction from each loop that don't belong to that // partition. @@ -854,11 +860,11 @@ L->getHeader()) << "distributed loop"; }); - return true; + return Modified; } - /// Provide diagnostics then \return with false. - bool fail(StringRef RemarkName, StringRef Message) { + /// Provide diagnostics then \return with Modified. + bool fail(StringRef RemarkName, StringRef Message, bool Modified=false) { LLVMContext &Ctx = F->getContext(); bool Forced = isForced().getValueOr(false); @@ -887,7 +893,7 @@ *F, L->getStartLoc(), "loop not distributed: failed " "explicitly specified loop distribution")); - return false; + return Modified; } /// Return if distribution forced to be enabled/disabled for the loop.