[llvm] [AArch64] Add SVE shuffle optimization pass (PR #193951)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 18 09:44:57 PDT 2026


================
@@ -0,0 +1,292 @@
+//===------- SVEShuffleOpts - SVE Shuffle Optimization --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Tries to pattern match and combine scalable vector shuffles that could
+// be more efficiently performed by tbl instructions.
+//
+// An example would be a loop with 4 multiply-accumulate reductions, where the
+// new data in each vector iterations comes from a 4-way deinterleaving of
+// smaller datatypes loaded from memory which are then zero extended.
+//
+// Something like the following:
+//   %bgra = call ... @llvm.masked.load
+//   %deinterleave = call ... @llvm.vector.deinterleave4(%bgra)
+// If the load was of a <vscale x 8 x i16>, we now have 4 deinterleaved
+// <vscale x 2 x i16> values.
+//   %b.i16 = extractvalue %deinterleave, 0
+//   %b.i64 = zext <vscale x 2 x i16> %b.i16 to <vscale x 2 x i64>
+//   %acc.b.next = add <vscale x 2 x i64> %acc.b, %b.i64
+//   <repeat for the other 3 subvectors>
+//
+// If the initial load is a legal vector rather than 4x the size (generating a
+// structured ld4 instead), we would see multiple uunpkhi/lo instructions for
+// the extensions, followed by uzp1/2 instructions for the deinterleave.
+// Instead, we can replace all of those with 4 tbl instructions. The tradeoff,
+// of course, is that we now have 4 mask values to maintain which increases
----------------
huntergr-arm wrote:

done.

https://github.com/llvm/llvm-project/pull/193951


More information about the llvm-commits mailing list