@@ -623,34 +623,37 @@ CallBase *llvm::promoteCallWithIfThenElse(CallBase &CB, Function &Callee,
623623 // All the ctx-es belonging to a function must have the same size counters.
624624 Ctx.resizeCounters (NewCountersSize);
625625
626- // Maybe in this context, the indirect callsite wasn't observed at all
626+ // Maybe in this context, the indirect callsite wasn't observed at all. That
627+ // would make both direct and indirect BBs cold - which is what we already
628+ // have from resising the counters.
627629 if (!Ctx.hasCallsite (CSIndex))
628630 return ;
629631 auto &CSData = Ctx.callsite (CSIndex);
630- auto It = CSData.find (CalleeGUID);
631632
632- // Maybe we did notice the indirect callsite, but to other targets.
633- if (It == CSData.end ())
634- return ;
635-
636- assert (CalleeGUID == It->second .guid ());
637-
638- uint32_t DirectCount = It->second .getEntrycount ();
639- uint32_t TotalCount = 0 ;
633+ uint64_t TotalCount = 0 ;
640634 for (const auto &[_, V] : CSData)
641635 TotalCount += V.getEntrycount ();
636+ uint64_t DirectCount = 0 ;
637+ // If we called the direct target, update the DirectCount. If we didn't, we
638+ // still want to update the indirect BB (to which the TotalCount goes, in
639+ // that case).
640+ if (auto It = CSData.find (CalleeGUID); It != CSData.end ()) {
641+ assert (CalleeGUID == It->second .guid ());
642+ DirectCount = It->second .getEntrycount ();
643+ // This direct target needs to be moved to this caller under the
644+ // newly-allocated callsite index.
645+ assert (Ctx.callsites ().count (NewCSID) == 0 );
646+ Ctx.ingestContext (NewCSID, std::move (It->second ));
647+ CSData.erase (CalleeGUID);
648+ }
649+
642650 assert (TotalCount >= DirectCount);
643- uint32_t IndirectCount = TotalCount - DirectCount;
651+ uint64_t IndirectCount = TotalCount - DirectCount;
644652 // The ICP's effect is as-if the direct BB would have been taken DirectCount
645653 // times, and the indirect BB, IndirectCount times
646654 Ctx.counters ()[DirectID] = DirectCount;
647655 Ctx.counters ()[IndirectID] = IndirectCount;
648656
649- // This particular indirect target needs to be moved to this caller under
650- // the newly-allocated callsite index.
651- assert (Ctx.callsites ().count (NewCSID) == 0 );
652- Ctx.ingestContext (NewCSID, std::move (It->second ));
653- CSData.erase (CalleeGUID);
654657 };
655658 CtxProf.update (ProfileUpdater, &Caller);
656659 return &DirectCall;
0 commit comments