diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/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 VL, unsigned OpIdx, bool EnableFP); + TargetTransformInfo::OperandValueInfo getOperandInfo(ArrayRef VL, + unsigned OpIdx); /// \returns the cost of the vectorizable entry. InstructionCost getEntryCost(const TreeEntry *E, @@ -5816,24 +5815,30 @@ } TTI::OperandValueInfo BoUpSLP::getOperandInfo(ArrayRef 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(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(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(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(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 Operands(VL0->operand_values()); InstructionCost ScalarEltCost = @@ -6516,7 +6520,7 @@ auto *SI = cast(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;