Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h =================================================================== --- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h +++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h @@ -867,6 +867,12 @@ OverlapMap OverlapFragments; VarToFragments SeenFragments; + /// Mapping of DBG_INSTR_REF instructions to their values, for those + /// DBG_INSTR_REFs that call resolveDbgPHIs. These variable references solve + /// a mini SSA problem caused by DBG_PHIs being cloned, this colleciton caches + /// the result. + DenseMap> SeenDbgPHIs; + /// True if we need to examine call instructions for stack clobbers. We /// normally assume that they don't clobber SP, but stack probes on Windows /// do. Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp =================================================================== --- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -3092,6 +3092,7 @@ DebugPHINumToValue.clear(); OverlapFragments.clear(); SeenFragments.clear(); + SeenDbgPHIs.clear(); return Changed; } @@ -3357,6 +3358,12 @@ ValueIDNum **MLiveIns, MachineInstr &Here, uint64_t InstrNum) { + // This function will be called twice per DBG_INSTR_REF, and might end up + // computing lots of SSA information: memoize it. + auto SeenDbgPHIIt = SeenDbgPHIs.find(&Here); + if (SeenDbgPHIIt != SeenDbgPHIs.end()) + return SeenDbgPHIIt->second; + // Pick out records of DBG_PHI instructions that have been observed. If there // are none, then we cannot compute a value number. auto RangePair = std::equal_range(DebugPHINumToValue.begin(), @@ -3406,6 +3413,7 @@ if (AvailIt != AvailableValues.end()) { // Actually, we already know what the value is -- the Use is in the same // block as the Def. + SeenDbgPHIs.insert({&Here, ValueIDNum::fromU64(AvailIt->second)}); return ValueIDNum::fromU64(AvailIt->second); } @@ -3452,8 +3460,10 @@ // Are all these things actually defined? for (auto &PHIIt : PHI->IncomingValues) { // Any undef input means DBG_PHIs didn't dominate the use point. - if (Updater.UndefMap.find(&PHIIt.first->BB) != Updater.UndefMap.end()) + if (Updater.UndefMap.find(&PHIIt.first->BB) != Updater.UndefMap.end()) { + SeenDbgPHIs.insert({&Here, None}); return None; + } ValueIDNum ValueToCheck; ValueIDNum *BlockLiveOuts = MLiveOuts[PHIIt.first->BB.getNumber()]; @@ -3471,8 +3481,10 @@ ValueToCheck = VVal->second; } - if (BlockLiveOuts[Loc.asU64()] != ValueToCheck) + if (BlockLiveOuts[Loc.asU64()] != ValueToCheck) { + SeenDbgPHIs.insert({&Here, None}); return None; + } } // Record this value as validated. @@ -3481,5 +3493,6 @@ // All the PHIs are valid: we can return what the SSAUpdater said our value // number was. + SeenDbgPHIs.insert({&Here, Result}); return Result; }