A pseudo probe is implemented as a dedicated intrinsic call with the IntrInaccessibleMemOnly attribute which intentionally blocks optimizations which merges code for better counts quality but i’ve noticed it also accidentally blocks few seemingly not so harmful optimizations like Loop Vectorization of loops with early exits and LoopChain. I wanted to ask the following :
→ Is it worthwhile to systematically find such accidentally-blocked optimizations and unblock them?
→ I understand transformations that merge or delete blocks degrade profile quality – are there other transformation classes that degrade pseudo-probe profile quality?
→ What’s the recommended way to measure the impact of such a change – are there preferred benchmarks?
Test Case :
; RUN: opt -S < %s -p pseudo-probe,loop-vectorize -debug-only=loop-vectorize -force-vector-width=4 -disable-output 2>&1 | FileCheck %s
declare void @init_mem(ptr, i64);
define i64 @loop_contains_safe_div() {
; CHECK-LABEL: LV: Checking a loop in ‘loop_contains_safe_div’
; CHECK: LV: Found an early exit loop with symbolic max backedge taken count: 63
; CHECK-NEXT: LV: We can vectorize this loop!
entry: %p1 = alloca [1024 x i8]
%p2 = alloca [1024 x i8]
call void @init_mem(ptr %p1, i64 1024)
call void @init_mem(ptr %p2, i64 1024)
br label %loop
loop:
%index = phi i64 [ %index.next, %loop.inc ], [ 3, %entry ]
%arrayidx = getelementptr inbounds i32, ptr %p1, i64 %index
%ld1 = load i32, ptr %arrayidx, align 1
%div = udiv i32 %ld1, 20000
%cmp = icmp eq i32 %div, 1
br i1 %cmp, label %loop.inc, label %loop.end
loop.inc:
%index.next = add i64 %index, 1
%exitcond = icmp ne i64 %index.next, 67
br i1 %exitcond, label %loop, label %loop.end
loop.end:
%retval = phi i64 [ %index, %loop ], [ 67, %loop.inc ]
ret i64 %retval
}
Output
LV: Checking a loop in ‘loop_contains_safe_div’ from
LV: Loop hints: force=? width=4 interleave=0
LV: Found a loop: loop
LV: Found an induction variable.
LV: Did not find one integer induction var.
LV: Not vectorizing: Writes to memory unsupported in early exit loops.
LV: Interleaving disabled by the pass manager
remark: :0:0: loop not vectorized: Cannot vectorize early exit loop with writes to memory
LV: Not vectorizing: Cannot prove legality.
Same loop vectorizes if we remove pseudo-probe optimization in the run line i.e.
opt -S < %s -p loop-vectorize -debug-only=loop-vectorize -force-vector-width=4 -disable-output 2>&1 | FileCheck %s