[llvm] [AArch64] Reduce the cost of repeated sub-shuffle (PR #139331)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Mon May 12 02:43:43 PDT 2025


================
@@ -5514,15 +5516,25 @@ InstructionCost AArch64TTIImpl::getShuffleCost(
         else
           NMask.push_back(MaskElt % LTNumElts);
       }
+      // Check if we have already generated this sub-shuffle, which means we
+      // will have already generated the output. For example a <16 x i32> splat
+      // will be the same sub-splat 4 times, which only needs to be generated
+      // once and reused.
+      auto Result =
+          PreviousCosts.insert({std::make_tuple(Source1, Source2, NMask), 0});
+      if (!Result.second)
+        continue;
----------------
SamTebbs33 wrote:

It wasn't immediately clear that `Result.second` isn't the map's entry's value and is actually whether the entry was inserted or not. Could you explain that a little in the comment?

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


More information about the llvm-commits mailing list