[PATCH] D146118: [X86]add assert to confirm not-null ptr in getArithmeticReductionCost
Wang, Xin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 15 02:22:22 PDT 2023
XinWang10 created this revision.
Herald added a project: All.
XinWang10 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146118
Files:
llvm/include/llvm/CodeGen/BasicTTIImpl.h
Index: llvm/include/llvm/CodeGen/BasicTTIImpl.h
===================================================================
--- llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -2334,6 +2334,7 @@
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
std::optional<FastMathFlags> FMF,
TTI::TargetCostKind CostKind) {
+ assert(Ty && "Unexpected argument types");
if (TTI::requiresOrderedReduction(FMF))
return getOrderedReductionCost(Opcode, Ty, CostKind);
return getTreeReductionCost(Opcode, Ty, CostKind);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146118.505404.patch
Type: text/x-patch
Size: 675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230315/dd90922c/attachment.bin>
More information about the llvm-commits
mailing list