[llvm] [VPlan] Compute scalar cost based on VPlan0 instead of legacy CM. (PR #196845)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 10:52:20 PDT 2026
https://github.com/lukel97 commented:
It looks like branches that never get executed end up losing their scalar cost divisor in this PR. E.g. with `opt -passes=loop-vectorize -mattr=+avx2` the scalar vplan cost goes from 4 -> 30, so the VF goes from VF 1 -> VF 8:
```llvm
define void @never_taken(ptr noalias %a, ptr noalias %b, i64 %n) {
entry:
br label %loop
loop:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
%gep.a = getelementptr inbounds i32, ptr %a, i64 %iv
%l = load i32, ptr %gep.a, align 4
%c = icmp sgt i32 %l, 0
br i1 %c, label %then, label %latch, !prof !0
then:
%d = sdiv i32 1000, %l
%gep.b = getelementptr inbounds i32, ptr %b, i64 %iv
store i32 %d, ptr %gep.b, align 4
br label %latch
latch:
%iv.next = add nuw nsw i64 %iv, 1
%ec = icmp eq i64 %iv.next, %n
br i1 %ec, label %exit, label %loop
exit:
ret void
}
!0 = !{!"branch_weights", i32 0, i32 1000}
```
I think this is related to the previous PRs that handled setExecutionFrequency?
https://github.com/llvm/llvm-project/pull/196845
More information about the llvm-commits
mailing list