[llvm] afbf546 - [SLP]Improve operands kind analaysis for constants.

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 06:36:44 PDT 2022


Author: Alexey Bataev
Date: 2022-08-30T06:35:39-07:00
New Revision: afbf5466ba0e20ca575b3f6af9ab20251e5285b6

URL: https://github.com/llvm/llvm-project/commit/afbf5466ba0e20ca575b3f6af9ab20251e5285b6
DIFF: https://github.com/llvm/llvm-project/commit/afbf5466ba0e20ca575b3f6af9ab20251e5285b6.diff

LOG: [SLP]Improve operands kind analaysis for constants.

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.

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

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 c3f66624a98c2..bf746b9320f15 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2125,9 +2125,8 @@ class BoUpSLP {
 
   /// 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 @@ static bool isAlternateInstruction(const Instruction *I,
 }
 
 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 
diff erent 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 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
       // 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 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
       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;


        


More information about the llvm-commits mailing list