Skip to content

[DAG] Fold trunc(abdu(x,y)) and trunc(abds(x,y)) if they have sufficient leading zero/sign bits #147683

Open
@RKSimon

Description

@RKSimon

https://zig.godbolt.org/z/f3ac4Moxr

SelectionDAG has 12 nodes:
  t0: ch,glue = EntryToken
          t2: v4i16,ch = CopyFromReg t0, Register:v4i16 %0
        t5: v4i32 = zero_extend t2
          t4: v4i16,ch = CopyFromReg t0, Register:v4i16 %1
        t6: v4i32 = zero_extend t4
      t13: v4i32 = abdu t5, t6
    t9: v4i16 = truncate t13
  t11: ch,glue = CopyToReg t0, Register:v4i16 $d0, t9
  t12: ch = AArch64ISD::RET_GLUE t11, Register:v4i16 $d0, t11:1

If a ABD node has sufficient leading zero/sign bits then it should still work in a truncated type - it doesn't have to be from a zext/sext node specifically so computeKnownBits/ComputeNumSignBits should probably be used.

  • Create alive2 links to prove when abd patterns can be safely truncated
  • Add test coverage (using aarch64 intrinsics is probably easiest as that will always start from ISD::ABDU/S nodes)
  • Add suitable folds in DAGCombiner::visitTRUNCATE - including legality checks

Metadata

Metadata

Assignees

Labels

good first issuehttps://github.com/llvm/llvm-project/contributellvm:SelectionDAGSelectionDAGISel as well

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions