Skip to content

[DAG] Match some basic ISD::AVGFLOORU patterns #84749

Closed
@RKSimon

Description

@RKSimon

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

define i4 @fixedwidth(i4 %a0, i4 %a1)  {
  %and = and i4 %a0, %a1
  %xor = xor i4 %a0, %a1
  %srl = lshr i4 %xor, 1
  %res = add i4 %and, %srl
  ret i4 %res
}

define i4 @zext_add_extract(i4 %a0, i4 %a1)  {
  %x0 = zext i4 %a0 to i5
  %x1 = zext i4 %a1 to i5
  %sum = add i5 %x0, %x1
  %srl = lshr i5 %sum, 1
  %res = trunc i5 %srl to i4
  ret i4 %res
}

These will need aarch64 vector tests as thats the only target that has legal ISD::AVGFLOORU instructions so far.

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