[GlobalISel] Port known-bit and known-sign-bits for all operations
gI was going through the SDAG version of computeKnownBits and computeSignBits to see what was missing from GISel. This is a list of all the nodes that SDAG tries to handle and their current status is GISel. Some nodes have no equivalent in GISel. Missing nodes will presumably need to be ported over, under the assumption that they will eventually be useful somewhere. Some of the examples like https://github.com/llvm/llvm-project/pull/141933 and https://github.com/llvm/llvm-project/pull/142355 make a good example of what kind of thing needs to be added and how tests can be written.
| SDAG computeKnownBits | Status |
|---|---|
| MERGE_VALUES | Not relevant |
| SPLAT_VECTOR | Done |
| SPLAT_VECTOR_PARTS | Not relevant |
| STEP_VECTOR | Done |
| BUILD_VECTOR | Done |
| VECTOR_SHUFFLE | Done |
| VSCALE | Done |
| CONCAT_VECTORS | Done |
| INSERT_SUBVECTOR | Done |
| EXTRACT_SUBVECTOR | Done |
| SCALAR_TO_VECTOR | Not relevant |
| BITCAST | #216287 |
| AND | Done |
| OR | Done |
| XOR | Done |
| MUL | Done |
| MULHU | Done |
| MULHS | Done |
| ABDU | Done |
| ABDS | Done |
| UMUL_LOHI | Not relevant |
| SMUL_LOHI | Not relevant |
| AVGFLOORU | Done |
| AVGCEILU | Done |
| AVGFLOORS | Done |
| AVGCEILS | Done |
| SELECT | Done |
| VSELECT | Not relevant |
| SELECT_CC | Not relevant |
| SETCC | Done |
| SETCCCARRY | Not relevant |
| STRICT_FSETCC | Not relevant |
| STRICT_FSETCCS | Not relevant |
| SHL | Done |
| SRL | Done |
| SRA | Done |
| ROTL | Done |
| ROTR | Done |
| FSHL | Done |
| FSHR | Done |
| SHL_PARTS | Not relevant |
| SRA_PARTS | Not relevant |
| SRL_PARTS | Not relevant |
| SIGN_EXTEND_INREG | Done |
| CTTZ | Done |
| CTTZ_ZERO_UNDEF | Done |
| CTLZ | Done |
| CTLZ_ZERO_UNDEF | Done |
| CTPOP | Done |
| PARITY | Not relevant |
| MGATHER | No node yet |
| MLOAD | No node yet |
| LOAD | Done |
| ZERO_EXTEND_VECTOR_INREG | Not relevant |
| ZERO_EXTEND | Done |
| SIGN_EXTEND_VECTOR_INREG | Not relevant |
| SIGN_EXTEND | Done |
| ANY_EXTEND_VECTOR_INREG | Not relevant |
| ANY_EXTEND | Done |
| TRUNCATE | Done |
| AssertZext | Done |
| AssertAlign | Done |
| FGETSIGN | Not relevant |
| ADD | Done |
| SUB | Done |
| USUBO | Done |
| SSUBO | Done |
| USUBO_CARRY | Done |
| SSUBO_CARRY | Done |
| UADDO | Done |
| SADDO | Done |
| UADDO_CARRY | Done |
| SADDO_CARRY | Done |
| SMULO | Done |
| UMULO | Done |
| UDIV | Done |
| SDIV | Done |
| SREM | Done |
| UREM | Done |
| EXTRACT_ELEMENT | Not relevant |
| EXTRACT_VECTOR_ELT | Done |
| INSERT_VECTOR_ELT | Done |
| BITREVERSE | Done |
| BSWAP | Done |
| ABS | Done |
| USUBSAT | Done |
| UMIN | Done |
| UMAX | Done |
| SMIN | Done |
| SMAX | Done |
| UINT_TO_FP | Possibly not relevant |
| SINT_TO_FP | Possibly not relevant |
| FP_TO_UINT_SAT | Probably not relevant |
| ATOMIC_LOAD | Possibly not relevant |
| ATOMIC_CMP_SWAP_WITH_SUCCESS | Possibly not relevant |
| ATOMIC_CMP_SWAP | Possibly not relevant |
| ATOMIC_SWAP | Possibly not relevant |
| ATOMIC_LOAD_ADD | Possibly not relevant |
| ATOMIC_LOAD_SUB | Possibly not relevant |
| ATOMIC_LOAD_AND | Possibly not relevant |
| ATOMIC_LOAD_CLR | Possibly not relevant |
| ATOMIC_LOAD_OR | Possibly not relevant |
| ATOMIC_LOAD_XOR | Possibly not relevant |
| ATOMIC_LOAD_NAND | Possibly not relevant |
| ATOMIC_LOAD_MIN | Possibly not relevant |
| ATOMIC_LOAD_MAX | Possibly not relevant |
| ATOMIC_LOAD_UMIN | Possibly not relevant |
| ATOMIC_LOAD_UMAX | Possibly not relevant |
| FrameIndex | Done |
| TargetFrameIndex | Not relevant |
| SDAG computeNumSignBits | Status |
|---|---|
| ISD::AssertSext | Done |
| ISD::AssertZext | Not necessary |
| ISD::MERGE_VALUES | Not relevant |
| ISD::SPLAT_VECTOR | Done |
| ISD::BUILD_VECTOR | Done |
| ISD::VECTOR_SHUFFLE | Done |
| ISD::BITCAST | #220317 |
| ISD::FP_TO_SINT_SAT | Probably not relevant |
| ISD::SIGN_EXTEND | Done |
| ISD::SIGN_EXTEND_INREG | Done |
| ISD::SIGN_EXTEND_VECTOR_INREG | Not relevant |
| ISD::SRA | Done |
| ISD::SHL | Done |
| ISD::AND | Done |
| ISD::OR | Done |
| ISD::XOR | Done |
| ISD::SELECT | Done |
| ISD::VSELECT | Done |
| ISD::SMIN | Done |
| ISD::SMAX | Done |
| ISD::UMIN | Done |
| ISD::UMAX | Done |
| ISD::SSUBO_CARRY | Done |
| ISD::USUBO_CARRY | Done |
| ISD::SADDO | Done |
| ISD::UADDO | Done |
| ISD::SADDO_CARRY | Done |
| ISD::UADDO_CARRY | Done |
| ISD::SSUBO | Done |
| ISD::USUBO | Done |
| ISD::SMULO | Done |
| ISD::UMULO | Done |
| ISD::SETCC | Done |
| ISD::SETCCCARRY | Not relevant |
| ISD::STRICT_FSETCC | Not relevant |
| ISD::STRICT_FSETCCS | Not relevant |
| ISD::ROTL | Done |
| ISD::ROTR | Done |
| ISD::ADD | Done |
| ISD::SUB | Done |
| ISD::MUL | #229766 |
| ISD::AVGCEILS | Done |
| ISD::AVGFLOORS | Done |
| ISD::SREM | Done |
| ISD::TRUNCATE | Done |
| ISD::EXTRACT_ELEMENT | Not relevant |
| ISD::INSERT_VECTOR_ELT | #220842 / #213480 |
| ISD::EXTRACT_VECTOR_ELT | Done |
| ISD::EXTRACT_SUBVECTOR | Done |
| ISD::CONCAT_VECTORS | Done |
| ISD::INSERT_SUBVECTOR | #220976 |
| ISD::LOAD | Done |
| ISD::ATOMIC_CMP_SWAP | Possibly not relevant |
| ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS | Possibly not relevant |
| ISD::ATOMIC_SWAP | Possibly not relevant |
| ISD::ATOMIC_LOAD_ADD | Possibly not relevant |
| ISD::ATOMIC_LOAD_SUB | Possibly not relevant |
| ISD::ATOMIC_LOAD_AND | Possibly not relevant |
| ISD::ATOMIC_LOAD_CLR | Possibly not relevant |
| ISD::ATOMIC_LOAD_OR | Possibly not relevant |
| ISD::ATOMIC_LOAD_XOR | Possibly not relevant |
| ISD::ATOMIC_LOAD_NAND | Possibly not relevant |
| ISD::ATOMIC_LOAD_MIN | Possibly not relevant |
| ISD::ATOMIC_LOAD_MAX | Possibly not relevant |
| ISD::ATOMIC_LOAD_UMIN | Possibly not relevant |
| ISD::ATOMIC_LOAD_UMAX | Possibly not relevant |
| ISD::ATOMIC_LOAD | Possibly not relevant |
The vector_inreg* nodes will be relevant, we just haven't added the equivalents yet
I would expect that these would be the most sensible things to add to begin with if anyone is interested in getting involved. computeKnownBits: G_EXTRACT_VECTOR_ELT, G_INSERT_VECTOR_ELT, G_ABS, G_FSHL, G_FSHR, G_ROTL, G_ROTR,
computeNumSignBits: G_EXTRACT_VECTOR_ELT, G_INSERT_VECTOR_ELT, G_SHL G_SUB G_MUL
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:
- 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.
- 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.
- Fix the issue locally.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - 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.
@llvm/issue-subscribers-good-first-issue
Author: David Green (davemgreen)
...
@davemgreen I would like to work on this.
@davemgreen I would like to work on this.
Sounds good - there is plenty to do. Pick a node and see what you can come up with.
Hi @davemgreen, I submitted a PR to port computeNumSignBits for SHL. The test passes, but I’m unsure if it’s fully correct since this change didn’t seem to affect any existing tests. Could you take a look and let me know if the approach and test coverage look good?
Nice one, I've added it to the page above. We might not have a lot of test coverage so far - I am hoping that if it was useful to SDAG then it will be useful to GISel.
Hi @davemgreen, I have submitted a PR for porting G_ABS to computeKnownBitsImpl. I ran the existing tests, but I am not sure how to add tests for my changes (as the test files seem to be generated).
Looks good. Some of the patches like #141933 and #152067 have example mir test that test the known-bits and sign-bits for the operations they were adding.
I have put up #158445
Hi @davemgreen, I have submitted a PR (#158384) for porting G_SUB to computeNumSignBits. I added the mir test for the known-bits and sign-bits, also added some unit test for SelectionDAG.
It seems porting ADD and ADDC is quite similar to SUB, so I will work on ADD and ADDC for computeNumSignBits next.
Very nice. I've added it to the table.
The PR for porting G_ADD to computeNumSignBits is up: #159202.
Funny thing, I cannot seem to find the opcode G_ADDC. Is that expected? Should I add one? If so, is there an example?
I might be wrong, but I guess ADDC corresponds to https://llvm.org/docs/GlobalISel/GenericOpcode.html#g-uadde-g-sadde-g-usube-g-ssube
I'll wait for a maintainer to confirm it though (I might be wrong).
I might be wrong, but I guess
ADDCcorresponds to https://llvm.org/docs/GlobalISel/GenericOpcode.html#g-uadde-g-sadde-g-usube-g-ssubeI'll wait for a maintainer to confirm it though (I might be wrong).
Ah thanks for showing me this page! I haven't seen it before!
I don't know enough to tell either. One additional information is that G_UADDE/G_SADDE/G_USUBE/G_SSUBE is already handled to computeKnownBits in a change from 3 years ago. Yet David still marked ADDC as a TODO item in the issue description.
Let's wait to see what the experts say. :)
Oh yeah, it looks like I missed that one when comparing the lists. It's a deprecated opcode in SDAG so lets remove it from the table.
Hi @davemgreen , I would love to take up this issue
Hi @davemgreen , I would love to take up this issue
Which opcode interests you? The table at the top should be pretty much up to date and this ticket is trying to spread the pain :)
Hi, I have a quick question regarding this issue. Do you recommend submitting a single PR that ports multiple opcodes at once, or is it better to submit them one or two at a time? Some opcodes are straightforward to port, so I am not sure if submitting many small PRs might cause too much friction. I want to make sure I’m following the preferred workflow for reviewers.
Also, since there are many opcodes still available, is this issue intended specifically for newcomers to pick up, or is it okay if a few people tackle larger chunks? Any feedback is welcome!