[llvm] 4c14735 - [LoopVectorize] Verify the function once per pass, not once per loop (#216448)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 18:11:16 PDT 2026


Author: Fangrui Song
Date: 2026-08-23T01:11:11Z
New Revision: 4c14735ebb08e10ad8c2e06c0f06f1b6cf6d91ed

URL: https://github.com/llvm/llvm-project/commit/4c14735ebb08e10ad8c2e06c0f06f1b6cf6d91ed
DIFF: https://github.com/llvm/llvm-project/commit/4c14735ebb08e10ad8c2e06c0f06f1b6cf6d91ed.diff

LOG: [LoopVectorize] Verify the function once per pass, not once per loop (#216448)

processLoop verifies the whole function once per vectorized loop, making
LoopVectorize quadratic in the number of loops per function on assertion
builds. In an `opt -O3` run the verifier accounts for 59% of the
instructions for a function with 800 vectorizable loops, and 5.6% for
SingleSource/Benchmarks/Linpack/linpack-pc.c.

Move the call to the end of runImpl. Assertion builds still verify what
LoopVectorize produces, but once per function instead of once per
vectorized loop, which costs 0.1-0.7% of the O3 run.

The call was added under DEBUG() in 2012 and became unconditional on
assertion builds in c9f63297e24a. 0aa75fb12faa hit the same problem in
SLPVectorizer and fixed it with EXPENSIVE_CHECKS (#48033).

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 24083eb7e8e6e..bae9fb9db902f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8370,7 +8370,6 @@ bool LoopVectorizePass::processLoop(Loop *L) {
 
   assert(DT->verify(DominatorTree::VerificationLevel::Fast) &&
          "DT not preserved correctly");
-  assert(!verifyFunction(*F, &dbgs()));
 
   return true;
 }
@@ -8437,6 +8436,11 @@ LoopVectorizeResult LoopVectorizePass::runImpl(Function &F) {
     }
   }
 
+  // Verify once per function rather than once per processed loop, which would
+  // make the pass quadratic in the number of loops.
+  assert((!Changed || !verifyFunction(F, &dbgs())) &&
+         "Invalid IR produced by LoopVectorize");
+
   // Process each loop nest in the function.
   return LoopVectorizeResult(Changed, CFGChanged);
 }


        


More information about the llvm-commits mailing list