[PGO] Setting ValueProfNode Array's Alignment
authorQiongsi Wu <qwu@ibm.com>
Thu, 23 Feb 2023 22:31:50 +0000 (17:31 -0500)
committerQiongsi Wu <qwu@ibm.com>
Fri, 24 Feb 2023 00:07:29 +0000 (19:07 -0500)
commit401f768061e6b7498f6f5d50f8e31143c4d6ae2d
tree45ba001a5f7f47ca7eaea2a857a2daf8a1a6787a
parent21631b567e88b5a1146a74b0a25f7a20afef8afb
[PGO] Setting ValueProfNode Array's Alignment

`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, 20 on 32 bit targets).

This patch sets `__llvm_prf_vnds`'s alignment to its ABI alignment, which always divides its size. Then `__llvm_profile_end_vnodes() - __llvm_profile_begin_vnodes()` will be a multiple of `sizeof(ValueProfNode)`.

Reviewed By: w2yehia, MaskRay

Differential Revision: https://reviews.llvm.org/D144302
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/align32.ll [new file with mode: 0644]
llvm/test/Instrumentation/InstrProfiling/icall-comdat.ll