Languages: [EN] English | [KO] 한국어
Technical Report: Front-end PGO & LLVM Optimization for AMD Zen4
기술 보고서: AMD Zen4 아키텍처를 위한 프론트엔드 PGO 및 LLVM 컴파일 최적화 분석
Introduction
서론
This report documents the application of LLVM Front-end PGO
and Zen4-specific compiler tuning to a control-flow heavy
workload. The primary focus is on branch prediction convergence,
basic block layout optimization, and instruction cache locality
under real-world execution profiles.
본 보고서는 제어 흐름 집약적 워크로드에 대한 LLVM 프론트엔드 PGO 및
Zen4 특화 컴파일러 튜닝 적용 과정을 기록합니다. 실제 실행 프로파일
기반의 분기 예측 수렴, 기본 블록 배치 최적화, 명령어 캐시 지역성을
중점적으로 다룹니다.
Build Configuration
빌드 구성
- AMD Zen4–specific build (not executable on CPUs other than the AMD Zen4 series)
- Profile-Guided Optimization applied (PGO)
- Build Setup:
- Environment: Visual Studio 2026 Insider (CMake + Ninja)
- Toolchain: LLVM 21.1.8 (clang-cl, lld)
- Toolchain: LLVM 21.1.8 (clang-cl, lld)
- CMake patched for clang-cl + PGO support on Win64
- Package Manager: vcpkg
- Platform: Windows 11
- PGO data collection build options:
-fprofile-instr-generate -fprofile-loop-info - PGO optimization applied build options:
-fprofile-instr-use
- AMD Zen4 전용 (AMD Zen4 계열 외 CPU에서는 실행 불가)
- 프로파일 가이드 최적화 적용 (PGO)
- 빌드 설정:
- 환경: Visual Studio 2026 Insider (CMake + Ninja)
- Toolchain: LLVM 21.1.8 (clang-cl, lld)
- clang-cl + Win64 PGO 지원을 위한 CMake 패치
- 패키지 매니저: vcpkg
- 플랫폼: Windows 11
- PGO 데이터 수집 빌드 옵션:
-fprofile-instr-generate -fprofile-loop-info - PGO 최적화 적용 빌드 옵션:
-fprofile-instr-use
PGO Data Summary
PGO 데이터 요약
- Instrumentation level: Front-end
- Total functions: 99003
- Maximum function count: 555422090880
- Maximum internal block count: 1837157549715
- Total number of blocks: 281908
- Total count: 29961822282003
- Coverage report: Download
Why Front-end PGO?
Front-end PGO 선택 이유
-
The target workload is control-flow bound rather than compute-bound
- The dominant cost comes from conditional branches, state checks, and cache validity checks
- ALU throughput and vectorization have less impact than branch mispredictions and control-flow overhead
-
Hot paths matter more than hot loops
- The workload is built around state machines rather than tight loops
- The same function can execute very different paths depending on the current runtime state
- Performance is determined by execution paths across functions, not by individual functions alone
-
Vulkan renderers are inherently branch-heavy
- Extensive conditional logic for pipeline state, resource caches, and GPU capability checks
- Composed of many small functions with frequent branching
- Branch mispredictions directly translate into frame time spikes
-
Front-end PGO learns real-world branch probabilities and state transitions
- Collects accurate branch selection frequencies from real execution
- Places frequently executed basic blocks adjacently in memory
- Separates rarely executed error-handling and exceptional paths into cold regions
- Improves both branch prediction accuracy and instruction cache locality
-
IR PGO can induce excessive inlining and code growth in state-machine-heavy workloads
- IR PGO aggressively optimizes hot IR regions, often increasing inlining decisions
- Code size growth increases instruction cache pressure
- This can harm frame time stability despite improving microbenchmarks
-
Real usage-based Front-end PGO stabilizes state-machine execution paths
- Captures diverse transitions such as menus, loading screens, real-world usage scenarios, UI, and scripted events
- Extended usage sessions allow branch probabilities to converge statistically
- Represents execution patterns that short benchmarks and automated tests fail to capture
-
The primary benefit is frame time stability rather than peak FPS
- Average FPS gains may be modest
- Frame drops, stutter, and hitches during real-world usage are significantly reduced
- Results in a smoother and more consistent user experience
-
대상 워크로드는 연산 집약적이 아닌 제어 흐름 집약적 구조
- 주요 비용은 산술 연산이 아니라 조건 분기, 상태 체크, 캐시 여부 판단에 있음
- ALU 성능이나 벡터화보다 분기 예측 실패 및 제어 흐름 비용이 성능에 더 큰 영향
-
Hot loop보다 Hot path가 성능을 좌우
- 워크로드는 반복 루프 중심이 아닌 상태 머신 기반 구조
- 동일한 함수라도 호출되는 런타임 상태에 따라 전혀 다른 실행 경로를 가짐
- 함수 자체보다 함수 간 실행 경로(Path)의 연속성이 중요
-
Vulkan 렌더러는 분기 집약적(branch-heavy) 구조
- 파이프라인 상태, 리소스 캐시, GPU 기능 여부에 따른 조건 분기가 매우 많음
- 작은 함수와 다수의 조건 분기가 결합된 구조
- 분기 예측 실패 시 프레임 타임 스파이크로 직결
-
Front-end PGO는 실제 분기 확률과 상태 전이를 직접 학습
- 실제 실행 시 어떤 분기가 얼마나 자주 선택되는지를 수집
- 자주 연속 실행되는 basic block을 인접하게 배치
- 드물게 실행되는 오류 처리 및 예외 경로를 cold path로 분리
- 분기 예측 정확도와 instruction cache locality를 동시에 개선
-
IR PGO는 상태 머신 집약적 워크로드에서 과도한 인라이닝과 코드 팽창을 유발
- IR PGO는 실행 빈도가 높은 IR 단위에 반응하여 인라이닝을 공격적으로 수행
- 코드 사이즈 증가로 인해 I-cache 압박이 발생
- 성능 증가보다 프레임 타임 불안정성을 초래하는 경우가 있음
-
실제 사용 기반 Front-end PGO는 상태 머신 경로를 통계적으로 수렴
- 메뉴, 로딩, 실행 시나리오, UI, 이벤트 등 다양한 상태 전이를 포함
- 장시간 실제 사용을 통해 분기 확률이 안정적으로 수렴
- 벤치마크나 자동화 테스트로는 재현하기 어려운 경로까지 반영 가능
-
결과적으로 평균 FPS보다 프레임 타임 안정성에 더 큰 영향
- 평균 FPS 수치 변화는 크지 않을 수 있음
- 프레임 드랍, stutter, hitch 현상이 감소
- 체감 성능과 실행 안정성이 증가
Changes
수정 사항
- Taskbar appearing in borderless fullscreen mode on Windows 11 tablet mode (not fully resolved, still in progress, further testing required)
- Restarting while in borderless fullscreen mode caused both borderless fullscreen to be disabled and a window attribute error
- Error when creating shortcut icons for titles containing multi-byte characters
- Error when the shortcut path includes multi-byte characters
- When launched via a shortcut with the fullscreen(-f) option, the main UI is hidden at startup and a separate start screen is immediately displayed to confirm execution
- 전체화면(보더리스)에서 Windows 11 태블릿 모드 작업표시줄 표시 문제 (아직 완벽하지 않음)
- 전체화면(보더리스)에서 재시작시 보더리스 전체화면 해제 및 창 속성 오류
- 멀티바이트 문자열이 포함된 바로가기 생성 오류
- 바로가기 생성 경로에 멀티바이트 문자가 포함될 경우 오류
- 전체화면(-f) 옵션이 포함된 바로가기 실행 시, 시작 시 메인 UI를 숨기고 실행 여부 확인을 위한 별도 시작 화면을 바로 표시
Notice
안내
- Current changes are incompatible with Eden's multi-platform direction, so they cannot be applied to the official build
- The borderless fullscreen issue is likely caused by differences in how Qt5 and Qt6 handle this feature
- Applying CS-PGO or LTO (fat/thin) causes runtime failures and is not recommended
- Use at your own risk
- 현재 수정 사항은 Eden의 방향성(멀티플랫폼)과 맞지 않아 공식 빌드에 적용 어려움
- 전체화면(보더리스) 문제는 Qt5와 Qt6의 렌더링 처리 방식 차이로 인한 것으로 추정
- CS-PGO 또는 LTO(fat/thin) 적용 시 런타임 오류가 발생하므로 권장하지 않음
- 사용에 따른 문제는 전적으로 사용자 책임입니다
Download
다운로드
Submission
참여
A PGO Collector build is also provided. Please send the .profraw file generated after a normal workload session for inclusion in the next build.
PGO Collector 버전도 같이 제공되고 있으니 해당 버전으로 정상 실행 세션 후 생성된 .profraw 파일을 보내주시면 빌드에 적용합니다.
License
라이센스
Eden is licensed under the GPLv3 (or any later version). Refer to the LICENSE.txt file.
Comments
Post a Comment