<div dir="ltr">Yes, cl::opt<bool> defaults to false when there's no init. Changing the default will affect non-LTO too. This may be the right thing to do, but isn't my call. Turning it on only for LTO sounds better IMO, but I'm not sure what you're suggesting: I think there shouldn't be a vectorization flags that are different for LTO and for non-LTO.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 24, 2014 at 8:57 AM, Arnold Schwaighofer <span dir="ltr"><<a href="mailto:aschwaighofer@apple.com" target="_blank">aschwaighofer@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">JF are you sure that “LoopVectorize” is set to true by default by the PassManager instance of libLTO?<br>
<br>
The reason why I forced these parameters to true is that this is not the case if I remember correctly.<br>
<br>
We wanted the default for libLTO to be with vectorization.<br>
<br>
PassManager.cpp:<br>
<br>
static cl::opt<bool><br>
RunLoopVectorization("vectorize-loops", cl::Hidden,<br>
                     cl::desc("Run the Loop vectorization passes"));<br>
<br>
PassManagerBuilder::PassManagerBuilder() {<br>
    OptLevel = 2;<br>
    SizeLevel = 0;<br>
    LibraryInfo = nullptr;<br>
    Inliner = nullptr;<br>
    DisableTailCalls = false;<br>
    DisableUnitAtATime = false;<br>
    DisableUnrollLoops = false;<br>
    BBVectorize = RunBBVectorization;<br>
    SLPVectorize = RunSLPVectorization;<br>
    LoopVectorize = RunLoopVectorization;<br>
    RerollLoops = RunLoopRerolling;<br>
    LoadCombine = RunLoadCombine;<br>
    DisableGVNLoadPRE = false;<br>
    VerifyInput = false;<br>
    VerifyOutput = false;<br>
    StripDebug = false;<br>
    MergeFunctions = false;<br>
}<br>
<br>
LTOCodeGenerator.cpp:<br>
<br>
/// Optimize merged modules using various IPO passes<br>
bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,<br>
                                          bool DisableOpt,<br>
                                          bool DisableInline,<br>
                                          bool DisableGVNLoadPRE,<br>
                                          std::string &errMsg) {<br>
  if (!this->determineTarget(errMsg))<br>
    return false;<br>
<br>
  Module *mergedModule = IRLinker.getModule();<br>
<br>
  // Mark which symbols can not be internalized<br>
  this->applyScopeRestrictions();<br>
<br>
  // Instantiate the pass manager to organize the passes.<br>
  PassManager passes;<br>
<br>
  // Add an appropriate DataLayout instance for this module...<br>
  mergedModule->setDataLayout(TargetMach->getSubtargetImpl()->getDataLayout());<br>
<br>
  Triple TargetTriple(TargetMach->getTargetTriple());<br>
  PassManagerBuilder PMB;<br>
  PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;<br>
  if (!DisableInline)<br>
    PMB.Inliner = createFunctionInliningPass();<br>
  PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple);<br>
  if (DisableOpt)<br>
    PMB.OptLevel = 0;<br>
  PMB.VerifyInput = true;<br>
  PMB.VerifyOutput = true;<br>
<br>
  PMB.populateLTOPassManager(passes, TargetMach);<br>
<br>
<br>
<br>
I think cl::opt<bool> defaults to false and your commit effectively disabled vectorization during LTO. We can recover this by changing the default cl::opt flags 'vectorize-loops’ and 'vectorize-slp'  to true. If that does not work (because we make assumption somewhere about the default being false) we can follow the example of “DisableGVNLoadPRE” in LTOCodeGenerator.cpp and a a flag to disable Vectorization during LTO and pass that to the PassManager created in generateObjectFile.<br>
<br>
  PMB.LoopVectorize = !DisableLTOVectorization;<br>
<br>
<br>
Thanks,<br>
Arnold<br>
<br>
> DisableUnrollLoops<br>
<div class="HOEnZb"><div class="h5">> On Oct 24, 2014, at 5:27 AM, Alexey Volkov <<a href="mailto:avolkov.intel@gmail.com">avolkov.intel@gmail.com</a>> wrote:<br>
><br>
> Hi JF,<br>
><br>
> After your commit I saw a performance regression because of disabled Loop Vectorizer:<br>
>  LV: Not vectorizing: No #pragma vectorize enable.<br>
> It is really strange since I used -Ofast -flto clang's options to build an application.<br>
> Before this change loop was successfully vectorized by Loop Vectorizer.<br>
><br>
> Thanks, Alexey.<br>
><br>
> 2014-10-22 3:18 GMT+04:00 JF Bastien <<a href="mailto:jfb@google.com">jfb@google.com</a>>:<br>
> Author: jfb<br>
> Date: Tue Oct 21 18:18:21 2014<br>
> New Revision: 220345<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=220345&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=220345&view=rev</a><br>
> Log:<br>
> LTO: respect command-line options that disable vectorization.<br>
><br>
> Summary: Patches 202051 and 208013 added calls to LTO's PassManager which unconditionally add LoopVectorizePass and SLPVectorizerPass instead of following the logic in PassManagerBuilder::populateModulePassManager and honoring the -vectorize-loops -run-slp-after-loop-vectorization flags.<br>
><br>
> Reviewers: nadav, aschwaighofer, yijiang<br>
><br>
> Subscribers: llvm-commits<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D5884" target="_blank">http://reviews.llvm.org/D5884</a><br>
><br>
> Modified:<br>
>     llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp<br>
><br>
> Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=220345&r1=220344&r2=220345&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=220345&r1=220344&r2=220345&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Tue Oct 21 18:18:21 2014<br>
> @@ -440,10 +440,12 @@ void PassManagerBuilder::addLTOOptimizat<br>
>    // More loops are countable; try to optimize them.<br>
>    PM.add(createIndVarSimplifyPass());<br>
>    PM.add(createLoopDeletionPass());<br>
> -  PM.add(createLoopVectorizePass(true, true));<br>
> +  PM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));<br>
><br>
>    // More scalar chains could be vectorized due to more alias information<br>
> -  PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.<br>
> +  if (RunSLPAfterLoopVectorization)<br>
> +    if (SLPVectorize)<br>
> +      PM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.<br>
><br>
>    // After vectorization, assume intrinsics may tell us more about pointer<br>
>    // alignments.<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
><br>
><br>
> --<br>
> Alexey Volkov<br>
> Intel Corporation<br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></blockquote></div><br></div>