This is an archive of the discontinued LLVM Phabricator instance.

[PseudoProbe] Clean up dwarf discriminator and avoid duplicating factor.
ClosedPublic

Authored by hoy on Apr 17 2023, 2:04 PM.

Details

Summary

A pseudo probe is created with dwarf line information shared with its nearest instruction. If the instruction comes with a dwarf discriminator, it will be shared with the probe as well. This can confuse the later FS-AFDO discriminator assignment pass. To fix this, I'm cleaning up the discriminator fields for probes when they are inserted.

I also notice another possibility to change the discriminator field of pseudo probes in the pipeline before the FS discriminator assignment pass. That is the loop unroller, which assigns duplication factor to instruction being vectorized. I'm disabling that for pseudo probe intrinsics specifically, also for callsites with probes.

Diff Detail

Event Timeline

hoy created this revision.Apr 17 2023, 2:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 17 2023, 2:04 PM
hoy requested review of this revision.Apr 17 2023, 2:04 PM
hoy edited the summary of this revision. (Show Details)Apr 17 2023, 2:48 PM
hoy added reviewers: wenlei, wlei.
wenlei added inline comments.May 8 2023, 5:00 PM
llvm/include/llvm/IR/DebugInfoMetadata.h
2311

perhaps it's worth explaining in the comment, the model used by probe, and why duplication factor isn't needed.

2312–2313

since you already guard this at call sites, is this still needed, or should it be an assert?

line-based FS-AFDO doesn't use duplication factor either, where is the use of duplication factor prevented for that today?

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
356

What if two probes come from the same line? should we still expect a unique line+base_disc to be able to differentiate them?

hoy added inline comments.May 8 2023, 10:11 PM
llvm/include/llvm/IR/DebugInfoMetadata.h
2311

comment updated.

2312–2313

This is still needed as the guard on the callsite is to filter block probes. The logic here is mainly for callsite probes.

line-based FS-AFDO doesn't use duplication factor either, where is the use of duplication factor prevented for that today?

The callsites of this function are disabled at For FS-AFDO, e.g, https://github.com/llvm/llvm-project/blob/5362a0d859d8e96b3f7c0437b7866e17a818a4f7/llvm/lib/Transforms/Utils/LoopUnroll.cpp#L516 . The logic here is not only for FS-AFDO, but also for in general not screwing up callsite probe ids.

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
356

We do not need a unique line number for each probe as the probe id is used to determine the probe's discriminator.

hoy updated this revision to Diff 520590.May 8 2023, 10:13 PM

Addressing comments.

wenlei added inline comments.May 9 2023, 9:03 AM
llvm/include/llvm/IR/DebugInfoMetadata.h
2312–2313

This is still needed as the guard on the callsite is to filter block probes. The logic here is mainly for callsite probes.

Where is the call site for call probes? Why this is guarded in the function for call probe, but at call site for block probe?

I saw three places where this clone is used, and two of the three you guarded them at call site. The remaining one is in VPlan.cpp. Is that inconsistency intentional?

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
356

Sounds good, hope it (not having unique line+disc) will not make merging probes more likely to happen for downstream opts..

hoy added inline comments.May 9 2023, 9:19 AM
llvm/include/llvm/IR/DebugInfoMetadata.h
2312–2313

Block probe is in form of probe intrinsics, and the checks enforced in this change, i.,e, if (!I.isDebugOrPseudoInst()), excludes probe intrinsics from getting duplicated factor updated.

Call probe is just attached to user call instruction in form of dwarf discriminator, and they are not excluded at the callsites of this function. We could do that, but I think it's more cleaner to do it here.

I saw three places where this clone is used, and two of the three you guarded them at call site. The remaining one is in VPlan.cpp. Is that inconsistency intentional?

Good catch. Should also exclude probe intrinsic there for completeness, though it doesn't affect anything since FS-AFDO is already excluded there.

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
356

Right, it will unlikely affect the merging which doesn't look at debug data anyways.

hoy updated this revision to Diff 520726.May 9 2023, 9:21 AM

Updating D148569: [PseudoProbe] Clean up dwarf discriminator and avoid duplicating factor.

hoy added inline comments.May 9 2023, 9:23 AM
llvm/include/llvm/IR/DebugInfoMetadata.h
2312–2313

Actually we have to exclude probe there, otherwise the duplication factor will be mistakenly encoded as a FS-discriminator.

wenlei accepted this revision.May 10 2023, 9:01 AM

lgtm, thanks.

This revision is now accepted and ready to land.May 10 2023, 9:01 AM
hoy updated this revision to Diff 521027.May 10 2023, 10:14 AM

Cleaning up a test.

This revision was landed with ongoing or failed builds.May 10 2023, 11:26 AM
This revision was automatically updated to reflect the committed changes.