[llvm] [NewPM] Don't preserve BlockFrequencyInfo in FunctionToLoopPassAdaptor (PR #157888)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 15 10:39:25 PDT 2025
lukel97 wrote:
@alinas @aeubanks I gave this a try, but unfortunately I don't think it's (easily) possible to add a test which shows any difference in LoopVectorizer behaviour today. LoopVectorizer currently only uses BFI to check if it's optimizing for size, but it's very difficult to recreate the conditions to trigger this in combination with the loop simplifications needed to trigger the invalid BFI state.
Also to recreate this `UseBlockFrequencyInfo` needs to be set to true in `createFunctionToLoopPassAdaptor`, but we only do this with the LTO pipelines in e.g. `buildLTODefaultPipeline`, so AFAICT we can't do 'print<block-freq>'.
I've instead posted the motivating LoopVectorizer patch which includes a test that crashes without this fix: https://github.com/llvm/llvm-project/pull/158690/files#diff-a388af039904a990257f3235bf23eb5271c54ea5a31f916b760b36143d937d81
Specifically, it crashes because the BFI results are inaccurate: The loop header will have a lower frequency than one of the blocks it dominates, which causes a divide by zero when calculating the probability. I hope this illustrates the problem a bit better.
https://github.com/llvm/llvm-project/pull/157888
More information about the llvm-commits
mailing list