This is an archive of the discontinued LLVM Phabricator instance.

[LIR] Add CTTZ support
AbandonedPublic

Authored by ychen on Dec 13 2018, 1:21 PM.

Details

Summary

Existing LIR recognizes CTLZ where shifting input variable right until it is zero. (Shift-Until-Zero idiom)

This commit:

  1. augment Shift-Until-Zero idiom to recognize CTTZ where input variable is shifted left.
  2. Add a second idiom recognition (BitScan idiom) where bits of input variable are scanned in order until hit a set bit: scan-from-left-to-right means CTLZ; scan-from-right-to-left means CTTZ. The starting bit index do not have to be first bit if we could prove from CFG that preceding bits are zero.

Related PR: llvm.org/PR17087

Diff Detail

Event Timeline

ychen created this revision.Dec 13 2018, 1:21 PM

Can you split this into two patches? One for the cttz shift until zero and one for the second idiom.

lib/Transforms/Scalar/LoopIdiomRecognize.cpp
191

No need to make IntrinID or InitShift const.

1123

Can this be split into two different functions? One that returns Value* and one that returns BasicBlock*? Maybe the shared code could be a helper function they both use?

ychen marked 2 inline comments as done.Dec 18 2018, 7:25 PM
ychen abandoned this revision.Dec 26 2018, 7:42 PM