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

[DAG] SelectionDAG::ComputeNumSignBits - add ISD::ABDS handling

Open RKSimon opened this issue 10 months ago • 7 comments

We can probably handle this best by thinking in terms of the abds(lhs, rhs) -> sub(smax(lhs,rhs), smin(lhs,rhs)) expansion:

numsignbits = max(sub(min(numsignbits(lhs),numsignbits(rhs)),1),1)

Although I'm sure there will be special cases that can improve on that.

Test coverage probably easiest to add to aarch64 which has neon support for ABDS instructions - either in codegen tests or via AArch64SelectionDAGTest.cpp

RKSimon avatar Jan 09 '26 12:01 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 Jan 09 '26 12:01 llvmbot

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

Author: Simon Pilgrim (RKSimon)

We can probably handle this best by thinking in terms of the `abds(lhs, rhs) -> sub(smax(lhs,rhs), smin(lhs,rhs))` expansion:

numsignbits = max(sub(min(numsignbits(lhs),numsignbits(rhs)),1),1)

Although I'm sure there will be special cases that can improve on that.

Test coverage probably easiest to add to aarch64 which has neon support for ABDS instructions - either in codegen tests or via AArch64SelectionDAGTest.cpp

llvmbot avatar Jan 09 '26 12:01 llvmbot

@RKSimon can i work on this?

Xylecrack avatar Jan 09 '26 12:01 Xylecrack

@RKSimon I've fixed this issue, since it's my first contribution, could you please review it to see if it's implemented correctly?

cpist avatar Jan 10 '26 12:01 cpist

@cpist I thought @Xylecrack was working on it?

RKSimon avatar Jan 10 '26 13:01 RKSimon

@RKSimon Oh! Based on what you said, I thought this might be what you meant, so I gave it a try. In that case, I'll wait for Xylecrack to post their results. After then, check if I did it correctly after looking at the content.

cpist avatar Jan 10 '26 13:01 cpist

Confirmed that the computeKnownBits handling already covers this - #175321 is now about improving test coverage.

RKSimon avatar Jan 14 '26 17:01 RKSimon