[llvm] [VectorCombine] foldShuffleOfShuffles - replace IR with poison on the !NewX path (PR #201826)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 05:30:43 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: mbhade-amd
<details>
<summary>Changes</summary>
The function returns bool. The early return `return PoisonValue::get(ShuffleDstTy);` relies on implicit pointer-to-bool conversion of a non-null PoisonValue*, so the caller records a change and invalidates non-CFG analyses while the original shuffle is never replaced.
Call replaceValue(I, *PoisonValue::get(ShuffleDstTy)) and return true so the fold actually fires. Downstream InstCombine usually cleans up the residual shuffle via simplifyShuffleVectorInst, which masks the bug at -O2 but leaves vector-combine producing the wrong result on its own.
Adds a regression test covering the case where both inner shuffles have all-poison masks, so the merge loop never assigns NewX.
This was found as part of @<!-- -->jlebar's X86 LLVM bug hunt / FuzzX effort:
https://github.com/SemiAnalysisAI/FuzzX/tree/master/x86 : [024-foldshuffleofshuffles-poison-bool-cast](https://github.com/SemiAnalysisAI/FuzzX/tree/master/x86/bugs/024-foldshuffleofshuffles-poison-bool-cast)
cc @<!-- -->jlebar
---
Full diff: https://github.com/llvm/llvm-project/pull/201826.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/VectorCombine.cpp (+5-2)
- (modified) llvm/test/Transforms/VectorCombine/X86/shuffle-of-shuffles.ll (+13)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index fc6a3c26708d3..db812745f1df5 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -3026,8 +3026,11 @@ bool VectorCombine::foldShuffleOfShuffles(Instruction &I) {
}
}
- if (!NewX)
- return PoisonValue::get(ShuffleDstTy);
+ if (!NewX) {
+ replaceValue(I, *PoisonValue::get(ShuffleDstTy));
+ return true;
+ }
+
if (!NewY)
NewY = PoisonValue::get(ShuffleSrcTy);
diff --git a/llvm/test/Transforms/VectorCombine/X86/shuffle-of-shuffles.ll b/llvm/test/Transforms/VectorCombine/X86/shuffle-of-shuffles.ll
index 627b1e341f86c..faa28bd7e5155 100644
--- a/llvm/test/Transforms/VectorCombine/X86/shuffle-of-shuffles.ll
+++ b/llvm/test/Transforms/VectorCombine/X86/shuffle-of-shuffles.ll
@@ -105,6 +105,19 @@ define void @PR161980(<4 x i64> %a, <4 x i64> %b, ptr %dst) {
ret void
}
+; inner shuffle masks are entirely poison - merged mask references no real source, fold to poison
+
+define <4 x i32> @concat_inner_shuffles_all_poison_masks(<4 x i32> %x, <4 x i32> %y) {
+; CHECK-LABEL: define <4 x i32> @concat_inner_shuffles_all_poison_masks(
+; CHECK-SAME: <4 x i32> [[X:%.*]], <4 x i32> [[Y:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: ret <4 x i32> poison
+;
+ %a = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 poison, i32 poison, i32 poison, i32 poison>
+ %b = shufflevector <4 x i32> %y, <4 x i32> poison, <4 x i32> <i32 poison, i32 poison, i32 poison, i32 poison>
+ %r = shufflevector <4 x i32> %a, <4 x i32> %b, <4 x i32> <i32 0, i32 4, i32 1, i32 5>
+ ret <4 x i32> %r
+}
+
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; AVX: {{.*}}
; SSE: {{.*}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/201826
More information about the llvm-commits
mailing list