From 113133f179fd98f34845b27cd55ce357f87eb8c6 Mon Sep 17 00:00:00 2001 From: Logan Date: Wed, 11 Nov 2026 15:00:55 -0800 Subject: [PATCH] GH: Gandiva: drop redundant duplicate GVN and LoopVectorize passes The custom pass list added before the O3 default pipeline ran two global value numbering passes back to back (the legacy GVNPass and NewGVNPass) and an extra LoopVectorizePass. NewGVN subsumes the legacy GVN, and SLPVectorizer together with the O3 default pipeline's own vectorization already cover vectorization, so the duplicate GVN and the extra LoopVectorize are wasted compile time. Drop both in the new and legacy pass-manager paths. Generated code is unchanged (the surviving passes cover the same optimizations); only compile time drops (~8-12% on uncached compiles in local measurement). --- cpp/src/gandiva/engine.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cpp/src/gandiva/engine.cc b/cpp/src/gandiva/engine.cc index c868f059acb..51199f7f398 100644 --- a/cpp/src/gandiva/engine.cc +++ b/cpp/src/gandiva/engine.cc @@ -530,10 +530,11 @@ static void OptimizeModuleWithNewPassManager(llvm::Module& module, llvm::FunctionPassManager function_pm; function_pm.addPass(llvm::InstCombinePass()); function_pm.addPass(llvm::PromotePass()); - function_pm.addPass(llvm::GVNPass()); + // NewGVN subsumes the legacy GVN; running both back to back just repeats the + // analysis. SLPVectorizer plus the O3 default pipeline's own loop vectorization + // cover vectorization, so the extra LoopVectorizePass here is redundant too. function_pm.addPass(llvm::NewGVNPass()); function_pm.addPass(llvm::SimplifyCFGPass()); - function_pm.addPass(llvm::LoopVectorizePass()); function_pm.addPass(llvm::SLPVectorizerPass()); module_pm.addPass(llvm::createModuleToFunctionPassAdaptor(std::move(function_pm))); @@ -554,10 +555,10 @@ static void OptimizeModuleWithLegacyPassManager(llvm::Module& module, pass_manager->add(llvm::createFunctionInliningPass()); pass_manager->add(llvm::createInstructionCombiningPass()); pass_manager->add(llvm::createPromoteMemoryToRegisterPass()); - pass_manager->add(llvm::createGVNPass()); + // NewGVN subsumes the legacy GVN, and SLPVectorizer plus the O3 pipeline cover + // vectorization, so the duplicate GVN and LoopVectorize passes are dropped. pass_manager->add(llvm::createNewGVNPass()); pass_manager->add(llvm::createCFGSimplificationPass()); - pass_manager->add(llvm::createLoopVectorizePass()); pass_manager->add(llvm::createSLPVectorizerPass()); pass_manager->add(llvm::createGlobalOptimizerPass());