[PATCH] D132886: [SLP]Improve operands kind analaysis for constants.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 29 13:49:11 PDT 2022
ABataev created this revision.
ABataev added reviewers: RKSimon, vdmitrie, reames.
Herald added subscribers: vporpo, hiraditya.
Herald added a project: All.
ABataev requested review of this revision.
Herald added a subscriber: pcwang-thead.
Herald added a project: LLVM.
Removed EnableFP parameter in getOperandInfo function since it is not
needed, the operands kinds also controlled by the operation code, which
allows to remove extra check for the type of the operands. Also, added
analysis for uniform constant float values.
This change currently does not trigger any changes in the code since TTI
does not do analysis for constant floats, so it can be considered NFC.
Tested with llvm-test-suite + SPEC2017, no changes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132886
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2125,9 +2125,8 @@
/// Return information about the vector formed for the specified index
/// of a vector of (the same) instruction.
- /// \param EnableFP - If true, check for float constants.
- TargetTransformInfo::OperandValueInfo
- getOperandInfo(ArrayRef<Value *> VL, unsigned OpIdx, bool EnableFP);
+ TargetTransformInfo::OperandValueInfo getOperandInfo(ArrayRef<Value *> VL,
+ unsigned OpIdx);
/// \returns the cost of the vectorizable entry.
InstructionCost getEntryCost(const TreeEntry *E,
@@ -5816,24 +5815,30 @@
}
TTI::OperandValueInfo BoUpSLP::getOperandInfo(ArrayRef<Value *> VL,
- unsigned OpIdx, bool EnableFP) {
- TTI::OperandValueKind VK = TTI::OK_UniformConstantValue;
- TTI::OperandValueProperties VP = TTI::OP_PowerOf2;
-
- // If all float operands are constants then set the operand kind to
+ unsigned OpIdx) {
+ // If all float point constants are the same, return OK_UniformConstantValue.
+ // If all float operands are different constants then set the operand kind to
// OK_NonUniformConstantValue. Otherwise, return OK_AnyValue.
const auto *I0 = cast<Instruction>(VL.front());
if (I0->getOperand(OpIdx)->getType()->isFloatingPointTy()) {
- if (!EnableFP || any_of(VL, [OpIdx, I0](Value *V) {
+ if (any_of(VL, [OpIdx, I0](Value *V) {
const auto *Inst = cast<Instruction>(V);
assert(Inst->getOpcode() == I0->getOpcode() &&
"Expected same opcode");
return !isConstant(Inst->getOperand(OpIdx));
}))
return {TTI::OK_AnyValue, TTI::OP_None};
- return {TTI::OK_NonUniformConstantValue, TTI::OP_None};
+ const auto *Op0 = I0->getOperand(OpIdx);
+ if (any_of(VL, [OpIdx, Op0](Value *V) {
+ return cast<Instruction>(V)->getOperand(OpIdx) == Op0;
+ }))
+ return {TTI::OK_NonUniformConstantValue, TTI::OP_None};
+ return {TTI::OK_UniformConstantValue, TTI::OP_None};
}
+ TTI::OperandValueKind VK = TTI::OK_UniformConstantValue;
+ TTI::OperandValueProperties VP = TTI::OP_PowerOf2;
+
// If all operands are exactly the same ConstantInt then set the
// operand kind to OK_UniformConstantValue.
// If instead not all operands are constants, then set the operand kind
@@ -6430,8 +6435,7 @@
// Certain instructions can be cheaper to vectorize if they have a
// constant second vector operand.
const unsigned OpIdx = isa<BinaryOperator>(VL0) ? 1 : 0;
- // TODO: impact of enabling the analysis there is yet to be determined
- auto Op2Info = getOperandInfo(VL, OpIdx, /*EnableFP=*/false);
+ auto Op2Info = getOperandInfo(VL, OpIdx);
SmallVector<const Value *, 4> Operands(VL0->operand_values());
InstructionCost ScalarEltCost =
@@ -6516,7 +6520,7 @@
auto *SI =
cast<StoreInst>(IsReorder ? VL[E->ReorderIndices.front()] : VL0);
Align Alignment = SI->getAlign();
- TTI::OperandValueInfo OpInfo = getOperandInfo(VL, 0, /*EnableFP=*/true);
+ TTI::OperandValueInfo OpInfo = getOperandInfo(VL, 0);
InstructionCost ScalarEltCost = TTI->getMemoryOpCost(
Instruction::Store, ScalarTy, Alignment, 0, CostKind, OpInfo, VL0);
InstructionCost ScalarStCost = VecTy->getNumElements() * ScalarEltCost;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132886.456455.patch
Type: text/x-patch
Size: 3637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220829/ea9593fd/attachment.bin>
More information about the llvm-commits
mailing list