From e3b4c1bc528bf6d6f8b52aa4e85779cc6fa32511 Mon Sep 17 00:00:00 2001 From: "Wang, Xin10" Date: Fri, 17 Mar 2023 02:16:58 -0400 Subject: [PATCH] [X86]add assert to confirm not-null ptr in getArithmeticReductionCost 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 2ae0133..81c0074 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -2334,6 +2334,7 @@ public: InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional FMF, TTI::TargetCostKind CostKind) { + assert(Ty && "Unknown reduction vector type"); if (TTI::requiresOrderedReduction(FMF)) return getOrderedReductionCost(Opcode, Ty, CostKind); return getTreeReductionCost(Opcode, Ty, CostKind); -- 2.7.4