Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1440,6 +1440,12 @@ Conf.OptLevel = CGOpts.OptimizationLevel; initTargetOptions(Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts); Conf.SampleProfile = std::move(SampleProfile); + Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops; + // For historical reasons, loop interleaving is set to mirror setting for loop + // unrolling. + Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops; + Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop; + Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP; // Context sensitive profile. if (CGOpts.hasProfileCSIRInstr()) { Index: clang/test/CodeGen/thinlto-debug-pm.c =================================================================== --- clang/test/CodeGen/thinlto-debug-pm.c +++ clang/test/CodeGen/thinlto-debug-pm.c @@ -13,5 +13,16 @@ // O2-OLDPM: Loop Vectorization // O0-OLDPM-NOT: Loop Vectorization +// Test to ensure the SLP flag is passed down to the ThinLTO backend. +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -vectorize-slp +// -mllvm -vectorize-slp=false -mllvm -vectorize-loops=false -o %t2.o -x ir %t.o +// -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager +// -fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O2-SLP +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -vectorize-slp +// -o %t2.o -x ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager +// -fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O0-SLP +// O2-SLP: Running pass: SLPVectorizerPass +// O0-SLP-NOT: Running pass: SLPVectorizerPass + void foo() { } Index: llvm/include/llvm/LTO/Config.h =================================================================== --- llvm/include/llvm/LTO/Config.h +++ llvm/include/llvm/LTO/Config.h @@ -16,6 +16,7 @@ #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/Passes/PassBuilder.h" #include "llvm/Support/CodeGen.h" #include "llvm/Target/TargetOptions.h" @@ -126,6 +127,8 @@ /// with llvm-lto2. std::unique_ptr ResolutionFile; + PipelineTuningOptions PTO; + /// The following callbacks deal with tasks, which normally represent the /// entire optimization and code generation pipeline for what will become a /// single native object file. Each task has a unique identifier between 0 and Index: llvm/lib/LTO/LTOBackend.cpp =================================================================== --- llvm/lib/LTO/LTOBackend.cpp +++ llvm/lib/LTO/LTOBackend.cpp @@ -169,7 +169,7 @@ PassInstrumentationCallbacks PIC; StandardInstrumentations SI; SI.registerCallbacks(PIC); - PassBuilder PB(TM, PipelineTuningOptions(),PGOOpt, &PIC); + PassBuilder PB(TM, Conf.PTO, PGOOpt, &PIC); AAManager AA; // Parse a custom AA pipeline if asked to. Index: llvm/tools/llvm-lto2/CMakeLists.txt =================================================================== --- llvm/tools/llvm-lto2/CMakeLists.txt +++ llvm/tools/llvm-lto2/CMakeLists.txt @@ -9,6 +9,7 @@ LTO MC Object + Passes Support Target )