[PATCH] D120571: [CGP, AArch64] Replace zexts with shuffle that can be lowered using tbl.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 25 09:30:02 PST 2022


fhahn created this revision.
fhahn added reviewers: t.p.northover, ab, dmgreen, paquette.
Herald added subscribers: hiraditya, kristof.beyls.
fhahn requested review of this revision.
Herald added a project: LLVM.

This patch extends CodeGenPrepare to lower zext v16i8 -> v16i32 in loops
using a wide shuffle  creating a v64i8 vector, selecting groups of 3
zero elements and an element from the input.

This is profitable on AArch64 where such shuffles can be lowered to tbl
instructions, but only in loops, because it requires materializing 4
masks, which can be done in the loop preheader.

This is the only reason the transform is part of CGP. If there's a
better alternative I missed, please let me know. The same goes for the
shouldReplaceZExtWithShuffle hook which guards this. I am not sure if
this transform will be beneficial on other targets, but it seems like
there is no way other convenient way.

This improves the generated code for loops like the one below in
combination with D96522 <https://reviews.llvm.org/D96522>.

  int foo(uint8_t *p, int N) {
    unsigned long long sum = 0;
    for (int i = 0; i < N ; i++, p++) {

unsigned int v = *p;
	sum += (v < 127) ? v : 256 - v;

    }
    return sum;
  }

https://clang.godbolt.org/z/Wco866MjY


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120571

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/test/CodeGen/AArch64/vselect-ext.ll
  llvm/test/CodeGen/AArch64/zext-to-tbl.ll
  llvm/test/Transforms/CodeGenPrepare/AArch64/zext-to-shuffle.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120571.411435.patch
Type: text/x-patch
Size: 13793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220225/0e56d514/attachment.bin>


More information about the llvm-commits mailing list