[PATCH] D152399: [CodeGen] Fine tune MachineFunctionSplitPass (MFS) for FSAFDO.
David Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 12:37:35 PDT 2023
davidxl added inline comments.
================
Comment at: llvm/lib/CodeGen/MachineFunctionSplitter.cpp:111
+ if (IsFSAFDOFlavor)
+ return Count.has_value() && Count.value() == 0;
+
----------------
wenlei wrote:
> shenhan wrote:
> > wenlei wrote:
> > > shenhan wrote:
> > > > shenhan wrote:
> > > > > wenlei wrote:
> > > > > > snehasish wrote:
> > > > > > > Can we use `< ColdCountThreshold` instead of `== 0`?
> > > > > > >
> > > > > > > `ColdCountThreshold` defaults to 1 so it should have the same effect.
> > > > > > So for IRPGO, we want to treat unknown as zero/cold, but not so for FSAFDO? Why is the difference?
> > > > > >
> > > > > > IIRC after profile inference, not sampled block will still get zero counts. What produces `Count.has_value() == false`?
> > > > > > So for IRPGO, we want to treat unknown as zero/cold, but not so for FSAFDO? Why is the difference?
> > > > >
> > > > > Yes, the reason is that when IRPGO dictates a zero block counter, we trust it with higher confidence, but less so for FSAFDO. The latter could be a miss sampling or inference / propagation error. Since the cost of splitting a non-cold block is high, we only split when we are sure of the block counter.
> > > > >
> > > > > > IIRC after profile inference, not sampled block will still get zero counts. What produces Count.has_value() == false?
> > > > > You are right. This is an extra caution in (unlikely) case when Count has no value and we don't want an exception to be thrown.
> > > > Done.
> > > > Yes, the reason is that when IRPGO dictates a zero block counter, we trust it with higher confidence, but less so for FSAFDO. The latter could be a miss sampling or inference / propagation error.
> > >
> > > But checking `has_value` isn't going to be able to differentiate inaccurate counts.
> > >
> > > > You are right. This is an extra caution in (unlikely) case when Count has no value and we don't want an exception to be thrown.
> > >
> > > In this case, we don't need to guard it under `HasAccurateProfile` as it applies to IRPGO as well.
> > Thanks. I made the following change:
> >
> > Firstly, per hoy's comment, I replaced "if (HasAccurateProfile) {" with "if (!HasAccurateProfile) {", noticing that HasAccurateProfile should be False when using FSAFDO or CSSPGO, and True when using IRPGO. Previously the value is negated.
> >
> > Secondly, when !HasAccurateProfile && !Count.has_value() (although the latter is unlikely), this needs to return false. Whereas when HasAccurateProfile && !Count.has_value(), this returns true. So I have to guard it with HasAccureateProfile.
> >
> > Thirdly, the next line "if (!Count)" is not testing "if (Count !=0)", it is testing "if(!Count.has_value())", it is little bit misleading, so I changed it to if(!Count.has_value()), so it is clear why this is guarded under HasAccurateProfile.
> >
> > Hope this is clearer.
> If the key difference is how we treat unknown/missing counts, I'd suggest let's make it explicit.
>
> Would it work if we just make a simple and explicit change:
>
> ```
> if (!Count)
> return true;
> ```
> -->
> ```
> // Treat unknown/missing counts as cold if profile is accurate, but not if profile is inaccurate.
> if (!Count.has_value()) {
> return HasAccurateProfile;
> }
> ```
> If the key difference is how we treat unknown/missing counts, I'd suggest let's make it explicit.
>
> Would it work if we just make a simple and explicit change:
>
> ```
> if (!Count)
> return true;
> ```
> -->
> ```
> // Treat unknown/missing counts as cold if profile is accurate, but not if profile is inaccurate.
> if (!Count.has_value()) {
> return HasAccurateProfile;
> }
> ```
Sounds reasonable.
Missing count in IRPGO does mean very cold (module not even linked into the binary), but for sample PGO, it means unknown -- e.g. new code added which is not sampled. In this sense, their handling should be different.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152399/new/
https://reviews.llvm.org/D152399
More information about the llvm-commits
mailing list