[SLP] Return a boolean value for these static helpers. NFC.

Differential Revision: https://reviews.llvm.org/D24008

llvm-svn: 280020
This commit is contained in:
Chad Rosier 2016-08-29 22:09:51 +00:00
parent 77ed6af416
commit 6e1eaac62b
1 changed files with 16 additions and 17 deletions

View File

@ -115,22 +115,22 @@ static bool isValidElementType(Type *Ty) {
!Ty->isPPC_FP128Ty(); !Ty->isPPC_FP128Ty();
} }
/// \returns the parent basic block if all of the instructions in \p VL /// \returns true if all of the instructions in \p VL are in the same block or
/// are in the same block or null otherwise. /// false otherwise.
static BasicBlock *getSameBlock(ArrayRef<Value *> VL) { static bool allSameBlock(ArrayRef<Value *> VL) {
Instruction *I0 = dyn_cast<Instruction>(VL[0]); Instruction *I0 = dyn_cast<Instruction>(VL[0]);
if (!I0) if (!I0)
return nullptr; return false;
BasicBlock *BB = I0->getParent(); BasicBlock *BB = I0->getParent();
for (int i = 1, e = VL.size(); i < e; i++) { for (int i = 1, e = VL.size(); i < e; i++) {
Instruction *I = dyn_cast<Instruction>(VL[i]); Instruction *I = dyn_cast<Instruction>(VL[i]);
if (!I) if (!I)
return nullptr; return false;
if (BB != I->getParent()) if (BB != I->getParent())
return nullptr; return false;
} }
return BB; return true;
} }
/// \returns True if all of the values in \p VL are constants. /// \returns True if all of the values in \p VL are constants.
@ -224,15 +224,15 @@ static void propagateIRFlags(Value *I, ArrayRef<Value *> VL) {
} }
} }
/// \returns The type that all of the values in \p VL have or null if there /// \returns true if all of the values in \p VL have the same type or false
/// are different types. /// otherwise.
static Type* getSameType(ArrayRef<Value *> VL) { static bool allSameType(ArrayRef<Value *> VL) {
Type *Ty = VL[0]->getType(); Type *Ty = VL[0]->getType();
for (int i = 1, e = VL.size(); i < e; i++) for (int i = 1, e = VL.size(); i < e; i++)
if (VL[i]->getType() != Ty) if (VL[i]->getType() != Ty)
return nullptr; return false;
return Ty; return true;
} }
/// \returns True if Extract{Value,Element} instruction extracts element Idx. /// \returns True if Extract{Value,Element} instruction extracts element Idx.
@ -921,7 +921,7 @@ void BoUpSLP::buildTree(ArrayRef<Value *> Roots,
ArrayRef<Value *> UserIgnoreLst) { ArrayRef<Value *> UserIgnoreLst) {
deleteTree(); deleteTree();
UserIgnoreList = UserIgnoreLst; UserIgnoreList = UserIgnoreLst;
if (!getSameType(Roots)) if (!allSameType(Roots))
return; return;
buildTree_rec(Roots, 0); buildTree_rec(Roots, 0);
@ -975,9 +975,8 @@ void BoUpSLP::buildTree(ArrayRef<Value *> Roots,
void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) {
bool SameTy = allConstant(VL) || getSameType(VL); (void)SameTy;
bool isAltShuffle = false; bool isAltShuffle = false;
assert(SameTy && "Invalid types!"); assert((allConstant(VL) || allSameType(VL)) && "Invalid types!");
if (Depth == RecursionMaxDepth) { if (Depth == RecursionMaxDepth) {
DEBUG(dbgs() << "SLP: Gathering due to max recursion depth.\n"); DEBUG(dbgs() << "SLP: Gathering due to max recursion depth.\n");
@ -1010,7 +1009,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) {
} }
// If all of the operands are identical or constant we have a simple solution. // If all of the operands are identical or constant we have a simple solution.
if (allConstant(VL) || isSplat(VL) || !getSameBlock(VL) || !Opcode) { if (allConstant(VL) || isSplat(VL) || !allSameBlock(VL) || !Opcode) {
DEBUG(dbgs() << "SLP: Gathering due to C,S,B,O. \n"); DEBUG(dbgs() << "SLP: Gathering due to C,S,B,O. \n");
newTreeEntry(VL, false); newTreeEntry(VL, false);
return; return;
@ -1585,7 +1584,7 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
return getGatherCost(E->Scalars); return getGatherCost(E->Scalars);
} }
unsigned Opcode = getSameOpcode(VL); unsigned Opcode = getSameOpcode(VL);
assert(Opcode && getSameType(VL) && getSameBlock(VL) && "Invalid VL"); assert(Opcode && allSameType(VL) && allSameBlock(VL) && "Invalid VL");
Instruction *VL0 = cast<Instruction>(VL[0]); Instruction *VL0 = cast<Instruction>(VL[0]);
switch (Opcode) { switch (Opcode) {
case Instruction::PHI: { case Instruction::PHI: {