[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 15:07:05 PDT 2022


ABataev updated this revision to Diff 456472.
ABataev added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132886/new/

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.456472.patch
Type: text/x-patch
Size: 3637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220829/457d2913/attachment.bin>


More information about the llvm-commits mailing list