[clang] [llvm] [VectorCombine] Shrink loads used in shufflevector rebroadcasts (PR #128938)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 11 01:24:45 PDT 2025
================
@@ -3483,6 +3487,125 @@ bool VectorCombine::foldInterleaveIntrinsics(Instruction &I) {
return true;
}
+// Attempt to shrink loads that are only used by shufflevector instructions.
+bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
+ auto *OldLoad = dyn_cast<LoadInst>(&I);
+ if (!OldLoad || !OldLoad->isSimple())
+ return false;
+
+ auto *OldLoadTy = dyn_cast<FixedVectorType>(OldLoad->getType());
+ if (!OldLoadTy)
+ return false;
+
+ unsigned const OldNumElements = OldLoadTy->getNumElements();
+
+ // Search all uses of load. If all uses are shufflevector instructions, and
+ // the second operands are all poison values, find the minimum and maximum
+ // indices of the vector elements referenced by all shuffle masks.
+ // Otherwise return `std::nullopt`.
+ using IndexRange = std::pair<int, int>;
+ auto GetIndexRangeInShuffles = [&]() -> std::optional<IndexRange> {
+ IndexRange OutputRange = IndexRange(OldNumElements, -1);
+ for (auto &Use : I.uses()) {
----------------
RKSimon wrote:
do you have test cases with multiple uses?
https://github.com/llvm/llvm-project/pull/128938
More information about the llvm-commits
mailing list