diff --git a/llvm/bindings/go/llvm/executionengine_test.go b/llvm/bindings/go/llvm/executionengine_test.go --- a/llvm/bindings/go/llvm/executionengine_test.go +++ b/llvm/bindings/go/llvm/executionengine_test.go @@ -80,7 +80,6 @@ pass := NewPassManager() defer pass.Dispose() - pass.AddConstantPropagationPass() pass.AddInstructionCombiningPass() pass.AddPromoteMemoryToRegisterPass() pass.AddGVNPass() diff --git a/llvm/bindings/go/llvm/transforms_scalar.go b/llvm/bindings/go/llvm/transforms_scalar.go --- a/llvm/bindings/go/llvm/transforms_scalar.go +++ b/llvm/bindings/go/llvm/transforms_scalar.go @@ -40,6 +40,5 @@ } func (pm PassManager) AddSimplifyLibCallsPass() { C.LLVMAddSimplifyLibCallsPass(pm.C) } func (pm PassManager) AddTailCallEliminationPass() { C.LLVMAddTailCallEliminationPass(pm.C) } -func (pm PassManager) AddConstantPropagationPass() { C.LLVMAddConstantPropagationPass(pm.C) } func (pm PassManager) AddDemoteMemoryToRegisterPass() { C.LLVMAddDemoteMemoryToRegisterPass(pm.C) } func (pm PassManager) AddVerifierPass() { C.LLVMAddVerifierPass(pm.C) } diff --git a/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli b/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli --- a/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli +++ b/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli @@ -161,11 +161,6 @@ : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit = "llvm_add_tail_call_elimination" -(** See the [llvm::createConstantPropagationPass] function. *) -external add_constant_propagation - : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit - = "llvm_add_constant_propagation" - (** See the [llvm::createDemoteMemoryToRegisterPass] function. *) external add_memory_to_register_demotion : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit diff --git a/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c b/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c --- a/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c +++ b/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c @@ -200,12 +200,6 @@ return Val_unit; } -/* [ unit */ -CAMLprim value llvm_add_constant_propagation(LLVMPassManagerRef PM) { - LLVMAddConstantPropagationPass(PM); - return Val_unit; -} - /* [ unit */ CAMLprim value llvm_add_demote_memory_to_register(LLVMPassManagerRef PM) { LLVMAddDemoteMemoryToRegisterPass(PM); diff --git a/llvm/docs/CommandLine.rst b/llvm/docs/CommandLine.rst --- a/llvm/docs/CommandLine.rst +++ b/llvm/docs/CommandLine.rst @@ -475,7 +475,7 @@ Now that we have the standard run-of-the-mill argument types out of the way, lets get a little wild and crazy. Lets say that we want our optimizer to accept a **list** of optimizations to perform, allowing duplicates. For example, we -might want to run: "``compiler -dce -constprop -inline -dce -strip``". In this +might want to run: "``compiler -dce -instsimplify -inline -dce -strip``". In this case, the order of the arguments and the number of appearances is very important. This is what the "``cl::list``" template is for. First, start by defining an enum of the optimizations that you would like to perform: @@ -484,7 +484,7 @@ enum Opts { // 'inline' is a C++ keyword, so name it 'inlining' - dce, constprop, inlining, strip + dce, instsimplify, inlining, strip }; Then define your "``cl::list``" variable: @@ -494,7 +494,7 @@ cl::list OptimizationList(cl::desc("Available Optimizations:"), cl::values( clEnumVal(dce , "Dead Code Elimination"), - clEnumVal(constprop , "Constant Propagation"), + clEnumVal(instsimplify , "Instruction Simplification"), clEnumValN(inlining, "inline", "Procedure Integration"), clEnumVal(strip , "Strip Symbols"))); @@ -553,16 +553,16 @@ cl::bits OptimizationBits(cl::desc("Available Optimizations:"), cl::values( clEnumVal(dce , "Dead Code Elimination"), - clEnumVal(constprop , "Constant Propagation"), + clEnumVal(instsimplify , "Instruction Simplification"), clEnumValN(inlining, "inline", "Procedure Integration"), clEnumVal(strip , "Strip Symbols"))); -To test to see if ``constprop`` was specified, we can use the ``cl:bits::isSet`` +To test to see if ``instsimplify`` was specified, we can use the ``cl:bits::isSet`` function: .. code-block:: c++ - if (OptimizationBits.isSet(constprop)) { + if (OptimizationBits.isSet(instsimplify)) { ... } diff --git a/llvm/docs/Passes.rst b/llvm/docs/Passes.rst --- a/llvm/docs/Passes.rst +++ b/llvm/docs/Passes.rst @@ -460,27 +460,6 @@ string constants into the program, regardless of whether or not an existing string is available. -``-constprop``: Simple constant propagation -------------------------------------------- - -This pass implements constant propagation and merging. It looks for -instructions involving only constant operands and replaces them with a constant -value instead of an instruction. For example: - -.. code-block:: llvm - - add i32 1, 2 - -becomes - -.. code-block:: llvm - - i32 3 - -NOTE: this pass has a habit of making definitions be dead. It is a good idea -to run a :ref:`Dead Instruction Elimination ` pass sometime after -running this pass. - .. _passes-dce: ``-dce``: Dead Code Elimination diff --git a/llvm/include/llvm-c/Transforms/Scalar.h b/llvm/include/llvm-c/Transforms/Scalar.h --- a/llvm/include/llvm-c/Transforms/Scalar.h +++ b/llvm/include/llvm-c/Transforms/Scalar.h @@ -125,9 +125,6 @@ /** See llvm::createTailCallEliminationPass function. */ void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM); -/** See llvm::createConstantPropagationPass function. */ -void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM); - /** See llvm::demotePromoteMemoryToRegisterPass function. */ void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM); diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -113,7 +113,6 @@ void initializeCodeGenPreparePass(PassRegistry&); void initializeConstantHoistingLegacyPassPass(PassRegistry&); void initializeConstantMergeLegacyPassPass(PassRegistry&); -void initializeConstantPropagationPass(PassRegistry&); void initializeControlHeightReductionLegacyPassPass(PassRegistry&); void initializeCorrelatedValuePropagationPass(PassRegistry&); void initializeCostModelAnalysisPass(PassRegistry&); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -89,7 +89,6 @@ (void) llvm::createLibCallsShrinkWrapPass(); (void) llvm::createCalledValuePropagationPass(); (void) llvm::createConstantMergePass(); - (void) llvm::createConstantPropagationPass(); (void) llvm::createControlHeightReductionLegacyPass(); (void) llvm::createCostModelAnalysisPass(); (void) llvm::createDeadArgEliminationPass(); diff --git a/llvm/include/llvm/Transforms/Scalar.h b/llvm/include/llvm/Transforms/Scalar.h --- a/llvm/include/llvm/Transforms/Scalar.h +++ b/llvm/include/llvm/Transforms/Scalar.h @@ -24,12 +24,6 @@ class ModulePass; class Pass; -//===----------------------------------------------------------------------===// -// -// ConstantPropagation - A worklist driven constant propagation pass -// -FunctionPass *createConstantPropagationPass(); - //===----------------------------------------------------------------------===// // // AlignmentFromAssumptions - Use assume intrinsics to set load/store diff --git a/llvm/lib/Transforms/Scalar/CMakeLists.txt b/llvm/lib/Transforms/Scalar/CMakeLists.txt --- a/llvm/lib/Transforms/Scalar/CMakeLists.txt +++ b/llvm/lib/Transforms/Scalar/CMakeLists.txt @@ -4,7 +4,6 @@ BDCE.cpp CallSiteSplitting.cpp ConstantHoisting.cpp - ConstantProp.cpp CorrelatedValuePropagation.cpp DCE.cpp DeadStoreElimination.cpp diff --git a/llvm/lib/Transforms/Scalar/ConstantProp.cpp b/llvm/lib/Transforms/Scalar/ConstantProp.cpp deleted file mode 100644 --- a/llvm/lib/Transforms/Scalar/ConstantProp.cpp +++ /dev/null @@ -1,121 +0,0 @@ -//===- ConstantProp.cpp - Code to perform Simple Constant Propagation -----===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file implements constant propagation and merging: -// -// Specifically, this: -// * Converts instructions like "add int 1, 2" into 3 -// -// Notice that: -// * This pass has a habit of making definitions be dead. It is a good idea -// to run a DIE pass sometime after running this pass. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ADT/SmallPtrSet.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/Statistic.h" -#include "llvm/Analysis/ConstantFolding.h" -#include "llvm/Analysis/TargetLibraryInfo.h" -#include "llvm/IR/Constant.h" -#include "llvm/IR/InstIterator.h" -#include "llvm/IR/Instruction.h" -#include "llvm/InitializePasses.h" -#include "llvm/Pass.h" -#include "llvm/Support/DebugCounter.h" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Transforms/Utils/Local.h" -using namespace llvm; - -#define DEBUG_TYPE "constprop" - -STATISTIC(NumInstKilled, "Number of instructions killed"); -DEBUG_COUNTER(CPCounter, "constprop-transform", - "Controls which instructions are killed"); - -namespace { - struct ConstantPropagation : public FunctionPass { - static char ID; // Pass identification, replacement for typeid - ConstantPropagation() : FunctionPass(ID) { - initializeConstantPropagationPass(*PassRegistry::getPassRegistry()); - } - - bool runOnFunction(Function &F) override; - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesCFG(); - AU.addRequired(); - } - }; -} - -char ConstantPropagation::ID = 0; -INITIALIZE_PASS_BEGIN(ConstantPropagation, "constprop", - "Simple constant propagation", false, false) -INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) -INITIALIZE_PASS_END(ConstantPropagation, "constprop", - "Simple constant propagation", false, false) - -FunctionPass *llvm::createConstantPropagationPass() { - return new ConstantPropagation(); -} - -bool ConstantPropagation::runOnFunction(Function &F) { - if (skipFunction(F)) - return false; - - // Initialize the worklist to all of the instructions ready to process... - SmallPtrSet WorkList; - // The SmallVector of WorkList ensures that we do iteration at stable order. - // We use two containers rather than one SetVector, since remove is - // linear-time, and we don't care enough to remove from Vec. - SmallVector WorkListVec; - for (Instruction &I : instructions(&F)) { - WorkList.insert(&I); - WorkListVec.push_back(&I); - } - - bool Changed = false; - const DataLayout &DL = F.getParent()->getDataLayout(); - TargetLibraryInfo *TLI = - &getAnalysis().getTLI(F); - - while (!WorkList.empty()) { - SmallVector NewWorkListVec; - for (auto *I : WorkListVec) { - WorkList.erase(I); // Remove element from the worklist... - - if (!I->use_empty()) // Don't muck with dead instructions... - if (Constant *C = ConstantFoldInstruction(I, DL, TLI)) { - if (!DebugCounter::shouldExecute(CPCounter)) - continue; - - // Add all of the users of this instruction to the worklist, they might - // be constant propagatable now... - for (User *U : I->users()) { - // If user not in the set, then add it to the vector. - if (WorkList.insert(cast(U)).second) - NewWorkListVec.push_back(cast(U)); - } - - // Replace all of the uses of a variable with uses of the constant. - I->replaceAllUsesWith(C); - - if (isInstructionTriviallyDead(I, TLI)) { - I->eraseFromParent(); - ++NumInstKilled; - } - - // We made a change to the function... - Changed = true; - } - } - WorkListVec = std::move(NewWorkListVec); - } - return Changed; -} diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -38,7 +38,6 @@ initializeAlignmentFromAssumptionsPass(Registry); initializeCallSiteSplittingLegacyPassPass(Registry); initializeConstantHoistingLegacyPassPass(Registry); - initializeConstantPropagationPass(Registry); initializeCorrelatedValuePropagationPass(Registry); initializeDCELegacyPassPass(Registry); initializeDeadInstEliminationPass(Registry); @@ -248,10 +247,6 @@ unwrap(PM)->add(createTailCallEliminationPass()); } -void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) { - unwrap(PM)->add(createConstantPropagationPass()); -} - void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) { unwrap(PM)->add(createDemoteRegisterToMemoryPass()); } diff --git a/llvm/test/Assembler/2002-04-07-HexFloatConstants.ll b/llvm/test/Assembler/2002-04-07-HexFloatConstants.ll --- a/llvm/test/Assembler/2002-04-07-HexFloatConstants.ll +++ b/llvm/test/Assembler/2002-04-07-HexFloatConstants.ll @@ -5,8 +5,8 @@ ; of the bug that was causing the Olden Health benchmark to output incorrect ; results! ; -; RUN: opt -constprop -S > %t.1 < %s -; RUN: llvm-as < %s | llvm-dis | llvm-as | opt -constprop | \ +; RUN: opt -instsimplify -S > %t.1 < %s +; RUN: llvm-as < %s | llvm-dis | llvm-as | opt -instsimplify | \ ; RUN: llvm-dis > %t.2 ; RUN: diff %t.1 %t.2 ; RUN: verify-uselistorder %s diff --git a/llvm/test/Bitcode/extractelement.ll b/llvm/test/Bitcode/extractelement.ll --- a/llvm/test/Bitcode/extractelement.ll +++ b/llvm/test/Bitcode/extractelement.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -constprop | llvm-dis -disable-output +; RUN: opt < %s -instsimplify | llvm-dis -disable-output ; RUN: verify-uselistorder < %s ; PR3465 diff --git a/llvm/test/Other/2002-03-11-ConstPropCrash.ll b/llvm/test/Transforms/InstSimplify/ConstProp/2002-03-11-ConstPropCrash.ll rename from llvm/test/Other/2002-03-11-ConstPropCrash.ll rename to llvm/test/Transforms/InstSimplify/ConstProp/2002-03-11-ConstPropCrash.ll --- a/llvm/test/Other/2002-03-11-ConstPropCrash.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/2002-03-11-ConstPropCrash.ll @@ -5,7 +5,7 @@ ; ; Fixed by adding new arguments to ConstantFoldTerminator ; -; RUN: opt < %s -constprop +; RUN: opt < %s -instsimplify define void @build_tree(i32 %ml) { ;