This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Basic combines for AVG nodes.
ClosedPublic

Authored by dmgreen on Feb 11 2022, 9:55 AM.

Details

Summary

This adds very basic combines for AVG nodes, mostly for constant folding and handling degenerate (zero) cases. The code performs mostly same transforms as visitMULHS, adjusted fro AVG nodes.

Constant folding extends to a higher bitwidth and drops the lowest bit. Undef is transformed to 0, as the add x, undef could be treated as 0. There is also a transform for avgfloor x, 0 transforming to shr x, 1.

Diff Detail

Event Timeline

dmgreen created this revision.Feb 11 2022, 9:55 AM
dmgreen requested review of this revision.Feb 11 2022, 9:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 11 2022, 9:55 AM
RKSimon added inline comments.Feb 11 2022, 10:15 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
4693

Why 0 and not the other (not undef) arg? https://alive2.llvm.org/ce/z/tNnJR3

dmgreen added inline comments.Feb 11 2022, 10:59 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
4693

I got 0 from the "haddu_undef" tests, but I see now that they were not extending the undef, which changes how they simplify.

I went back and forth with several options, but if the "other operand" verifies then that sounds good to me.

dmgreen updated this revision to Diff 407962.Feb 11 2022, 11:11 AM

Update undef handling

RKSimon accepted this revision.Feb 13 2022, 3:02 AM

LGTM with a couple of minors

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
4690

Please add a TODO comment for scalar (avg x, 0) patterns once we have test/type coverage?

llvm/test/CodeGen/AArch64/hadd-combine.ll
664

Maybe make the undef src not v0.8h so we see the move ?

This revision is now accepted and ready to land.Feb 13 2022, 3:02 AM
foad added a subscriber: foad.Feb 13 2022, 8:42 AM
This revision was landed with ongoing or failed builds.Feb 14 2022, 3:18 AM
This revision was automatically updated to reflect the committed changes.