This is an archive of the discontinued LLVM Phabricator instance.

[DemandedBits] Add support for funnel shifts
ClosedPublic

Authored by nikic on Nov 25 2018, 2:25 AM.

Details

Summary

Add support for funnel shifts to the DemandedBits analysis. The demanded bits of the first two operands can be determined if the shift amount is constant. The demanded bits of the third operand (shift amount) can be determined if the bitwidth is a power of two.

This is basically the same functionality as implemented in D54869 and D54478, but for DemandedBits rather than InstCombine.

Diff Detail

Event Timeline

nikic created this revision.Nov 25 2018, 2:25 AM
spatel added inline comments.Nov 25 2018, 7:55 AM
lib/Analysis/DemandedBits.cpp
147

Is this analysis completely ignoring vector integer instructions?

It would still be good to use 'match(X, m_APInt())' in case we ever upgrade the whole thing to handle vectors. But if the answer to the above question is 'yes', then a TODO comment is ok for now.

154–156

Can we do something like D54478 for operand 2 in a follow-up patch?

nikic updated this revision to Diff 175178.Nov 25 2018, 10:03 AM
nikic edited the summary of this revision. (Show Details)

Determine demanded bits for shift operand as well.

nikic marked 4 inline comments as done.Nov 25 2018, 10:08 AM
nikic added inline comments.
lib/Analysis/DemandedBits.cpp
147

Yes, DemandedBits currently only operates on scalar integer instructions. I originally wanted to use match() here, but seeing how all the surrounding code uses ConstantInt casts, I went with that.

I might look into adding vector support for DemandedBits, it does not seem too complicated.

154–156

I went ahead and included it here, as it seems like a small enough change :)

spatel accepted this revision.Nov 26 2018, 6:32 AM

LGTM

This revision is now accepted and ready to land.Nov 26 2018, 6:32 AM
This revision was automatically updated to reflect the committed changes.