[PATCH] D119072: [DAGCombine] Move AVG combine to SimplifyDemandBits

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 6 01:34:15 PST 2022


dmgreen created this revision.
dmgreen added reviewers: RKSimon, spatel, efriedma, craig.topper, lebedev.ri.
Herald added subscribers: ecnelises, hiraditya.
dmgreen requested review of this revision.
Herald added a project: LLVM.

Pulled out of D106237 <https://reviews.llvm.org/D106237>, this moves the matching of AVGFloor and AVGCeil into a place where demand bit are available, so that it can detect more cases for more folds. It changes the transform to start from a shift, not from a truncate. We match the pattern `shr(add(ext(A), ext(B)), 1)`, transforming to `ext(hadd(A, B))`.

For signed values, because only the bottom bits are demanded llvm will transform the above to use a lshr too, as opposed to ashr. In order to correctly detect the hadd we need to know the demanded bits to turn it back. Depending on whether the shift is signed (ashr) or logical (lshr), and the extensions are signed or unsigned we can create different nodes.
If the shift is signed:
Needs >= 2 sign bits. https://alive2.llvm.org/ce/z/h4gQAW generating signed rhadd.
Needs >= 2 zero bits. https://alive2.llvm.org/ce/z/B64DUA generating unsigned rhadd.
If the shift is unsigned:
Needs >= 1 zero bits. https://alive2.llvm.org/ce/z/ByD8sj generating unsigned rhadd.
Needs 1 demanded bit zero and >= 2 sign bits https://alive2.llvm.org/ce/z/hvPGxX and https://alive2.llvm.org/ce/z/32P5n1 generating signed rhadd.


https://reviews.llvm.org/D119072

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/test/CodeGen/AArch64/arm64-vhadd.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119072.406235.patch
Type: text/x-patch
Size: 25274 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220206/a03ed0a8/attachment.bin>


More information about the llvm-commits mailing list