This is an archive of the discontinued LLVM Phabricator instance.

[ConstantRange] Handle `Intrinsic::cttz` and `Intrinsic::ctpop`
AbandonedPublic

Authored by dtcxzyw on Jun 22 2023, 12:54 AM.

Details

Reviewers
nikic
reames
fhahn
Summary

This patch adds support for cttz and ctpop intrinsics in ConstantRange. It calculates the range in O(1) with the LCP-based method.

Diff Detail

Event Timeline

dtcxzyw created this revision.Jun 22 2023, 12:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 12:54 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
dtcxzyw requested review of this revision.Jun 22 2023, 12:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 12:54 AM
nikic requested changes to this revision.Jun 22 2023, 2:03 AM

If it's not possible to have efficient precise implementations for these, please just use simple approximations like this:

ConstantRange ConstantRange::ctpop() const {
  if (isEmptySet())
    return getEmpty();     
    
  KnownBits Known = toKnownBits();
  return getNonEmpty(APInt(getBitWidth(), Known.countMinPopulation()),
                     APInt(getBitWidth(), Known.countMaxPopulation() + 1));
}

I'm not willing to have linear time ConstantRange methods.

This revision now requires changes to proceed.Jun 22 2023, 2:03 AM
dtcxzyw updated this revision to Diff 533707.Jun 22 2023, 11:38 AM
dtcxzyw edited the summary of this revision. (Show Details)
  • Rebase
  • Do range minimum/maximum query in O(1) for cttz and ctpop

I will add more detailed comments later if the time complexity is acceptable.

dtcxzyw updated this revision to Diff 534176.Jun 24 2023, 12:57 AM
dtcxzyw edited the summary of this revision. (Show Details)
  • Rebase
  • Use simpler and faster O(1) LCP-based method
dtcxzyw abandoned this revision.Mon, Nov 20, 7:36 PM