[llvm] [VectorCombine] Skip dead shufflevector in GetIndexRangeInShuffles to fix crash. (PR #179217)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 2 04:10:08 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: Florian Hahn (fhahn)

<details>
<summary>Changes</summary>

Update GetIndexRangeInShuffles to skip unused shuffles. This matches the behavior in the loop below and without it, we end up with an index mis-match, causing a crash for the added test case.

---
Full diff: https://github.com/llvm/llvm-project/pull/179217.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/VectorCombine.cpp (+5) 
- (modified) llvm/test/Transforms/VectorCombine/load-shufflevector.ll (+16) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 1746d3e4b06f4..84ea8d81a7c46 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -5447,6 +5447,11 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
 
       for (llvm::Use &Use : I.uses()) {
         auto *Shuffle = cast<ShuffleVectorInst>(Use.getUser());
+
+        // Ignore shufflevector instructions that have no uses.
+        if (Shuffle->use_empty())
+          continue;
+
         ArrayRef<int> OldMask = Shuffle->getShuffleMask();
 
         // Create entry for new use.
diff --git a/llvm/test/Transforms/VectorCombine/load-shufflevector.ll b/llvm/test/Transforms/VectorCombine/load-shufflevector.ll
index 55a20d4489723..2692cb2d8c2b7 100644
--- a/llvm/test/Transforms/VectorCombine/load-shufflevector.ll
+++ b/llvm/test/Transforms/VectorCombine/load-shufflevector.ll
@@ -425,3 +425,19 @@ define <8 x i16> @shuffle_with_poison_mask(ptr %p) {
   %shuf = shufflevector <8 x i16> %pre, <8 x i16> poison, <8 x i32> <i32 1, i32 3, i32 poison, i32 poison, i32 poison, i32 5, i32 poison, i32 7>
   ret <8 x i16> %shuf
 }
+
+; Verify that dead shuffle uses (with indices outside the range of used
+; shuffles) are properly skipped when shrinking loads.
+define <2 x double> @shuffle_with_dead_use(ptr %p) {
+; CHECK-LABEL: define <2 x double> @shuffle_with_dead_use(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 16
+; CHECK-NEXT:    [[TMP2:%.*]] = load <1 x double>, ptr [[TMP1]], align 8
+; CHECK-NEXT:    [[SHUF2:%.*]] = shufflevector <1 x double> [[TMP2]], <1 x double> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    ret <2 x double> [[SHUF2]]
+;
+  %load = load <3 x double>, ptr %p, align 8
+  %shuf1 = shufflevector <3 x double> %load, <3 x double> poison, <2 x i32> <i32 0, i32 2>
+  %shuf2 = shufflevector <3 x double> %load, <3 x double> poison, <2 x i32> <i32 2, i32 2>
+  ret <2 x double> %shuf2
+}

``````````

</details>


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


More information about the llvm-commits mailing list