Skip to content

[DAG] Match some basic ISD::AVGCEILU patterns #84753

Closed
@RKSimon

Description

@RKSimon

Pulled out of Hacker's Delight, both of these are valid patterns that can be folded to ISD::AVGCEILU (assuming the target supports it):

define i4 @fixedwidth(i4 %a0, i4 %a1)  {
  %or = or i4 %a0, %a1
  %xor = xor i4 %a0, %a1
  %srl = lshr i4 %xor, 1
  %res = sub i4 %or, %srl
  ret i4 %res
}
define i4 @zext_add_inc_extract(i4 %a0, i4 %a1)  {
  %x0 = zext i4 %a0 to i5
  %x1 = zext i4 %a1 to i5
  %sum = add i5 %x0, %x1
  %inc = add i5 %sum, 1 
  %srl = lshr i5 %inc, 1
  %res = trunc i5 %srl to i4
  ret i4 %res
}

Both aarch64 and x86 have some ISD::AVGCEILU vector support, so we can test this with either - x86 already has a rather messy detectAVGPattern function that I hope we can eventually get rid of and just have a regular DAG combine, so try to keep away from that for now :)

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions