[PATCH] D149742: [SLP]Improve isGatherShuffledEntry by trying per-register shuffle.

Alexey Bataev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 04:21:18 PDT 2023


ABataev added a comment.

In D149742#4587735 <https://reviews.llvm.org/D149742#4587735>, @RKSimon wrote:

> Why are we doing this in SLP and not TTI getShuffleCost? It looks like TTI should be doing a better job of recognizing how it should split the shuffle mask and determine the shuffle kinds per split?

I thought about this. Unfortunately, TTI is too late here + it does not have idion of TreeEntry.

What this function does? It scans the list of scalars and then checks, if it can build a shuffle, using previously build TreeEntries (use previously build vector to build the new one) to reduce number of inserts.
It supports only 1- and 2-vector shuffles, as 3- and more vector shuffles may not be effective for some targets.
Why cannot it be done in TTI? 1. TTI does not know about TreeEntries. 2. Without this knowledge it won't help in complex situations.

Assume we have 3 already built TreeEntries: <abcd>, <efgh>, <ijkl>. But the actual vector register includes only 2 elements (i.e. each this vector uses 2 vector registers). And we trying to build a new buildvector (NeedToGather) entry with elements <acih>.
Original function will help to translate this gather node into this:

  %s1 = shuffle <abcd>, <efgh>, <0,2,poison,7>
  %v = insertelement %s1, i, 2 - might be very cost ineffective + there might be several such inserts, increasing the overall cost of the buildvector/gather node.

This reworked function can do this:

  %s1 = shuffle <abcd>, poison, <0,2>
  %s2 = shuffle <efgh>, <ijkl>, <4,3>
  %v = shuffle %s1, %s2, <0,1,2,3> - free insert subvector shuffle

TTI won't be able to transform the first variant to the second one without knowing that there is <ijkl> vector already exists. It requires teaching it about the whole SLP graph idiom.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149742/new/

https://reviews.llvm.org/D149742



More information about the llvm-commits mailing list