[X86]add assert to confirm not-null ptr in getArithmeticReductionCost
authorWang, Xin10 <xin10.wang@intel.com>
Fri, 17 Mar 2023 06:16:58 +0000 (02:16 -0400)
committerxin10.wang <wangxin8@f90srv19.nh.intel.com>
Fri, 17 Mar 2023 06:17:49 +0000 (02:17 -0400)
For the function getArithmeticReductionCost, it receive a ptr and dereferce it without check,
It is called many times in getTypeBasedIntrinsicInstrCost, the ptr passed to it is inited
from line 1709.

From the code, we can not ensure the ptr VecOpTy is inited when Tys is empty or Tys[VecTyIndex]
is not a VectorType, so that the getArithmeticReductionCost will do an undefined behavior.

I add assert to it, found the ptr passed to it in llvm tests are all not nullptr, but I think the check is
still meaningful for us.

Reviewed By: RKSimon

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

llvm/include/llvm/CodeGen/BasicTTIImpl.h

index 2ae01333b2c9a97799f5e0907255f4e58e33b49d..81c007485a993ac57d313c81f808c73a18650f1b 100644 (file)
@@ -2334,6 +2334,7 @@ public:
   InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
                                              std::optional<FastMathFlags> FMF,
                                              TTI::TargetCostKind CostKind) {
+    assert(Ty && "Unknown reduction vector type");
     if (TTI::requiresOrderedReduction(FMF))
       return getOrderedReductionCost(Opcode, Ty, CostKind);
     return getTreeReductionCost(Opcode, Ty, CostKind);