Skip to content

[WebAssembly] [Backend] Draft pull request for #129441 #145108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

badumbatish
Copy link

I'm hooking up dagcombine for AND(AND(AND(...), SHUFFLE(...)), SHUFFLE(...)) to reduce it to all_true.
I'm unsure why the hook for AND is not triggered when there are AND nodes as input to SelectionDAG. No nodes showed up as AND in:

SDValue
WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
                                             DAGCombinerInfo &DCI) const {
  // N->print(llvm::errs());
  // std::cout << "\n";

llvm ir Godbolt link: https://godbolt.org/z/qYEvPn1KW

Local input to selection dag:

Initial selection DAG: %bb.0 'bar:entry'
SelectionDAG has 21 nodes:
          t2: v4i32 = WebAssemblyISD::ARGUMENT TargetConstant:i32<0>
        t3: v16i8 = bitcast t2
        t5: v16i8 = BUILD_VECTOR Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>
      t7: v16i1 = setcc t3, t5, setne:ch
    t8: v16i8 = sign_extend t7
  t9: v4i32 = bitcast t8
    t11: v4i32 = vector_shuffle<2,3,u,u> t9, poison:v4i32
  t12: v4i32 = and t9, t11
    t0: ch,glue = EntryToken
            t13: v4i32 = vector_shuffle<1,u,u,u> t12, poison:v4i32
          t14: v4i32 = and t12, t13
        t17: i32 = extract_vector_elt t14, Constant:i64<0>
      t18: i1 = setcc t17, Constant:i32<0>, setne:ch
    t19: i32 = zero_extend t18
  t20: ch = WebAssemblyISD::RETURN t0, t19



Combining: t20: ch = WebAssemblyISD::RETURN t0, t19

Combining: t19: i32 = zero_extend t18
Creating constant: t21: i1 = Constant<-1>
Creating constant: t22: i1 = Constant<0>

Combining: t18: i1 = setcc t17, Constant:i32<0>, setne:ch

Combining: t17: i32 = extract_vector_elt t14, Constant:i64<0>

Combining: t16: i64 = Constant<0>

Combining: t15: i32 = Constant<0>

Combining: t14: v4i32 = and t12, t13

Combining: t13: v4i32 = vector_shuffle<1,u,u,u> t12, poison:v4i32

Combining: t12: v4i32 = and t9, t11

Combining: t11: v4i32 = vector_shuffle<2,3,u,u> t9, poison:v4i32

Combining: t10: v4i32 = poison

Combining: t9: v4i32 = bitcast t8

Combining: t8: v16i8 = sign_extend t7
Creating new node: t23: v16i8 = setcc t3, t5, setne:ch
 ... into: t23: v16i8 = setcc t3, t5, setne:ch

Combining: t23: v16i8 = setcc t3, t5, setne:ch

Combining: t9: v4i32 = bitcast t23

Combining: t6: ch = setne

Combining: t5: v16i8 = BUILD_VECTOR Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>, Constant:i8<0>
Creating new node: t24: v16i8 = splat_vector Constant:i8<0>
 ... into: t24: v16i8 = splat_vector Constant:i8<0>

Combining: t24: v16i8 = splat_vector Constant:i8<0>

Combining: t23: v16i8 = setcc t3, t24, setne:ch

Combining: t4: i8 = Constant<0>

Combining: t3: v16i8 = bitcast t2

Combining: t2: v4i32 = WebAssemblyISD::ARGUMENT TargetConstant:i32<0>

Combining: t1: i32 = TargetConstant<0>

Combining: t0: ch,glue = EntryToken

Optimized lowered selection DAG: %bb.0 'bar:entry'
SelectionDAG has 20 nodes:
        t2: v4i32 = WebAssemblyISD::ARGUMENT TargetConstant:i32<0>
      t3: v16i8 = bitcast t2
      t24: v16i8 = splat_vector Constant:i8<0>
    t23: v16i8 = setcc t3, t24, setne:ch
  t9: v4i32 = bitcast t23
    t11: v4i32 = vector_shuffle<2,3,u,u> t9, poison:v4i32
  t12: v4i32 = and t9, t11
    t0: ch,glue = EntryToken
            t13: v4i32 = vector_shuffle<1,u,u,u> t12, poison:v4i32
          t14: v4i32 = and t12, t13
        t17: i32 = extract_vector_elt t14, Constant:i64<0>
      t18: i1 = setcc t17, Constant:i32<0>, setne:ch
    t19: i32 = zero_extend t18
  t20: ch = WebAssemblyISD::RETURN t0, t19

I'm hooking up dagcombine for AND(AND(AND(...), SHUFFLE(...)), SHUFFLE(...)) to reduce it to all_true.
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@badumbatish badumbatish changed the title Draft pull request for #129441 [WebAssembly] [Backend] Draft pull request for #129441 Jun 20, 2025
@lukel97
Copy link
Contributor

lukel97 commented Jun 20, 2025

I'm unsure why the hook for AND is not triggered when there are AND nodes as input to SelectionDAG.

For the generic DAG nodes like ISD::AND you need to tell SelectionDAG that your target wants to perform custom combines on them by calling setTargetDAGCombine(ISD::AND); somewhere in the WebAssemblyTargetLowering constructor. Does that fix what you're seeing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy