llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[slp-vectorizer] Assertion `BitPosition < BitWidth && "BitPosition out of range"' failed.

Open dbakunevich opened this issue 4 years ago • 3 comments

Bug on vectorization. It seems to me that this bug is related to vectorization of multiplication and poison values.

Ir with bug:

define void @bar() {
  %tmp = add i64 poison, poison
  %tmp2 = add i64 poison, poison
  %tmp3 = mul i64 %tmp2, %tmp
  %tmp4 = mul i64 %tmp3, %tmp2
  %tmp5 = mul i64 %tmp4, %tmp2
  %tmp7 = add i64 %tmp, %tmp5
  %tmp8 = sitofp i64 %tmp7 to double
  call void @wibble(i32 poison, double %tmp8, i64 poison)
  unreachable
}

declare void @wibble(i32, double, i64)

Run: opt -passes=slp-vectorizer -S ir.ll

The ir can be seen/tested here: https://godbolt.org/z/PcanWMbb5

Stack trace:

opt: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:1281: void llvm::APInt::setBit(unsigned int): Assertion `BitPosition < BitWidth && "BitPosition out of range"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer -S <source>
 #0 0x0000556f72090264 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000556f7208da24 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f18a4c34420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f18a470100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f18a46e0859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f18a46e0729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f18a46f1fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000556f72354cf0 (anonymous namespace)::ScalarizationOverheadBuilder::addExtract(llvm::FixedVectorType*, unsigned int) SLPVectorizer.cpp:0:0
 #8 0x0000556f7238d1e3 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3bfd1e3)
 #9 0x0000556f7238f9c4 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) SLPVectorizer.cpp:0:0
#10 0x0000556f723917c0 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c017c0)
#11 0x0000556f72395826 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0
#12 0x0000556f72399002 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c09002)
#13 0x0000556f7239bde3 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
#14 0x0000556f7239cc5c llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c0cc5c)
#15 0x0000556f723ff606 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c6f606)
#16 0x0000556f6f855374 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x10c5374)
#17 0x0000556f7179a16f llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x300a16f)
#18 0x0000556f6f83bd36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x10abd36)
#19 0x0000556f717982ca llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x30082ca)
#20 0x0000556f6f3fde78 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::StringRef>, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xc6de78)
#21 0x0000556f6f320d7a main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xb90d7a)
#22 0x00007f18a46e2083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#23 0x0000556f6f3f0f5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xc60f5e)
Compiler returned: 139

dbakunevich avatar Sep 29 '22 11:09 dbakunevich

A fix was committed yesterday: 926ccfef032d206dcbcdf74ca1e3a9ebf4d1be45 are you still seeing this?

RKSimon avatar Sep 29 '22 15:09 RKSimon

It's still failing with godbolt. Is it out of date somehow, or the fix isn't working? https://godbolt.org/z/PcanWMbb5

xortator avatar Sep 30 '22 11:09 xortator

Some of the godbolt compilers can lag behind others - I've added test coverage at 5fc7bbfaa3b0365cf656485d3595d6f94e23164a to keep an eye on it but its passing fine atm

The original patch (D134605) has been reverted for now but I will revisit it soon.

RKSimon avatar Sep 30 '22 12:09 RKSimon