Skip to content

Commit e3b4c1b

Browse files
XinWang10xin10.wang
authored andcommitted
[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
1 parent bf8f684 commit e3b4c1b

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
23342334
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
23352335
std::optional<FastMathFlags> FMF,
23362336
TTI::TargetCostKind CostKind) {
2337+
assert(Ty && "Unknown reduction vector type");
23372338
if (TTI::requiresOrderedReduction(FMF))
23382339
return getOrderedReductionCost(Opcode, Ty, CostKind);
23392340
return getTreeReductionCost(Opcode, Ty, CostKind);

0 commit comments

Comments
 (0)