[clang] [flang] [llvm] Fix/172049 loop vectorize sigfpe (PR #172094)

Priyanshu Singh via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 14 11:10:21 PST 2025


================
@@ -2907,6 +2907,10 @@ uint64_t LoopVectorizationCostModel::getPredBlockCostDivisor(
   uint64_t BBFreq = getBFI().getBlockFreq(BB).getFrequency();
   assert(HeaderFreq >= BBFreq &&
          "Header has smaller block freq than dominated BB?");
+  // Guard against division by zero when BBFreq is 0.
+  // In such cases, return 1 to avoid undefined behavior.
+  if (BBFreq == 0)
----------------
dev-priyanshu15 wrote:

Thanks for the feedback. I've added the assert as you suggested:

assert(BBFreq != 0 && "BlockFrequencyInfo should never return zero frequency");

This validates your point that BlockFrequencyInfo should never return a zero frequency. If the assert fails, it will help identify the root cause of the issue.

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


More information about the llvm-commits mailing list