[llvm] 09156b3 - [InstCombine] Move worklist preparation into InstCombinerImpl (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 31 06:18:21 PDT 2023
Author: Nikita Popov
Date: 2023-07-31T15:18:12+02:00
New Revision: 09156b36c65def7d1954e78b70408b4e743d417e
URL: https://github.com/llvm/llvm-project/commit/09156b36c65def7d1954e78b70408b4e743d417e
DIFF: https://github.com/llvm/llvm-project/commit/09156b36c65def7d1954e78b70408b4e743d417e.diff
LOG: [InstCombine] Move worklist preparation into InstCombinerImpl (NFC)
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 2ee293ba8ff990..16812467f4c427 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -16,6 +16,7 @@
#define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/TargetFolder.h"
#include "llvm/Analysis/ValueTracking.h"
@@ -73,6 +74,10 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
virtual ~InstCombinerImpl() = default;
+ /// Perform early cleanup and prepare the InstCombine worklist.
+ bool prepareWorklist(Function &F,
+ ReversePostOrderTraversal<BasicBlock *> &RPOT);
+
/// Run the combiner over the entire worklist until it is empty.
///
/// \returns true if the IR is changed.
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index c9e0865b200acd..d2915bcc8c37c4 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -36,7 +36,6 @@
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
@@ -4119,11 +4118,8 @@ class AliasScopeTracker {
/// them to the worklist (this significantly speeds up instcombine on code where
/// many instructions are dead or constant). Additionally, if we find a branch
/// whose condition is a known constant, we only visit the reachable successors.
-static bool
-prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
- const TargetLibraryInfo *TLI,
- InstructionWorklist &ICWorklist,
- ReversePostOrderTraversal<BasicBlock *> &RPOT) {
+bool InstCombinerImpl::prepareWorklist(
+ Function &F, ReversePostOrderTraversal<BasicBlock *> &RPOT) {
bool MadeIRChange = false;
SmallPtrSet<BasicBlock *, 32> LiveBlocks;
LiveBlocks.insert(&F.front());
@@ -4140,12 +4136,12 @@ prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
// ConstantProp instruction if trivially constant.
if (!Inst.use_empty() &&
(Inst.getNumOperands() == 0 || isa<Constant>(Inst.getOperand(0))))
- if (Constant *C = ConstantFoldInstruction(&Inst, DL, TLI)) {
+ if (Constant *C = ConstantFoldInstruction(&Inst, DL, &TLI)) {
LLVM_DEBUG(dbgs() << "IC: ConstFold to: " << *C << " from: " << Inst
<< '\n');
Inst.replaceAllUsesWith(C);
++NumConstProp;
- if (isInstructionTriviallyDead(&Inst, TLI))
+ if (isInstructionTriviallyDead(&Inst, &TLI))
Inst.eraseFromParent();
MadeIRChange = true;
continue;
@@ -4159,7 +4155,7 @@ prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
auto *C = cast<Constant>(U);
Constant *&FoldRes = FoldedConstants[C];
if (!FoldRes)
- FoldRes = ConstantFoldConstant(C, DL, TLI);
+ FoldRes = ConstantFoldConstant(C, DL, &TLI);
if (FoldRes != C) {
LLVM_DEBUG(dbgs() << "IC: ConstFold operand of: " << Inst
@@ -4227,11 +4223,11 @@ prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
// of the function down. This jives well with the way that it adds all uses
// of instructions to the worklist after doing a transformation, thus avoiding
// some N^2 behavior in pathological cases.
- ICWorklist.reserve(InstrsForInstructionWorklist.size());
+ Worklist.reserve(InstrsForInstructionWorklist.size());
for (Instruction *Inst : reverse(InstrsForInstructionWorklist)) {
// DCE instruction if trivially dead. As we iterate in reverse program
// order here, we will clean up whole chains of dead instructions.
- if (isInstructionTriviallyDead(Inst, TLI) ||
+ if (isInstructionTriviallyDead(Inst, &TLI) ||
SeenAliasScopes.isNoAliasScopeDeclDead(Inst)) {
++NumDeadInst;
LLVM_DEBUG(dbgs() << "IC: DCE: " << *Inst << '\n');
@@ -4241,7 +4237,7 @@ prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
continue;
}
- ICWorklist.push(Inst);
+ Worklist.push(Inst);
}
return MadeIRChange;
@@ -4289,12 +4285,10 @@ static bool combineInstructionsOverFunction(
LLVM_DEBUG(dbgs() << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
<< F.getName() << "\n");
- bool MadeChangeInThisIteration =
- prepareICWorklistFromFunction(F, DL, &TLI, Worklist, RPOT);
-
InstCombinerImpl IC(Worklist, Builder, F.hasMinSize(), AA, AC, TLI, TTI, DT,
ORE, BFI, PSI, DL, LI);
IC.MaxArraySizeForCombine = MaxArraySize;
+ bool MadeChangeInThisIteration = IC.prepareWorklist(F, RPOT);
MadeChangeInThisIteration |= IC.run();
if (!MadeChangeInThisIteration)
break;
More information about the llvm-commits
mailing list