[llvm-commits] [RFC] Unrolling again after BBVectorize

Hal Finkel hfinkel at anl.gov
Tue Dec 11 12:33:40 PST 2012


Basic-block vectorization is run after loop unrolling (because loop unrolling is a primary provider of vectorizable basic blocks). Especially when partial and/or runtime unrolling is enabled, this leads to some suboptimal behavior after the loop bodies are vectorized. Because the vectorized loop bodies are often much shorter than the original loop bodies, the loop unroller would unroll them again if it were run. If the function is later inlined, this happens in the inlined copy, but the loop in the original function remains unusually short. A seemingly straightforward way to fix this would be to add this:

--- a/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ b/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -216,6 +216,11 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
       MPM.add(createGVNPass());                   // Remove redundancies
     else
       MPM.add(createEarlyCSEPass());              // Catch trivial redundancies
+
+    // When using runtime and/or partial unrolling, BBVectorize may have
+    // significantly shortened a loop body; unroll again.
+    if (!DisableUnrollLoops)
+      MPM.add(createLoopUnrollPass());
   }
 
   MPM.add(createAggressiveDCEPass());         // Delete dead instructions

One potential problem with this is that addExtensionsToPM(EP_LoopOptimizerEnd, MPM); is called after the original place where the loop unroller is scheduled. When vectorization is enabled, should I move this call to after the bb-vectorizer runs?

Thanks again,
Hal

-- 
Hal Finkel
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list