Issue 170836
Summary [SLP][Revec] Assertion `(allConstant(VLRef) || allSameType(VLRef)) && "Invalid types!"'
Labels vectorizers, crash-on-valid
Assignees
Reporter sjoerdmeijer
    This IR:

```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-linux-gnu"

define void @_Z1ev(<16 x i1> %0) {
entry:
  br label %vector.body

vector.body: ; preds = %vector.body, %entry
  %vec.phi = phi <16 x i16> [ zeroinitializer, %entry ], [ %2, %vector.body ]
  %vec.phi40 = phi <16 x i16> [ zeroinitializer, %entry ], [ %4, %vector.body ]
  %1 = select i1 false, <16 x i16> zeroinitializer, <16 x i16> zeroinitializer
  %2 = mul <16 x i16> zeroinitializer, %1
  %3 = select <16 x i1> %0, <16 x i16> zeroinitializer, <16 x i16> zeroinitializer
  %4 = mul <16 x i16> %3, zeroinitializer
  br label %vector.body
}
```

compiled with `opt -passes=slp-vectorizer  -S -slp-revec`,
triggers this assert:

```
opt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:11580: void llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, const llvm::slpvectorizer::BoUpSLP::EdgeInfo&, unsigned int): Assertion `(allConstant(VLRef) || allSameType(VLRef)) && "Invalid types!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer -S -slp-revec <source>
1.	Running pass "function(slp-vectorizer)" on module "<source>"
2.	Running pass "slp-vectorizer" on function "_Z1ev"
 #0 0x00000000059e50e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59e50e8)
 #1 0x00000000059e1f94 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x0000770d5d242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000770d5d2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x0000770d5d242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x0000770d5d2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000770d5d22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x0000770d5d239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000037fde8e llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x37fde8e)
 #9 0x00000000037fd248 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x37fd248)
#10 0x00000000037fd248 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x37fd248)
#11 0x00000000037fe2c6 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x37fe2c6)
#12 0x0000000003834c0d llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3834c0d)
#13 0x00000000038398ef bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0
#14 0x000000000383abfc llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x383abfc)
#15 0x0000000003842c06 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0
#16 0x000000000384382b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x384382b)

```

See also: https://godbolt.org/z/szTYP1PrP

Same comment as I made in #170828, I am slightly surprised that the vectors are already that wide, but that's what the loop vectorizer seems to be producing. 

This IR was reproduced from this source code reproducer:

```
short a, b;
int c;
char *d;
void e() {
  for (; c; c++) {
    a *= d[9] ?: c;
    b *= d[c] ? 10301777303764690586 : 0;
  }
}
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to