[llvm] [LV] Tidy up early bail outs related to runtime checks (PR #228077)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 06:42:07 PDT 2026


https://github.com/david-arm created https://github.com/llvm/llvm-project/pull/228077

There was no debug or error reporting when bailing out due to proving at compile time that we will fail the SCEV checks. I've added debug and a report for this. Also, the early bail out for runtime memory checks has no corresponding test and I cannot find any test that breaks when I remove it. I also cannot expose this code path when building the LLVM test suite, so I've removed it as dead code.

>From d767f9334f5c8821ae207be948ea346bda90ef55 Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Thu, 1 Oct 2026 13:38:12 +0000
Subject: [PATCH] [LV] Tidy up early bail outs related to runtime checks

There was no debug or error reporting when bailing out due to
proving at compile time that we will fail the SCEV checks. I've
added debug and a report for this. Also, the early bail out for
runtime memory checks has no corresponding test and I cannot
find any test that breaks when I remove it. I also cannot
expose this code path when building the LLVM test suite, so I've
removed it as dead code.
---
 llvm/lib/Transforms/Vectorize/LoopVectorize.cpp        | 10 ++++++----
 .../AArch64/runtime-check-size-based-threshold.ll      |  6 +++++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 45edf702d70920f..c6edd933b17ffd4 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7953,11 +7953,13 @@ bool LoopVectorizePass::processLoop(Loop *L) {
       // fail. In that case, the vector loop would never execute.
       using namespace llvm::PatternMatch;
       if (Checks.getSCEVChecks().first &&
-          match(Checks.getSCEVChecks().first, m_One()))
-        return false;
-      if (Checks.getMemRuntimeChecks().first &&
-          match(Checks.getMemRuntimeChecks().first, m_One()))
+          match(Checks.getSCEVChecks().first, m_One())) {
+        reportVectorizationFailure(
+            "runtime checks are known to fail, so we will never enter the "
+            "vector loop",
+            "RuntimeChecksNeverEnterVectorLoop", ORE, L);
         return false;
+      }
     }
 
     // Check if it is profitable to vectorize with runtime checks.
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/runtime-check-size-based-threshold.ll b/llvm/test/Transforms/LoopVectorize/AArch64/runtime-check-size-based-threshold.ll
index 9ded4ccc2822cd6..df4750abd6b4ad5 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/runtime-check-size-based-threshold.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/runtime-check-size-based-threshold.ll
@@ -1,7 +1,9 @@
 ; RUN: opt -passes=loop-vectorize -mtriple=arm64-apple-iphoneos -vectorizer-min-trip-count=8 \
 ; RUN:   -enable-epilogue-vectorization=false -S %s | FileCheck --check-prefixes=CHECK,DEFAULT %s
 ; RUN: opt -passes=loop-vectorize -mtriple=arm64-apple-iphoneos -vectorizer-min-trip-count=8 \
-; RUN:   -enable-epilogue-vectorization=false -vectorize-memory-check-threshold=1 -S %s | FileCheck --check-prefixes=CHECK,THRESHOLD %s
+; RUN:   -enable-epilogue-vectorization=false -vectorize-memory-check-threshold=1 -S %s \
+; RUN:   -debug-only=loop-vectorize 2> %t | FileCheck --check-prefixes=CHECK,THRESHOLD %s
+; RUN: cat %t | FileCheck --check-prefix=DEBUG %s
 
 ; Tests for loops with large numbers of runtime checks. Check that loops are
 ; vectorized, if the loop trip counts are large and the impact of the runtime
@@ -12,6 +14,8 @@
 ; CHECK-LABEL: define {{.*}} @test_tc_too_small
 ; CHECK-NOT: vector.memcheck
 ; CHECK-NOT: vector.body
+; DEBUG-LABEL: Checking a loop in 'test_tc_too_small'
+; DEBUG: LV: Not vectorizing: runtime checks are known to fail, so we will never enter the vector loop.
 define void @test_tc_too_small(ptr %ptr.1, ptr %ptr.2, ptr %ptr.3, ptr %ptr.4, i64 %off.1, i64 %off.2) {
 entry:
   br label %loop



More information about the llvm-commits mailing list