Running opt O1 outside of llvm

Hi,
I would like to run the -O1 pass sequence followed by -reg2mem from an out of tree project which uses llvm.
I am using the following code snippet to do so but in some cases, my method is also vectorising the code, which doesn’t happen when running the same sequence(-S -O1 -reg2mem) through opt. Can someone please help me find what I am missing?

Thanks,
Akash.

PassManagerBuilder PM;
PM.OptLevel = 1;
PM.SizeLevel = 0;
legacy::FunctionPassManager FPM(&llvm_module);
legacy::PassManager MPM;
PM.Inliner = createAlwaysInlinerLegacyPass();
PM.DisableUnrollLoops = true;
PM.populateFunctionPassManager(FPM);
PM.populateModulePassManager(MPM);
FPM.doInitialization();
for (auto &F : llvm_module)
FPM.run(F);
FPM.doFinalization();
MPM.run(llvm_module);
legacy::FunctionPassManager FPM(&llvm_module);
FPM.add(createDemoteRegisterToMemoryPass());
FPM.doInitialization();
for (auto &F : llvm_module)
FPM.run(F);
FPM.doFinalization();

It would be helpful to know in which cases your custom pipeline
vectorizes when it should not.
Note this might be dependent on target-specifics, such as
PMB.LibraryInfo tjat your code below is not using.

Michael

Hi,
I have since fixed it. I was missing setting the following two flags to false.

PM.LoopVectorize = false;
PM.SLPVectorize = false;

Thanks,
Akash.