Skip to content

Commit 2555fce

Browse files
committed
Add function reference as a member of the InstCombiner class and simplify createSelectInst(...)
1 parent 9764b21 commit 2555fce

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
6464
/// A worklist of the instructions that need to be simplified.
6565
InstructionWorklist &Worklist;
6666

67+
Function &F;
68+
6769
// Mode in which we are running the combiner.
6870
const bool MinimizeSize;
6971

@@ -98,17 +100,17 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
98100
bool ComputedBackEdges = false;
99101

100102
public:
101-
InstCombiner(InstructionWorklist &Worklist, BuilderTy &Builder,
102-
bool MinimizeSize, AAResults *AA, AssumptionCache &AC,
103-
TargetLibraryInfo &TLI, TargetTransformInfo &TTI,
104-
DominatorTree &DT, OptimizationRemarkEmitter &ORE,
105-
BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI,
106-
ProfileSummaryInfo *PSI, const DataLayout &DL,
103+
InstCombiner(InstructionWorklist &Worklist, BuilderTy &Builder, Function &F,
104+
AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI,
105+
TargetTransformInfo &TTI, DominatorTree &DT,
106+
OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
107+
BranchProbabilityInfo *BPI, ProfileSummaryInfo *PSI,
108+
const DataLayout &DL,
107109
ReversePostOrderTraversal<BasicBlock *> &RPOT)
108110
: TTIForTargetIntrinsicsOnly(TTI), Builder(Builder), Worklist(Worklist),
109-
MinimizeSize(MinimizeSize), AA(AA), AC(AC), TLI(TLI), DT(DT), DL(DL),
110-
SQ(DL, &TLI, &DT, &AC, nullptr, /*UseInstrInfo*/ true,
111-
/*CanUseUndef*/ true, &DC),
111+
F(F), MinimizeSize(F.hasMinSize()), AA(AA), AC(AC), TLI(TLI), DT(DT),
112+
DL(DL), SQ(DL, &TLI, &DT, &AC, nullptr, /*UseInstrInfo*/ true,
113+
/*CanUseUndef*/ true, &DC),
112114
ORE(ORE), BFI(BFI), BPI(BPI), PSI(PSI), RPOT(RPOT) {}
113115

114116
virtual ~InstCombiner() = default;

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,13 +882,11 @@ Instruction *InstCombinerImpl::foldAddWithConstant(BinaryOperator &Add) {
882882
SelectInst *SI = nullptr;
883883
if (match(Op0, m_ZExt(m_Value(X))) &&
884884
X->getType()->getScalarSizeInBits() == 1)
885-
SI = createSelectInstMaybeWithUnknownBranchWeights(
886-
X, InstCombiner::AddOne(Op1C), Op1, Add.getFunction());
885+
SI = createSelectInst(X, InstCombiner::AddOne(Op1C), Op1);
887886
// sext(bool) + C -> bool ? C - 1 : C
888887
if (!SI && match(Op0, m_SExt(m_Value(X))) &&
889888
X->getType()->getScalarSizeInBits() == 1)
890-
SI = createSelectInstMaybeWithUnknownBranchWeights(
891-
X, InstCombiner::SubOne(Op1C), Op1, Add.getFunction());
889+
SI = createSelectInst(X, InstCombiner::SubOne(Op1C), Op1);
892890
if (SI) {
893891
return SI;
894892
}

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
6363
public InstVisitor<InstCombinerImpl, Instruction *> {
6464
public:
6565
InstCombinerImpl(InstructionWorklist &Worklist, BuilderTy &Builder,
66-
bool MinimizeSize, AAResults *AA, AssumptionCache &AC,
66+
Function &F, AAResults *AA, AssumptionCache &AC,
6767
TargetLibraryInfo &TLI, TargetTransformInfo &TTI,
6868
DominatorTree &DT, OptimizationRemarkEmitter &ORE,
6969
BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI,
7070
ProfileSummaryInfo *PSI, const DataLayout &DL,
7171
ReversePostOrderTraversal<BasicBlock *> &RPOT)
72-
: InstCombiner(Worklist, Builder, MinimizeSize, AA, AC, TLI, TTI, DT, ORE,
73-
BFI, BPI, PSI, DL, RPOT) {}
72+
: InstCombiner(Worklist, Builder, F, AA, AC, TLI, TTI, DT, ORE, BFI, BPI,
73+
PSI, DL, RPOT) {}
7474

7575
virtual ~InstCombinerImpl() = default;
7676

@@ -470,14 +470,14 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
470470
Value *simplifyNonNullOperand(Value *V, bool HasDereferenceable,
471471
unsigned Depth = 0);
472472

473-
static SelectInst *createSelectInstMaybeWithUnknownBranchWeights(
474-
Value *C, Value *S1, Value *S2, Function *F, const Twine &NameStr = "",
475-
InsertPosition InsertBefore = nullptr, Instruction *MDFrom = nullptr) {
473+
SelectInst *createSelectInst(Value *C, Value *S1, Value *S2,
474+
const Twine &NameStr = "",
475+
InsertPosition InsertBefore = nullptr,
476+
Instruction *MDFrom = nullptr) {
476477
SelectInst *SI =
477478
SelectInst::Create(C, S1, S2, NameStr, InsertBefore, MDFrom);
478479
if (SI && !MDFrom) {
479-
assert(F && "provided parent function is nullptr!");
480-
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, *F, DEBUG_TYPE);
480+
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, F, DEBUG_TYPE);
481481
}
482482
return SI;
483483
}

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,7 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
12541254
// shl (zext i1 X), C1 --> select (X, 1 << C1, 0)
12551255
if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
12561256
auto *NewC = Builder.CreateShl(ConstantInt::get(Ty, 1), C1);
1257-
return createSelectInstMaybeWithUnknownBranchWeights(
1258-
X, NewC, ConstantInt::getNullValue(Ty), I.getFunction());
1257+
return createSelectInst(X, NewC, ConstantInt::getNullValue(Ty));
12591258
}
12601259
}
12611260

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
#include "llvm/IR/Operator.h"
8282
#include "llvm/IR/PassManager.h"
8383
#include "llvm/IR/PatternMatch.h"
84-
#include "llvm/IR/ProfDataUtils.h"
8584
#include "llvm/IR/Type.h"
8685
#include "llvm/IR/Use.h"
8786
#include "llvm/IR/User.h"
@@ -1736,8 +1735,7 @@ Instruction *InstCombinerImpl::foldBinopOfSextBoolToSelect(BinaryOperator &BO) {
17361735
Constant *Zero = ConstantInt::getNullValue(BO.getType());
17371736
Value *TVal = Builder.CreateBinOp(BO.getOpcode(), Ones, C);
17381737
Value *FVal = Builder.CreateBinOp(BO.getOpcode(), Zero, C);
1739-
return createSelectInstMaybeWithUnknownBranchWeights(X, TVal, FVal,
1740-
BO.getFunction());
1738+
return createSelectInst(X, TVal, FVal);
17411739
}
17421740

17431741
static Value *simplifyOperationIntoSelectOperand(Instruction &I, SelectInst *SI,
@@ -5936,8 +5934,8 @@ static bool combineInstructionsOverFunction(
59365934
LLVM_DEBUG(dbgs() << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
59375935
<< F.getName() << "\n");
59385936

5939-
InstCombinerImpl IC(Worklist, Builder, F.hasMinSize(), AA, AC, TLI, TTI, DT,
5940-
ORE, BFI, BPI, PSI, DL, RPOT);
5937+
InstCombinerImpl IC(Worklist, Builder, F, AA, AC, TLI, TTI, DT, ORE, BFI,
5938+
BPI, PSI, DL, RPOT);
59415939
IC.MaxArraySizeForCombine = MaxArraySize;
59425940
bool MadeChangeInThisIteration = IC.prepareWorklist(F);
59435941
MadeChangeInThisIteration |= IC.run();

0 commit comments

Comments
 (0)