[PATCH] D147373: [VectorCombine] fold vector reverse loops
Zhengyang Liu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 1 03:17:21 PDT 2023
liuz created this revision.
liuz added reviewers: spatel, RKSimon, hfinkel, efriedma, craig.topper, lebedev.ri, nemanjai.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
liuz requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.
LLVM's auto-vectorizer sometimes generates silly reverse loops, where a value is reversed by a shuffle, followed by some arithmetic, and then get reversed back.
For example, LLVM compiles this code sequence:
do {
if (*--p == '.') *p = '_';
} while (p != name);
into
%1 = shufflevector <32 x i8> %0, poison, <31, 30, 29, 28, 27, ... 4, 3, 2, 1, 0>
%2 = icmp eq <32 x i8> %1, <46, 46, 46, 46, 46, ... 46, 46, 46, 46, 46>
%3 = shufflevector <32 x i1> %2, poison, <31, 30, 29, 28, 27, ... 4, 3, 2, 1, 0>
Obviously reverse shuffle %1 and %3 are redundant, and the sequence can be optimized into
%1 = icmp eq <32 x i8> %0, <46, 46, 46, 46, 46, ... 46, 46, 46, 46, 46>
This sequence is found in gzip's `make_simple_name` function.
This patch implements this rule in VectorCombine. Currently it works when %2 is a `cmp` instruction comparing with an splat constant. I will add other cases in the future passes.
The test cases in this patch are validated with Alive2.
This rewrite pattern is found by the Minotaur superoptimizer (https://github.com/minotaur-toolkit/minotaur).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147373
Files:
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
llvm/test/Transforms/VectorCombine/reverse-loop.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147373.510199.patch
Type: text/x-patch
Size: 20455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230401/46c3d6ac/attachment.bin>
More information about the llvm-commits
mailing list