llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[DAG] computeKnownBits/ComputeNumSignBits - add ISD::VECTOR_COMPRESS integer vector types handling and test coverage

Open RKSimon opened this issue 1 year ago • 7 comments

  /// VECTOR_COMPRESS(Vec, Mask, Passthru)
  /// consecutively place vector elements based on mask
  /// e.g., vec = {A, B, C, D} and mask = {1, 0, 1, 0}
  ///         --> {A, C, ?, ?} where ? is undefined
  /// If passthru is defined, ?s are replaced with elements from passthru.
  /// If passthru is undef, ?s remain undefined.
  VECTOR_COMPRESS,

computeKnownBits should return the common knownbits between the Vec and PassThru values

ComputeNumSignBits should return the minimum of the num signbits of the Vec and PassThru values

If PassThru is undef you should earlyout and return knownbits = unknown / signbits = 1

You should probably ignore the computeKnownBits/ComputeNumSignBits DemandedElts parameter and analyse all vector elements of both operands.

RKSimon avatar Sep 12 '25 17:09 RKSimon

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
  2. Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

llvmbot avatar Sep 12 '25 17:09 llvmbot

@llvm/issue-subscribers-good-first-issue

Author: Simon Pilgrim (RKSimon)

``` /// VECTOR_COMPRESS(Vec, Mask, Passthru) /// consecutively place vector elements based on mask /// e.g., vec = {A, B, C, D} and mask = {1, 0, 1, 0} /// --> {A, C, ?, ?} where ? is undefined /// If passthru is defined, ?s are replaced with elements from passthru. /// If passthru is undef, ?s remain undefined. VECTOR_COMPRESS, ``` computeKnownBits should return the common knownbits between the Vec and PassThru values

ComputeNumSignBits should return the minimum of the num signbits of the Vec and PassThru values

If PassThru is undef you should earlyout and return knownbits = unknown / signbits = 1

You should probably ignore the computeKnownBits/ComputeNumSignBits DemandedElts parameter and analyse all vector elements of both operands.

llvmbot avatar Sep 12 '25 17:09 llvmbot

Hi, I would like to contribute. May I be assigned this issue @RKSimon?

KavinTheG avatar Sep 12 '25 17:09 KavinTheG

Hey @RKSimon, just for some clarification, can the mask vector be ignored, or should that be taken into consideration?

KavinTheG avatar Sep 15 '25 19:09 KavinTheG

Yes under most circumstances the mask must ignored and all elements of the other two sources demanded. If the mask is constant it's possible to compute the different demanded elements for the two sources but that can be a TODO for now.

RKSimon avatar Sep 15 '25 20:09 RKSimon

My apologies but are there any resources for writing tests? Any test cases for the other computeKnownBits isd operations? Thanks! @RKSimon

KavinTheG avatar Sep 16 '25 18:09 KavinTheG

Plenty a good starter would be this one for knownbits:

define <8 x i64> @test_compress_zext_v8i16_8i64(<8 x i16> %vec, <8 x  i1> %mask, <8 x i64> %passthru) nounwind {
  %xvec = zext <8 x i16> %vec to <8 x i64> ;  0 -> 65535
  %xpassthru = and <8 x i64> %passthru, splat (i64 3) ; 0 -> 3
  %out = call <8 x i64> @llvm.experimental.vector.compress(<8 x i64> %xvec, <8 x  i1> %mask, <8 x i64> %xpassthru)
  %res = and <8 x i64> %out, splat (i64 65535) unnecessary - %out guaranteed to be 0 -> 65535
  ret <8 x i64> %res
}

RKSimon avatar Sep 17 '25 08:09 RKSimon