[llvm] [NewPM] Don't preserve BlockFrequencyInfo in FunctionToLoopPassAdaptor (PR #157888)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 15 02:32:02 PDT 2025


lukel97 wrote:

> Could you add a testcase showing the incorrect results when followed by the LoopVectorizer?

This mostly causes incorrect results in an upcoming patch where I'm trying to use BFI more in the LoopVectorizer cost model. The smallest reproducer I have so far is with `opt -p 'lto<O3>':

```llvm
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"

define void @_Z22SetupPrecalculatedDatav(ptr readonly captures(none) %KingSafetyMask, ptr writeonly captures(none) initializes((0, 8)) %Mask, i1 %0) local_unnamed_addr #0 !prof !0 {
  br label %2

2:                                                ; preds = %5, %1
  %.pre = load i64, ptr %KingSafetyMask, align 8
  br label %3

3:                                                ; preds = %3, %2
  %4 = phi i1 [ false, %2 ], [ true, %3 ]
  store i64 %.pre, ptr %Mask, align 8
  br i1 %4, label %5, label %3

5:                                                ; preds = %3
  br i1 %0, label %6, label %2

6:                                                ; preds = %5
  ret void
}

attributes #0 = { "target-features"="+v" }

!0 = !{!"function_entry_count", i64 1}
```

This doesn't crash today but if you add this assert that the BFI is accurate for the loops that the loop vectorizer processes, it fails:

```c++
    // Stick this somewhere in LoopVectorizePass::runImpl
    if (!L->isInvalid() && L->isInnermost() && !L->hasNoExitBlocks())
      for (BasicBlock *BB : L->blocks())
        assert(BFI->getBlockFreq(L->getHeader()) >= BFI->getBlockFreq(BB))
```

I'll try and see if I can get a test case with `print<block-freq>`. So far I've had no luck since I can't seem to trigger the assertion when manually specifying the pipeline with the output of `print-pipeline-passes`, i.e. it seems to need `-p 'lto<O3>'`

https://github.com/llvm/llvm-project/pull/157888


More information about the llvm-commits mailing list