<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69246>69246</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SLPVectorizerPass] Assertion isValidOperands(V1, V2, Mask) in CreateShuffleVector
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
annamthomas
</td>
</tr>
</table>
<pre>
With IR below, with slp-vectorizer, we force vectorize with VF = 8 and fail with assertion in the ShuffleInstructionBuilder.finalize() when building a shuffle vector.
```
target triple = "x86_64-unknown-linux-gnu"
define void @wombat(i32 %arg) #0 {
bb:
br label %bb1
bb1: ; preds = %bb4, %bb
%phi = phi i32 [ 0, %bb4 ], [ 0, %bb ]
%phi2 = phi i32 [ 0, %bb4 ], [ 0, %bb ]
br label %bb3
bb3: ; preds = %bb1
br i1 false, label %bb4, label %bb11
bb4: ; preds = %bb25, %bb3
%phi5 = phi i32 [ 0, %bb3 ], [ 0, %bb25 ]
%phi6 = phi i32 [ %phi, %bb3 ], [ 0, %bb25 ]
%phi7 = phi i32 [ 0, %bb3 ], [ 0, %bb25 ]
%phi8 = phi i32 [ 0, %bb3 ], [ 0, %bb25 ]
%phi9 = phi i32 [ 0, %bb3 ], [ 0, %bb25 ]
%phi10 = phi i32 [ %phi2, %bb3 ], [ 0, %bb25 ]
br label %bb1
bb11: ; preds = %bb3
br i1 false, label %bb12, label %bb13
bb12: ; preds = %bb11
%add = add i32 0, 0
br label %bb13
bb13: ; preds = %bb12, %bb11
%phi14 = phi i32 [ 0, %bb11 ], [ 0, %bb12 ]
%phi15 = phi i32 [ %phi, %bb11 ], [ 0, %bb12 ]
%phi16 = phi i32 [ 0, %bb11 ], [ 0, %bb12 ]
%phi17 = phi i32 [ undef, %bb11 ], [ %arg, %bb12 ]
%phi18 = phi i32 [ undef, %bb11 ], [ %arg, %bb12 ]
%phi19 = phi i32 [ undef, %bb11 ], [ %arg, %bb12 ]
%phi20 = phi i32 [ undef, %bb11 ], [ %add, %bb12 ]
%phi21 = phi i32 [ undef, %bb11 ], [ 0, %bb12 ]
%phi22 = phi i32 [ undef, %bb11 ], [ 0, %bb12 ]
%phi23 = phi i32 [ undef, %bb11 ], [ 0, %bb12 ]
br label %bb25
bb24: ; No predecessors!
br label %bb25
bb25: ; preds = %bb24, %bb13
%phi26 = phi i32 [ 0, %bb24 ], [ %phi14, %bb13 ]
%phi27 = phi i32 [ 0, %bb24 ], [ %phi16, %bb13 ]
br label %bb4
}
attributes #0 = { "target-features"="+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-xsaves,-avx512fp16,-sm4,+sse4.1,-avx512ifma,+xsave,-avx512pf,+sse4.2,-tsxldtrk,-ptwrite,-widekl,-sm3,-invpcid,+64bit,+xsavec,-avx512vpopcntdq,+cmov,-avx512vp2intersect,-avx512cd,+movbe,-avxvnniint8,-avx512er,-amx-int8,-kl,-sha512,-avxvnni,-rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-vpclmulqdq,-avx512vl,-uintr,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,+xsaveopt,+rdrnd,-avx512f,-amx-bf16,-avx512bf16,-avx512vnni,+cx8,-avx512bw,+sse3,-pku,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,+sha,-movdir64b,-wbnoinvd,-enqcmd,-prefetchwt1,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,-avx512dq,+sse4a" }
```
We fail with:
```
Assertion failed: (isValidOperands(V1, V2, Mask) && "Invalid shuffle vector instruction operands!"), function ShuffleVectorInst, file Instructions.cpp, line 1959.
```
Backtrace is:
```
frame #4: 0x000000010288fcb3 opt`llvm::ShuffleVectorInst::ShuffleVectorInst(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>, llvm::Twine const&, llvm::Instruction*) (.cold.2) at Instructions.cpp:1958:3 [opt]
frame #5: 0x0000000101006bc4 opt`llvm::ShuffleVectorInst::ShuffleVectorInst(this=0x00006000035001a0, V1=0x000060000210a678, V2=0x0000600000210c60, Mask=ArrayRef<int> @ 0x0000600001283db0, Name=0x00007ff7bfef9150, InsertBefore=0x0000000000000000) at Instructions.cpp:1958:3 [opt]
frame #6: 0x000000010179a174 opt`llvm::IRBuilderBase::CreateShuffleVector(this=0x00007ff7bfefca18, V1=0x000060000210a678, V2=0x0000600000210c60, Mask=ArrayRef<int> @ 0x00006000012b3740, Name=0x00007ff7bfef91c8) at IRBuilder.h:2465:23 [opt]
frame #7: 0x0000000101b4dab1 opt`llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder::createShuffleVector(llvm::Value*, llvm::ArrayRef<int>) [inlined] llvm::IRBuilderBase::CreateShuffleVector(this=0x00007ff7bfefca18, V=0x000060000210a678, Mask=ArrayRef<int> @ 0x00006000012f9ac0, Name=0x00007ff7bfef91c8) at IRBuilder.h:2472:12 [opt]
frame #8: 0x0000000101b4da94 opt`llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder::createShuffleVector(this=0x00007ff7bfef9248, V1=0x000060000210a678, Mask=ArrayRef<int> @ 0x00006000012f9ac0) at SLPVectorizer.cpp:9749:28 [opt]
frame #9: 0x0000000101b4cb30 opt`llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::createShuffle(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>) [inlined] llvm::Value* (anonymous namespace)::BaseShuffleAnalysis::createShuffle<llvm::Value*, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder>(V1=0x000060000210a678, V2=<unavailable>, Mask=<unavailable>, Builder=0x00007ff7bfef9248) at SLPVectorizer.cpp:6948:22 [opt]
frame #10: 0x0000000101b4c98a opt`llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::createShuffle(this=<unavailable>, V1=<unavailable>, V2=<unavailable>, Mask=<unavailable>) at SLPVectorizer.cpp:9792:12 [opt]
frame #11: 0x0000000101b4c89a opt`llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::finalize(this=0x00007ff7bfef9768, ExtMask=ArrayRef<int> @ 0x00006000012f6a40, VF=<unavailable>, Action=function_ref<void (llvm::Value *&, llvm::SmallVectorImpl<int> &)> @ 0x00006000012f6b00)>) at SLPVectorizer.cpp:0 [opt]
frame #12: 0x0000000101b27682 opt`llvm::Value* llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder, llvm::Value*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>, llvm::slpvectorizer::BoUpSLP>(this=0x00007ff7bfefbf90, E=<unavailable>, Params=0x00007ff7bfefca18, Params=0x00007ff7bfefbf90) at SLPVectorizer.cpp:0 [opt]
frame #13: 0x0000000101b230d6 opt`llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) [inlined] llvm::slpvectorizer::BoUpSLP::createBuildVector(this=0x00007ff7bfefbf90, E=0x0000000109409d70) at SLPVectorizer.cpp:10479:10 [opt]
frame #14: 0x0000000101b230c5 opt`llvm::slpvectorizer::BoUpSLP::vectorizeTree(this=0x00007ff7bfefbf90, E=0x0000000109409d70) at SLPVectorizer.cpp:10494:18 [opt]
frame #15: 0x0000000101b221bd opt`llvm::slpvectorizer::BoUpSLP::vectorizeOperand(this=0x00007ff7bfefbf90, E=0x00000001094041d0, NodeIdx=<unavailable>) at SLPVectorizer.cpp:10123:10 [opt]
frame #16: 0x0000000101b23ca2 opt`llvm::slpvectorizer::BoUpSLP::vectorizeTree(this=0x00007ff7bfefbf90, E=0x00000001094041d0) at SLPVectorizer.cpp:10570:22 [opt]
```
When the same IR is changed from `undef` to `poison`, we generate the IR just fine: https://godbolt.org/z/e4rvM981e
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Wltv66gW_jXuC0pl8P2hD03TSpVm5mx1z-l5HAHGCVMbvAEn2fvXHwF24sRJep2pqtjm8rHWty4snGCt-VIwdhMk8yBZXOHOrKS6wULgxqxkg_UVkeXPmyBcBOHt_7hZgccnQFgtNwG6AxvboOt2tmbUSMV_MeWaGaikogzsmv3I5wcQRAuQAyxKUGFe-2asNVOGSwG4AGbFwPdVV1U1exTaqI7annnH65Kp64oLXPNfLEB5gAqwWTEBiO3jYgkw0H5iv-61l7r_TMP-3z0arJbMAKN4WzMnVYDQNk__SuNZJ16E3IhZzUW3nS1FFyA0hipZxQUDa8lLEMThRjYEmwDlPEIgQAlWSytbgKIQBNnczyEkiPrpABAFakxYbUcTAsfY9jG6BUE0B61ipe5FSwiJLbPuboAJUNKuuBthr275ZA7C3cAYBMnCPR00u1aP4SHQpzCO1IkO1YnOqANHszkEFa41s-gjpPjoGR4xFVvod_2dkAMlO52iQ2KTC6xEp1lByZgXD5NOYHz7R7CyrxEp_xqY4mtgYHiGIfQ-tMtRdS6sotf9EKLjhiMfh-ick8ORqrgsXY-9WkWdHuEZ6Y9XOBtGe5IOFrO8xhfsA-FpSiGaZAc4DYQjD34T2IA2jYd3SjUATYOhEyWrzoANifkS4jQuPos4DZFPIqJpsLyGWJaXEeG7EC-6CpruJB_AGsCiLwE7DCyUHAYWiofA-kO62GKUaS2VDhB8I0Ly3m3o1C60393h0TaELgUMio-s7eJ-hDU10aU95CRcehruiJa4ZyVbjOnBxihOOsN0Xw9ZhTMLjXwFNqsYNp1i2tZY0cJ-onmrKrqyBeaM1iVrpLEZOUBzvN72N3a8vdF4Vfm7ltZNV9s5W9n6JqpohFyLxms3Y4bX2wSiqnVKzXQT9zCax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