[llvm] [OpenMPOpt][PGO] Set entry count on merged parallel wrapper (PR #221654)

Robert Imschweiler via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 12:50:34 PDT 2026


================
@@ -1359,6 +1398,15 @@ struct OpenMPOpt {
             CallInst::Create(FT, Callee, Args, "", CI->getIterator());
         if (CI->getDebugLoc())
           NewCI->setDebugLoc(CI->getDebugLoc());
+        // Each body runs once per wrapper entry. Without a callsite weight,
+        // sample PGO treats these calls as cold.
+        if (WrapperCount && SampleProfile) {
+          uint64_t Count = *WrapperCount;
+          uint32_t Weight = Count > std::numeric_limits<uint32_t>::max()
+                                ? std::numeric_limits<uint32_t>::max()
+                                : static_cast<uint32_t>(Count);
+          setBranchWeights(*NewCI, {Weight}, /*IsExpected=*/false);
----------------
ro-i wrote:

nit: I think you can also use setFittedBranchWeights, which would allow you to drop your own clamping to uint32 max (and you could drop the limits header include).

https://github.com/llvm/llvm-project/pull/221654


More information about the llvm-commits mailing list