Skip to content

Commit 2819126

Browse files
committed
[SLP][NFC]Replace multiple isa calls with single one where possible,
NFC.
1 parent 2dde4ba commit 2819126

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static bool isValidElementType(Type *Ty) {
205205
/// \returns True if the value is a constant (but not globals/constant
206206
/// expressions).
207207
static bool isConstant(Value *V) {
208-
return isa<Constant>(V) && !isa<ConstantExpr>(V) && !isa<GlobalValue>(V);
208+
return isa<Constant>(V) && !isa<ConstantExpr, GlobalValue>(V);
209209
}
210210

211211
/// Checks if \p V is one of vector-like instructions, i.e. undef,
@@ -2994,7 +2994,7 @@ class BoUpSLP {
29942994
// okay.
29952995
auto *In = BundleMember->Inst;
29962996
assert(In &&
2997-
(isa<ExtractValueInst>(In) || isa<ExtractElementInst>(In) ||
2997+
(isa<ExtractValueInst, ExtractElementInst>(In) ||
29982998
In->getNumOperands() == TE->getNumOperands()) &&
29992999
"Missed TreeEntry operands?");
30003000
(void)In; // fake use to avoid build failure when assertions disabled
@@ -4489,7 +4489,7 @@ static std::pair<size_t, size_t> generateKeySubkey(
44894489
} else if (auto *I = dyn_cast<Instruction>(V)) {
44904490
// Sort other instructions just by the opcodes except for CMPInst.
44914491
// For CMP also sort by the predicate kind.
4492-
if ((isa<BinaryOperator>(I) || isa<CastInst>(I)) &&
4492+
if ((isa<BinaryOperator, CastInst>(I)) &&
44934493
isValidForAlternation(I->getOpcode())) {
44944494
if (AllowAlternate)
44954495
Key = hash_value(isa<BinaryOperator>(I) ? 1 : 0);
@@ -5536,8 +5536,7 @@ unsigned BoUpSLP::canMapToVector(Type *T, const DataLayout &DL) const {
55365536
unsigned N = 1;
55375537
Type *EltTy = T;
55385538

5539-
while (isa<StructType>(EltTy) || isa<ArrayType>(EltTy) ||
5540-
isa<VectorType>(EltTy)) {
5539+
while (isa<StructType, ArrayType, VectorType>(EltTy)) {
55415540
if (auto *ST = dyn_cast<StructType>(EltTy)) {
55425541
// Check that struct is homogeneous.
55435542
for (const auto *Ty : ST->elements())
@@ -5867,9 +5866,9 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
58675866
// Take credit for instruction that will become dead.
58685867
if (EE->hasOneUse()) {
58695868
Instruction *Ext = EE->user_back();
5870-
if ((isa<SExtInst>(Ext) || isa<ZExtInst>(Ext)) &&
5871-
all_of(Ext->users(),
5872-
[](User *U) { return isa<GetElementPtrInst>(U); })) {
5869+
if (isa<SExtInst, ZExtInst>(Ext) && all_of(Ext->users(), [](User *U) {
5870+
return isa<GetElementPtrInst>(U);
5871+
})) {
58735872
// Use getExtractWithExtendCost() to calculate the cost of
58745873
// extractelement/ext pair.
58755874
Cost -=
@@ -6142,18 +6141,18 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
61426141
// Take credit for instruction that will become dead.
61436142
if (EI->hasOneUse()) {
61446143
Instruction *Ext = EI->user_back();
6145-
if ((isa<SExtInst>(Ext) || isa<ZExtInst>(Ext)) &&
6144+
if (isa<SExtInst, ZExtInst>(Ext) &&
61466145
all_of(Ext->users(),
61476146
[](User *U) { return isa<GetElementPtrInst>(U); })) {
6148-
// Use getExtractWithExtendCost() to calculate the cost of
6149-
// extractelement/ext pair.
6150-
CommonCost -= TTI->getExtractWithExtendCost(
6151-
Ext->getOpcode(), Ext->getType(), VecTy, I);
6152-
// Add back the cost of s|zext which is subtracted separately.
6153-
CommonCost += TTI->getCastInstrCost(
6154-
Ext->getOpcode(), Ext->getType(), EI->getType(),
6155-
TTI::getCastContextHint(Ext), CostKind, Ext);
6156-
continue;
6147+
// Use getExtractWithExtendCost() to calculate the cost of
6148+
// extractelement/ext pair.
6149+
CommonCost -= TTI->getExtractWithExtendCost(
6150+
Ext->getOpcode(), Ext->getType(), VecTy, I);
6151+
// Add back the cost of s|zext which is subtracted separately.
6152+
CommonCost += TTI->getCastInstrCost(
6153+
Ext->getOpcode(), Ext->getType(), EI->getType(),
6154+
TTI::getCastContextHint(Ext), CostKind, Ext);
6155+
continue;
61576156
}
61586157
}
61596158
CommonCost -=
@@ -9001,8 +9000,8 @@ void BoUpSLP::optimizeGatherSequence() {
90019000
for (Instruction &In : llvm::make_early_inc_range(*BB)) {
90029001
if (isDeleted(&In))
90039002
continue;
9004-
if (!isa<InsertElementInst>(&In) && !isa<ExtractElementInst>(&In) &&
9005-
!isa<ShuffleVectorInst>(&In) && !GatherShuffleSeq.contains(&In))
9003+
if (!isa<InsertElementInst, ExtractElementInst, ShuffleVectorInst>(&In) &&
9004+
!GatherShuffleSeq.contains(&In))
90069005
continue;
90079006

90089007
// Check if we can replace this instruction with any of the
@@ -9660,17 +9659,15 @@ unsigned BoUpSLP::getVectorElementSize(Value *V) {
96609659

96619660
// If the current instruction is a load, update MaxWidth to reflect the
96629661
// width of the loaded value.
9663-
if (isa<LoadInst>(I) || isa<ExtractElementInst>(I) ||
9664-
isa<ExtractValueInst>(I))
9662+
if (isa<LoadInst, ExtractElementInst, ExtractValueInst>(I))
96659663
Width = std::max<unsigned>(Width, DL->getTypeSizeInBits(Ty));
96669664

96679665
// Otherwise, we need to visit the operands of the instruction. We only
96689666
// handle the interesting cases from buildTree here. If an operand is an
96699667
// instruction we haven't yet visited and from the same basic block as the
96709668
// user or the use is a PHI node, we add it to the worklist.
9671-
else if (isa<PHINode>(I) || isa<CastInst>(I) || isa<GetElementPtrInst>(I) ||
9672-
isa<CmpInst>(I) || isa<SelectInst>(I) || isa<BinaryOperator>(I) ||
9673-
isa<UnaryOperator>(I)) {
9669+
else if (isa<PHINode, CastInst, GetElementPtrInst, CmpInst, SelectInst,
9670+
BinaryOperator, UnaryOperator>(I)) {
96749671
for (Use &U : I->operands())
96759672
if (auto *J = dyn_cast<Instruction>(U.get()))
96769673
if (Visited.insert(J).second &&
@@ -9723,8 +9720,7 @@ static bool collectValuesToDemote(Value *V, SmallPtrSetImpl<Value *> &Expr,
97239720
break;
97249721
case Instruction::ZExt:
97259722
case Instruction::SExt:
9726-
if (isa<ExtractElementInst>(I->getOperand(0)) ||
9727-
isa<InsertElementInst>(I->getOperand(0)))
9723+
if (isa<ExtractElementInst, InsertElementInst>(I->getOperand(0)))
97289724
return false;
97299725
break;
97309726

@@ -10422,8 +10418,7 @@ bool SLPVectorizerPass::tryToVectorize(Instruction *I, BoUpSLP &R) {
1042210418
if (!I)
1042310419
return false;
1042410420

10425-
if ((!isa<BinaryOperator>(I) && !isa<CmpInst>(I)) ||
10426-
isa<VectorType>(I->getType()))
10421+
if (!isa<BinaryOperator, CmpInst>(I) || isa<VectorType>(I->getType()))
1042710422
return false;
1042810423

1042910424
Value *P = I->getParent();
@@ -11533,8 +11528,7 @@ static void findBuildAggregate_rec(Instruction *LastInsertInst,
1153311528
getInsertIndex(LastInsertInst, OperandOffset);
1153411529
if (!OperandIndex)
1153511530
return;
11536-
if (isa<InsertElementInst>(InsertedOperand) ||
11537-
isa<InsertValueInst>(InsertedOperand)) {
11531+
if (isa<InsertElementInst, InsertValueInst>(InsertedOperand)) {
1153811532
findBuildAggregate_rec(cast<Instruction>(InsertedOperand), TTI,
1153911533
BuildVectorOpds, InsertElts, *OperandIndex);
1154011534

@@ -11544,8 +11538,7 @@ static void findBuildAggregate_rec(Instruction *LastInsertInst,
1154411538
}
1154511539
LastInsertInst = dyn_cast<Instruction>(LastInsertInst->getOperand(0));
1154611540
} while (LastInsertInst != nullptr &&
11547-
(isa<InsertValueInst>(LastInsertInst) ||
11548-
isa<InsertElementInst>(LastInsertInst)) &&
11541+
isa<InsertValueInst, InsertElementInst>(LastInsertInst) &&
1154911542
LastInsertInst->hasOneUse());
1155011543
}
1155111544

@@ -12240,8 +12233,8 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
1224012233
// Ran into an instruction without users, like terminator, or function call
1224112234
// with ignored return value, store. Ignore unused instructions (basing on
1224212235
// instruction type, except for CallInst and InvokeInst).
12243-
if (it->use_empty() && (it->getType()->isVoidTy() || isa<CallInst>(it) ||
12244-
isa<InvokeInst>(it))) {
12236+
if (it->use_empty() &&
12237+
(it->getType()->isVoidTy() || isa<CallInst, InvokeInst>(it))) {
1224512238
KeyNodes.insert(&*it);
1224612239
bool OpsChanged = false;
1224712240
if (ShouldStartVectorizeHorAtStore || !isa<StoreInst>(it)) {
@@ -12265,8 +12258,7 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
1226512258
}
1226612259
}
1226712260

12268-
if (isa<InsertElementInst>(it) || isa<CmpInst>(it) ||
12269-
isa<InsertValueInst>(it))
12261+
if (isa<CmpInst, InsertElementInst, InsertValueInst>(it))
1227012262
PostProcessInstructions.push_back(&*it);
1227112263
}
1227212264

0 commit comments

Comments
 (0)