[llvm] e3b4c1b - [X86]add assert to confirm not-null ptr in getArithmeticReductionCost
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 16 23:17:56 PDT 2023
Author: Wang, Xin10
Date: 2023-03-17T02:17:49-04:00
New Revision: e3b4c1bc528bf6d6f8b52aa4e85779cc6fa32511
URL: https://github.com/llvm/llvm-project/commit/e3b4c1bc528bf6d6f8b52aa4e85779cc6fa32511
DIFF: https://github.com/llvm/llvm-project/commit/e3b4c1bc528bf6d6f8b52aa4e85779cc6fa32511.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/CodeGen/BasicTTIImpl.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 2ae01333b2c9a..81c007485a993 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -2334,6 +2334,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
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);
More information about the llvm-commits
mailing list