This is an archive of the discontinued LLVM Phabricator instance.

[X86]add assert to confirm not-null ptr in getArithmeticReductionCost
ClosedPublic

Authored by XinWang10 on Mar 15 2023, 2:22 AM.

Details

Summary

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.

Diff Detail

Event Timeline

XinWang10 created this revision.Mar 15 2023, 2:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 2:22 AM
XinWang10 requested review of this revision.Mar 15 2023, 2:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 2:22 AM
XinWang10 edited the summary of this revision. (Show Details)Mar 15 2023, 2:23 AM
RKSimon accepted this revision.Mar 15 2023, 3:34 AM
RKSimon added a subscriber: RKSimon.

LGTM - a reduction cost is almost impossible without the type anyhow

llvm/include/llvm/CodeGen/BasicTTIImpl.h
2337

Maybe "Unknown reduction vector type" ?

This revision is now accepted and ready to land.Mar 15 2023, 3:34 AM
  • rebase and update assert msg

Thanks for your review!