This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] add folds for constant mask of value shifted by constant
ClosedPublic

Authored by spatel on May 15 2017, 4:25 PM.

Details

Summary

I was investigating why a different simplification wasn't happening and noticed that we don't have this fold for the easy case with constants.

We would eventually catch these via demanded bits and computing known bits in InstCombine, but I think it's better to handle the simple cases as soon as possible as a matter of efficiency?

If there's a better way to do the APInt manipulations, please let me know.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.May 15 2017, 4:25 PM
efriedma edited edge metadata.May 15 2017, 6:59 PM

We don't want to write out a bunch of patterns here which are completely redundant, but this pattern in particular is likely to come up in code involving bitfields, so it seems fine.

lib/Analysis/InstructionSimplify.cpp
1770 ↗(On Diff #99080)

(~*Mask).shl(*ShAmt).isNullValue()? Not sure that's better.

spatel added inline comments.May 16 2017, 8:45 AM
lib/Analysis/InstructionSimplify.cpp
1770 ↗(On Diff #99080)

Looks better to me - we can use the inverted mask for both cases to make things symmetrical.
That also makes it easier to write the Alive tests:
http://rise4fun.com/Alive/lY0

spatel updated this revision to Diff 99151.May 16 2017, 8:52 AM

Patch updated:

  1. Inverted the mask constant to simplify the code and make the 2 cases symmetrical.
  2. Modified the code comments to explain that logic.
efriedma accepted this revision.May 16 2017, 12:12 PM

Looks good.

This revision is now accepted and ready to land.May 16 2017, 12:12 PM
This revision was automatically updated to reflect the committed changes.