Skip to content

LLVM trunk cannot be built with LLVM 21.1-rc3 when using AutoPGO due to lifetime intrinsic incompatibility #153917

@chatgpt-copypasta

Description

@chatgpt-copypasta

Description

Building LLVM trunk (commit 76d993b or later) with LLVM 21.1-rc3 as the host compiler fails during the instrumented build phase of AutoPGO. The build fails with IR verification errors about lifetime intrinsics having incorrect argument types.

Root Cause

Commit c23b4fb "[IR] Remove size argument from lifetime intrinsics (#150248)" removed the size argument from llvm.lifetime.start/end intrinsics. When using LTO during the AutoPGO instrumented build, IR generated by the older host compiler (21.1-rc3) contains the old signature with size arguments, but trunk's verifier expects the new signature without them.

System Configuration

  • OS: Linux 6.16.1-zen1 x86_64
  • CPU: AMD Ryzen 9 9950X (Zen5)
  • Host Compiler: LLVM 21.1-rc3
  • Target: LLVM trunk @ 76d993b (929 commits after breaking change)
  • Build Method: Custom AutoPGO script with aggressive optimizations

Reproduction

Using LLVM's AutoPGO script or custom build with these flags:

BASE_CFLAGS="-O3 -march=znver5 -mtune=znver5 -mcmodel=medium -pipe"
BASE_CFLAGS+=" -flto=thin -fno-semantic-interposition"
BASE_CFLAGS+=" -mavx512f -mavx512bw -mavx512dq -mavx512vl -mfma -mbmi2"
BASE_CFLAGS+=" -mllvm -vp-counters-per-site=111"
BASE_CFLAGS+=" -mllvm -inline-threshold=1000"
BASE_CFLAGS+=" -mllvm -unroll-threshold=500"

python3 llvm/utils/collect_and_build_with_pgo.py \
  --llvm-dir /home/build/llvm-project/llvm \
  --stages instrumented

Failure Point

Stage1 builds successfully (394s for 3546 targets), but fails during instrumented build when linking with ThinLTO:

*** Building instrumented clang...
[3535/3541 320.860s] Linking CXX executable bin/lld
FAILED: bin/lld 
: && /home/build/llvm22-autopgo/stage1/bin/clang++ -O3 -march=znver5 -mtune=znver5 
-mcmodel=medium -pipe -flto=thin -fno-semantic-interposition [...] -o bin/lld [...]
clang++: warning: argument unused during compilation: '-mllvm -vp-counters-per-site=111'
clang++: warning: argument unused during compilation: '-mllvm -inline-threshold=1000'
[...more -mllvm warnings...]
Intrinsic has incorrect argument type!
ptr @llvm.lifetime.start.p0
Intrinsic has incorrect argument type!
ptr @llvm.lifetime.end.p0
[...repeats 18+ times...]
LLVM ERROR: Broken module found, compilation aborted!
Stack dump:
0.    Running pass "verify" on module "lib/libLLVMAMDGPUDesc.a(AMDGPUMCTargetDesc.cpp.o at 3730954)"
 #0 0x00006279a61a6a27 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/bin/ld.lld+0x38ffa27)
[...stack trace...]
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: linker command failed due to signal

The failure occurs when stage1 clang (built with 21.1-rc3, running trunk code) attempts to LTO-link the instrumented build. The IR contains lifetime intrinsics with the old signature from 21.1-rc3's codegen, but trunk's verifier expects the new signature.

Impact

  • Breaks the standard bootstrap workflow where stable releases build trunk
  • AutoPGO builds that worked with trunk as of early November 2024 now fail
  • Forces users to either:
    • Use trunk to build trunk (circular dependency, ironically works)
    • Build without AutoPGO/LTO (loses significant performance benefits)
    • Revert to commits before c23b4fb (loses 929+ commits of improvements)

Additional Context

  • The -mllvm flags shown as "unused during compilation" warnings are actually critical for PGO instrumentation, particularly -vp-counters-per-site=111
  • This worked successfully when building trunk just 24 hours ago, suggesting the incompatibility was introduced very recently or is triggered by specific build configurations
  • Using trunk to build trunk (LLVM 22 as host) bypasses the issue since both compiler and verifier agree on the new intrinsic signature

Expected Behavior

LLVM trunk should be buildable with recent stable releases to maintain a proper bootstrap chain. Either:

  1. The verifier should accept both old and new lifetime intrinsic signatures during a transition period
  2. The LTO pipeline should handle signature mismatches gracefully
  3. This should be documented as a breaking change requiring LLVM 22+ to build trunk with AutoPGO/LTO

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions