This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Add basic vector support to computeKnownBits and SimplifyDemandedBits
ClosedPublic

Authored by RKSimon on Sep 6 2016, 5:52 AM.

Details

Summary

Add the ability to computeKnownBits and SimplifyDemandedBits to extract the known zero/one bits from a BUILD_VECTOR, returning the known bits that are shared by every vector element.

This is an initial step towards determining the sign bits of a vector (PR29079).

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon updated this revision to Diff 70392.Sep 6 2016, 5:52 AM
RKSimon retitled this revision from to [SelectionDAG] Add basic vector support to computeKnownBits and SimplifyDemandedBits.
RKSimon updated this object.
RKSimon added reviewers: bogner, arsenm, niravd, zvi, andreadb, spatel.
RKSimon set the repository for this revision to rL LLVM.
RKSimon added a subscriber: llvm-commits.
niravd edited edge metadata.Sep 6 2016, 8:09 AM

Is there a reason why you aren't keeping the known bits of a BUILD_VECTOR precise, i.e. concatenating each elements known bits?

lib/CodeGen/SelectionDAG/SelectionDAG.cpp
2035 ↗(On Diff #70392)

It would be clearer if you initialized KnownOne and KnownZero to all ones at the start of the loop and replace the conditional with the else case.

lib/CodeGen/SelectionDAG/TargetLowering.cpp
494 ↗(On Diff #70392)

Same as above

In addition to the already modified tests, we should add more explicit tests for the new functionality.

RKSimon updated this revision to Diff 70550.Sep 7 2016, 9:56 AM
RKSimon edited edge metadata.

There aren't that many cases that can use vectors that call SelectionDAG::computeKnownBits - the AMDGPU cases already test the ZEXT_LOAD example.

I've added support to DAGCombiner::visitAND to work with splatted constant vector values as well which has exposed one more test case, if you'd prefer for this to be put up for review separately then just say.

SelectionDAG::computeKnownBits like much of DAGCombiner has been coded to work on individual scalar elements (see all the references to getScalarType().getSizeInBits()), its not something that can be easily reworked so that APInt represents every bit of every vector element.

Some vectors already work with SelectionDAG::computeKnownBits (e.g. zext returns the KnownZero bits as its the same for every element).

I agree we want to have full per-element vector support in the long term but its not something that this patch makes any more difficult.

RKSimon marked 2 inline comments as done.Sep 7 2016, 9:58 AM

We now set all bits in KnownZero and KnownOne and then mask them off when they are not available in a given build_vector element.

zvi accepted this revision.Sep 7 2016, 12:24 PM
zvi edited edge metadata.

Looks like a good start. Can you please share your plans for continuing this work?

This revision is now accepted and ready to land.Sep 7 2016, 12:24 PM
This revision was automatically updated to reflect the committed changes.