[llvm] 66c623b - [SLP][NFC]Use TreeEntry::getOprand instead of trying to rebuild it in getOperandInfo(), NFC.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 23 13:46:22 PDT 2023
Author: Alexey Bataev
Date: 2023-08-23T13:37:36-07:00
New Revision: 66c623bfc6c11a1d23e28166ecc5ad5297af8f9e
URL: https://github.com/llvm/llvm-project/commit/66c623bfc6c11a1d23e28166ecc5ad5297af8f9e
DIFF: https://github.com/llvm/llvm-project/commit/66c623bfc6c11a1d23e28166ecc5ad5297af8f9e.diff
LOG: [SLP][NFC]Use TreeEntry::getOprand instead of trying to rebuild it in getOperandInfo(), NFC.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 6c28f181146a58..196f1d384e8aa5 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2424,7 +2424,7 @@ class BoUpSLP {
/// Return information about the vector formed for the specified index
/// of a vector of (the same) instruction.
- TargetTransformInfo::OperandValueInfo getOperandInfo(ArrayRef<Value *> VL,
+ TargetTransformInfo::OperandValueInfo getOperandInfo(const TreeEntry &E,
unsigned OpIdx);
/// \returns the cost of the vectorizable entry.
@@ -6521,52 +6521,29 @@ static bool isAlternateInstruction(const Instruction *I,
return I->getOpcode() == AltOp->getOpcode();
}
-TTI::OperandValueInfo BoUpSLP::getOperandInfo(ArrayRef<Value *> VL,
+TTI::OperandValueInfo BoUpSLP::getOperandInfo(const TreeEntry &E,
unsigned OpIdx) {
+ ArrayRef<Value*> VL = E.getOperand(OpIdx);
assert(!VL.empty());
- const auto *I0 = cast<Instruction>(*find_if(VL, Instruction::classof));
- const auto *Op0 = I0->getOperand(OpIdx);
+ const auto *Op0 = VL.front();
- const bool IsConstant = all_of(VL, [&](Value *V) {
+ const bool IsConstant = all_of(VL, [](Value *V) {
// TODO: We should allow undef elements here
- const auto *I = dyn_cast<Instruction>(V);
- if (!I)
- return true;
- auto *Op = I->getOperand(OpIdx);
- return isConstant(Op) && !isa<UndefValue>(Op);
+ return isConstant(V) && !isa<UndefValue>(V);
});
- const bool IsUniform = all_of(VL, [&](Value *V) {
+ const bool IsUniform = all_of(VL, [=](Value *V) {
// TODO: We should allow undef elements here
- const auto *I = dyn_cast<Instruction>(V);
- if (!I)
- return false;
- return I->getOperand(OpIdx) == Op0;
+ return V == Op0;
});
- const bool IsPowerOfTwo = all_of(VL, [&](Value *V) {
+ const bool IsPowerOfTwo = all_of(VL, [](Value *V) {
// TODO: We should allow undef elements here
- const auto *I = dyn_cast<Instruction>(V);
- if (!I) {
- assert((isa<UndefValue>(V) ||
- I0->getOpcode() == Instruction::GetElementPtr) &&
- "Expected undef or GEP.");
- return true;
- }
- auto *Op = I->getOperand(OpIdx);
- if (auto *CI = dyn_cast<ConstantInt>(Op))
+ if (auto *CI = dyn_cast<ConstantInt>(V))
return CI->getValue().isPowerOf2();
return false;
});
- const bool IsNegatedPowerOfTwo = all_of(VL, [&](Value *V) {
+ const bool IsNegatedPowerOfTwo = all_of(VL, [](Value *V) {
// TODO: We should allow undef elements here
- const auto *I = dyn_cast<Instruction>(V);
- if (!I) {
- assert((isa<UndefValue>(V) ||
- I0->getOpcode() == Instruction::GetElementPtr) &&
- "Expected undef or GEP.");
- return true;
- }
- const auto *Op = I->getOperand(OpIdx);
- if (auto *CI = dyn_cast<ConstantInt>(Op))
+ if (auto *CI = dyn_cast<ConstantInt>(V))
return CI->getValue().isNegatedPowerOf2();
return false;
});
@@ -7973,8 +7950,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
};
auto GetVectorCost = [=](InstructionCost CommonCost) {
unsigned OpIdx = isa<UnaryOperator>(VL0) ? 0 : 1;
- TTI::OperandValueInfo Op1Info = getOperandInfo(VL, 0);
- TTI::OperandValueInfo Op2Info = getOperandInfo(VL, OpIdx);
+ TTI::OperandValueInfo Op1Info = getOperandInfo(*E, 0);
+ TTI::OperandValueInfo Op2Info = getOperandInfo(*E, OpIdx);
return TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind, Op1Info,
Op2Info) +
CommonCost;
@@ -8030,7 +8007,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
bool IsReorder = !E->ReorderIndices.empty();
auto GetScalarCost = [=](unsigned Idx) {
auto *VI = cast<StoreInst>(VL[Idx]);
- TTI::OperandValueInfo OpInfo = getOperandInfo(VI, 0);
+ TTI::OperandValueInfo OpInfo = TTI::getOperandInfo(VI->getValueOperand());
return TTI->getMemoryOpCost(Instruction::Store, ScalarTy, VI->getAlign(),
VI->getPointerAddressSpace(), CostKind,
OpInfo, VI);
@@ -8039,7 +8016,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
cast<StoreInst>(IsReorder ? VL[E->ReorderIndices.front()] : VL0);
auto GetVectorCost = [=](InstructionCost CommonCost) {
// We know that we can merge the stores. Calculate the cost.
- TTI::OperandValueInfo OpInfo = getOperandInfo(VL, 0);
+ TTI::OperandValueInfo OpInfo = getOperandInfo(*E, 0);
return TTI->getMemoryOpCost(Instruction::Store, VecTy, BaseSI->getAlign(),
BaseSI->getPointerAddressSpace(), CostKind,
OpInfo) +
More information about the llvm-commits
mailing list