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.
Details
Diff Detail
- Repository
- rL LLVM
- Build Status
Buildable 26197 Build 26196: arc lint + arc unit
Event Timeline
lib/Transforms/Scalar/LoopIdiomRecognize.cpp | ||
---|---|---|
1511 | Why are we doing this a different way than detectShiftUntilZeroIdiom? And why does the base need to be constant? | |
1578 | Why can't we limit to just checking the preheader condition like the shiftUntilZero? Do you have more complex real world examples you're trying to handle? | |
1761 | Can you write this as bool FoundBitScanIdiom; if (detectShiftUntilZero...) FoundBitScanIdiom = false; else if (detectShiftUntilZero...) FoundBitCanIdiom = true; else return false That should make it easier to add a third idiom in the future. |
lib/Transforms/Scalar/LoopIdiomRecognize.cpp | ||
---|---|---|
1511 | I thought they are an equivalent way to detect CntPhi and IMHO more clear to read than the way used by detectShiftUntilZeroIdiom. Making the base constant is unintentional. Updated patch to reflect that. | |
1578 | Other than checking the input is non-zero, a naive implementation of bitscan idiom like "cttz_bitscan_shl" and "cttz_bitscan_shl_phi" (in cttz.ll) have the preheader that checks the "first bit" of the input (check it is zero). Here is to generalize the native pattern 1: preheader is generalized to any block that dominates the loop; 2. "initial bit" is generalized to "first <x> bits where <x> is within the range of bit indexes that checked by the loop" I don't have a complex real world example, but thought this help recognize cttz pattern out of more than just the naive implementation with a few more checks. |
lib/Transforms/Scalar/LoopIdiomRecognize.cpp | ||
---|---|---|
1511 | I'm sure they are equivalent. I just think we should try to have consistent implementations for the same thing in the same area of the compiler. |
lib/Transforms/Scalar/LoopIdiomRecognize.cpp | ||
---|---|---|
1511 | updated |
Why are we doing this a different way than detectShiftUntilZeroIdiom? And why does the base need to be constant?