50 lines · plain
1; RUN: llc -mtriple=x86_64-- -O0 -pgo-kind=pgo-sample-use-pipeline -debug-pass=Structure %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=PASSES2; RUN: llc -mtriple=x86_64-- -O0 -pgo-kind=pgo-sample-use-pipeline -debug-only=branch-prob %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=BRANCH_PROB3; RUN: llc -mtriple=x86_64-- -O0 -pgo-kind=pgo-sample-use-pipeline -stop-after=finalize-isel %s -o - | FileCheck %s --check-prefix=MIR4 5; REQUIRES: asserts6 7; This test verifies that PGO profile information (branch weights) is preserved8; during instruction selection at -O0.9 10; Test function with explicit branch weights from PGO.11define i32 @test_pgo_preservation(i32 %x) !prof !15 {12entry:13 %cmp = icmp sgt i32 %x, 1014 ; This branch has bias: 97 taken vs 3 not taken15 br i1 %cmp, label %if.then, label %if.else, !prof !1616 17if.then:18 ; Hot path - should have high frequency19 %add = add nsw i32 %x, 10020 br label %if.end21 22if.else:23 ; Cold path - should have low frequency24 %sub = sub nsw i32 %x, 5025 br label %if.end26 27if.end:28 %result = phi i32 [ %add, %if.then ], [ %sub, %if.else ]29 ret i32 %result30}31 32; Profile metadata with branch weights 97:3.33!15 = !{!"function_entry_count", i64 100}34!16 = !{!"branch_weights", i32 97, i32 3}35 36; Verify that Branch Probability Analysis runs at O0.37; PASSES: Branch Probability Analysis38 39; Verify that the branch probabilities reflect the exact profile data.40; BRANCH_PROB: ---- Branch Probability Info : test_pgo_preservation ----41; BRANCH_PROB: set edge entry -> 0 successor probability to {{.*}} = 97.00%42; BRANCH_PROB: set edge entry -> 1 successor probability to {{.*}} = 3.00%43 44; Verify that machine IR preserves the branch probabilities from profile data45; MIR: bb.0.entry:46; MIR-NEXT: successors: %bb.{{[0-9]+}}({{0x03d70a3d|0x7c28f5c3}}), %bb.{{[0-9]+}}({{0x7c28f5c3|0x03d70a3d}})47; The two successor probability values should be:48; - 0x7c28f5c3: approximately 97% (high probability successor)49; - 0x03d70a3d: approximately 3% (low probability successor)50