This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Add vector demanded elements support to ComputeNumSignBits
ClosedPublic

Authored by RKSimon on Mar 23 2017, 3:04 PM.

Details

Summary

Currently ComputeNumSignBits returns the minimum number of sign bits for all elements of vector data, when we may only be interested in one/some of the elements.

This patch adds a DemandedElts argument that allows us to specify the elements we actually care about. The original ComputeNumSignBits implementation calls with a DemandedElts demanding all elements to match current behaviour. Scalar types set this to 1.

I've only added support for a few opcodes so far (the ones that have proven straightforward to test), all others will default to demanding all elements but can be updated in due course.

Followup to D25691.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Mar 23 2017, 3:04 PM
filcab added inline comments.Mar 24 2017, 9:37 AM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
3148 ↗(On Diff #92872)

Nit: I'd use the plural (DemandedElts).

3150 ↗(On Diff #92872)

Waiting for C++17… :-)

3156 ↗(On Diff #92872)

Do you care about adding a TODO here?

3191 ↗(On Diff #92872)

Was this change (the if, not the NumBits) done by clang-format?

test/CodeGen/X86/known-bits-vector.ll
41 ↗(On Diff #92872)

I wouldn't expect tests to change when you're just avoiding work.
Is this test hitting the computeKnownBits(...) case at the end of computeNumSignBits and has a non-trivial DemandedElts? (non-trivial would mean "not all 1s")

filcab added inline comments.Mar 24 2017, 9:39 AM
test/CodeGen/X86/known-bits-vector.ll
41 ↗(On Diff #92872)

Nevermind. This can happen on the other ones, when the minimum won't be among as many elements as before.
Assuming this test uses the EXTRACT_VECTOR_ELT, we probably are missing one for BUILD_VECTOR.

RKSimon added inline comments.Mar 24 2017, 12:07 PM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
3148 ↗(On Diff #92872)

Except it will cause a Wshadow problem - I can use DemandedElts maybe?

3150 ↗(On Diff #92872)

Someday......

3156 ↗(On Diff #92872)

I'd prefer not to - almost every opcode in this function needs a TODO right now.

3191 ↗(On Diff #92872)

I'll do a NFCI clang-format cleanup.

test/CodeGen/X86/known-bits-vector.ll
41 ↗(On Diff #92872)

It is actually calling the computeNumSignBits BUILD_VECTOR case here, but I'll add another test to make it clearer.

RKSimon added inline comments.Mar 24 2017, 4:53 PM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
3148 ↗(On Diff #92872)

DemandedSrcElts

RKSimon updated this revision to Diff 93053.Mar 25 2017, 12:27 PM

Updated with support for INSERT_VECTOR_ELT which is used by the i686 tests - and BUILD_VECTOR is tested with the x86_64 tests.

RKSimon updated this revision to Diff 93484.Mar 30 2017, 8:37 AM

Rebased and updated ComputeNumSignBitsForTargetNode doxygen comment based on similar feedback in D31249.

Any further feedback?

filcab accepted this revision.Mar 31 2017, 5:46 AM

LGTM. I'd prefer you split this into:

  • Commit just changing what is already there (build_vector/extract_vector_elt support)
  • Commit adding the INSERT_VECTOR_ELT support

But it's not a strong requirement.

Thank you,
Filipe

This revision is now accepted and ready to land.Mar 31 2017, 5:46 AM
This revision was automatically updated to reflect the committed changes.