[PATCH] D144302: [PGO] Setting ValueProfNode Array's Alignment

Qiongsi Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 14:20:41 PST 2023


qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: sfertile, w2yehia.
qiongsiwu1 added a project: LLVM.
Herald added subscribers: Enna1, wenlei, hiraditya.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added a project: Sanitizers.
Herald added subscribers: llvm-commits, Sanitizers.

`instrprof` currently does not set `__llvm_prf_vnds`'s alignment after creating it. The consequence is that the alignment is set to 16 later (https://github.com/llvm/llvm-project/blob/c0f3ac1d0015fd051144a987ff500b888a32be86/llvm/lib/IR/DataLayout.cpp#L1019). This can lead to undefined behaviour when we calculate `NumVNodes` in `lprofGetLoadModuleSignature` (https://github.com/llvm/llvm-project/blob/c0f3ac1d0015fd051144a987ff500b888a32be86/compiler-rt/lib/profile/InstrProfilingMerge.c#L32). The reason is that when the `__llvm_prf_vnds` array is 16 byte aligned, `__llvm_profile_end_vnodes() - __llvm_profile_begin_vnodes()` may not be a multiple of the size of ValueProfNode (which is 24).

This patch sets `__llvm_prf_vnds`'s alignment to 8, which divides 24. Then `__llvm_profile_end_vnodes() - __llvm_profile_begin_vnodes()` will be a multiple of 24.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144302

Files:
  compiler-rt/include/profile/InstrProfData.inc
  compiler-rt/lib/profile/InstrProfiling.h
  llvm/include/llvm/ProfileData/InstrProfData.inc
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/alignment.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144302.498504.patch
Type: text/x-patch
Size: 6493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230217/3f695e0c/attachment.bin>


More information about the llvm-commits mailing list