Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLPVectorizer creates invalid IR for reduction: Instruction does not dominate all uses! #58956

Closed
TatyanaDoubts opened this issue Nov 12, 2022 · 2 comments
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:optimizations llvm:SLPVectorizer

Comments

@TatyanaDoubts
Copy link

TatyanaDoubts commented Nov 12, 2022

Godbolt repro: https://godbolt.org/z/P7j1z1T1P
Run clang++ -O3 on the following test:
Test.zip

Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>
1.	<eof> parser at end of file
2.	Optimizer
 #0 0x000055b4b1eb1d44 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055b4b1eafadc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fc8adc)
 #2 0x000055b4b1deae78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f1e46b84420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f1e4665100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f1e46630859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f1e46630729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f1e46641fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055b4b1f79d1d (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4092d1d)
 #9 0x000055b4b1f79d8b llvm::formLCSSARecursively(llvm::Loop&, llvm::DominatorTree const&, llvm::LoopInfo const*, llvm::ScalarEvolution*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4092d8b)
#10 0x000055b4b1f79d71 llvm::formLCSSARecursively(llvm::Loop&, llvm::DominatorTree const&, llvm::LoopInfo const*, llvm::ScalarEvolution*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4092d71)
#11 0x000055b4b1f79d71 llvm::formLCSSARecursively(llvm::Loop&, llvm::DominatorTree const&, llvm::LoopInfo const*, llvm::ScalarEvolution*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4092d71)
#12 0x000055b4b1c74fdd llvm::LoopUnrollPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d8dfdd)
#13 0x000055b4b33d8ca6 llvm::detail::PassModel<llvm::Function, llvm::LoopUnrollPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54f1ca6)
#14 0x000055b4af6d3884 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/clang+++0x17ec884)
#15 0x000055b4b165032f llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x376932f)
#16 0x000055b4af6b97c6 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/clang+++0x17d27c6)
#17 0x000055b4b164e48a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x376748a)
#18 0x000055b4b2287ac0 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) BackendUtil.cpp:0:0
#19 0x000055b4b228a052 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43a3052)
#20 0x000055b4b31e6ffb clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52ffffb)
#21 0x000055b4b4484db5 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x659ddb5)
#22 0x000055b4b31e5aa8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52feaa8)
#23 0x000055b4b2a76b09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b8fb09)
#24 0x000055b4b29fd58e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b1658e)
#25 0x000055b4b2b5bd83 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c74d83)
#26 0x000055b4af358e34 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1471e34)
#27 0x000055b4af354c37 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#28 0x000055b4b2867479 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#29 0x000055b4b1deb61a llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f0461a)
#30 0x000055b4b2867ccf clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#31 0x000055b4b2830ff9 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4949ff9)
#32 0x000055b4b2831a7d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x494aa7d)
#33 0x000055b4b283b51c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x495451c)
#34 0x000055b4af357422 clang_main(int, char**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1470422)
#35 0x00007f1e46632083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#36 0x000055b4af35056e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x146956e)
clang-16: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
@EugeneZelenko EugeneZelenko added llvm:optimizations crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Nov 13, 2022
@fhahn
Copy link
Contributor

fhahn commented Nov 16, 2022

Looks like the issue is that SLPVectorizer generates invalid IR for https://godbolt.org/z/bj8e1soo4


define i8 @test() {
entry:
  br label %for.body

for.body:
  %sum = phi i32 [ %add285.19, %for.body ], [ 0, %entry ]
  %call278 = call i32 @fn(i32 %sum)
  %add285.13 = add i32 %call278, %call278
  %add285.14 = add i32 %add285.13, %call278
  %add285.15 = add i32 %add285.14, %call278
  %add285.16 = add i32 %add285.15, %call278
  %add285.17 = add i32 %add285.16, %call278
  %add285.18 = add i32 %add285.17, %call278
  %add285.19 = add i32 %add285.18, %call278
  br label %for.body
}

declare i32 @fn(i32)

cc @alexey-bataev

@fhahn fhahn changed the title Assertion `L.isLCSSAForm(DT)' failed. SLPVectorizer creates invalid IR for reduction: Instruction does not dominate all uses! Nov 16, 2022
@alexey-bataev
Copy link
Member

Fixed in 2f8f17c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:optimizations llvm:SLPVectorizer
Projects
None yet
Development

No branches or pull requests

4 participants