This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking, InstSimplify] extend isKnownNonZero() to handle vector constants
ClosedPublic

Authored by spatel on May 23 2016, 3:42 PM.

Details

Summary

Similar in spirit to D20497 :
If all elements of a constant vector are known non-zero, then we can say that the whole vector is known non-zero.
It seems like we could extend this to FP scalar/vector too, but isKnownNonZero() says it only works for integers and pointers for now.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 58166.May 23 2016, 3:42 PM
spatel retitled this revision from to [ValueTracking, InstSimplify] extend isKnownNonZero() to handle vector constants.
spatel updated this object.
spatel added reviewers: majnemer, jmolloy, sanjoy.
spatel added a subscriber: llvm-commits.
majnemer accepted this revision.May 23 2016, 4:21 PM
majnemer edited edge metadata.

LGTM with nits.

lib/Analysis/ValueTracking.cpp
1686–1689 ↗(On Diff #58166)

Might be easier to read as:

Constant *Elt = C->getAggregateElement(i);
if (!Elt || Elt->isNullValue())
  return false;
if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt))
  return false;

While it is a little more code, I think it's a little easier to follow along.

This revision is now accepted and ready to land.May 23 2016, 4:21 PM
spatel added inline comments.May 24 2016, 7:05 AM
lib/Analysis/ValueTracking.cpp
1686–1689 ↗(On Diff #58166)

Sure - I actually had written it that way initially, but I thought the nit would be to make it one big 'if'. :)
I'll flip it back. Thanks!

This revision was automatically updated to reflect the committed changes.