[all-commits] [llvm/llvm-project] 401f76: [PGO] Setting ValueProfNode Array's Alignment

Qiongsi Wu via All-commits all-commits at lists.llvm.org
Thu Feb 23 16:12:31 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 401f768061e6b7498f6f5d50f8e31143c4d6ae2d
      https://github.com/llvm/llvm-project/commit/401f768061e6b7498f6f5d50f8e31143c4d6ae2d
  Author: Qiongsi Wu <qwu at ibm.com>
  Date:   2023-02-23 (Thu, 23 Feb 2023)

  Changed paths:
    M llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
    A llvm/test/Instrumentation/InstrProfiling/align32.ll
    M llvm/test/Instrumentation/InstrProfiling/icall-comdat.ll

  Log Message:
  -----------
  [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




More information about the All-commits mailing list