From 1f655d71d9df4fc79545eba8667bdf24afa23792 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 30 Apr 2024 11:12:48 -0700 Subject: [PATCH] Add EarlyCSEPass before InstCombinePass (#1339) It prevents InstCombinePass from obfuscating MADs in some cases. --- lib/Compiler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Compiler.cpp b/lib/Compiler.cpp index 9345cec13..f1fe1e8db 100644 --- a/lib/Compiler.cpp +++ b/lib/Compiler.cpp @@ -39,6 +39,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/Scalar/DCE.h" +#include "llvm/Transforms/Scalar/EarlyCSE.h" #include "llvm/Transforms/Scalar/InferAddressSpaces.h" #include "llvm/Transforms/Scalar/SROA.h" #include "llvm/Transforms/Scalar/StructurizeCFG.h" @@ -590,6 +591,7 @@ int RunPassPipeline(llvm::Module &M, llvm::raw_svector_ostream *binaryStream) { // See https://github.com/google/clspv/issues/71 pm.addPass(clspv::HideConstantLoadsPass()); + pm.addPass(llvm::createModuleToFunctionPassAdaptor(llvm::EarlyCSEPass())); pm.addPass( llvm::createModuleToFunctionPassAdaptor(llvm::InstCombinePass()));