This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Begin adding some useful methods to the proposed KnownBits struct
AbandonedPublic

Authored by craig.topper on Apr 25 2017, 3:26 PM.

Details

Summary

This patch adds some plausible methods to the KnownBits struct from D32376.

I'm not married to the names for hasConflict, isValid, isComplete, and getValue.

hasConflict and isValid are opposites of each other, but I've added both because isValid is going to be primarily used in asserts that verify no conflicts. hasConflict will be used in a couple places in places where we explicitly check for conflicts today like in the assume handling code.

I've intentionally avoided calling isComplete something like allBitsKnown because the struct itself is usually a variable called Known so it would read repetitively.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 25 2017, 3:26 PM
RKSimon added inline comments.Apr 26 2017, 1:29 AM
include/llvm/Support/KnownBits.h
10

This should be in D32376

RKSimon edited edge metadata.Apr 26 2017, 3:32 AM

I realise there are plenty of possible helpers but zextOrTrunc and clearAllBits would definitely be useful.

include/llvm/Support/KnownBits.h
51

<bikeshed>Not too sure about isComplete - bit too similar to isValid?</bikeshed>

If isComplete and getValue are likely to always be used together is it worth merging them into a single method:

bool isCompleteValue(APInt &) ?

I definitely meant to add clearAllBits.

include/llvm/Support/KnownBits.h
51

I made it two separate methods because it's often going to be used like

if (Known.isComplete())
  return ConstantInt::get(Tyep, Known.getValue());
53

I'm slightly concerned that doing the population count in the single word APInt case on pre-Westmere CPUs(no harware popcnt) is worse than doing the OR and checking for all 1s. But in the multiword case the OR needs a temporary APInt so this may be better.

Considering adding something like isUnionFull to APInt to do the OR in place on each word without the allocation like intersects and isSubsetOf.

Maybe a better name for isComplete/getValue would be isConstant and getConstant?

Maybe a better name for isComplete/getValue would be isConstant and getConstant?

Makes sense to me.

include/llvm/Support/KnownBits.h
53

Happy to go with this for now. APInt::isUnionFull makes sense - it complements the existing intersection/subset tests - but that can be a future change.

spatel edited edge metadata.Apr 30 2017, 8:28 AM

Maybe a better name for isComplete/getValue would be isConstant and getConstant?

isConstant/getConstant are better IMO. Not sure if it would cause 'known' overload in the user code, but could remove more ambiguity with: allBitsKnown/getKnownConstant ?

My implementation of sext/zext/trunc is busted in this patch. They need to create a new object and should return the new object.

Is this patch still relevant?

craig.topper abandoned this revision.May 12 2017, 9:37 AM