This is an archive of the discontinued LLVM Phabricator instance.

[SLP]Improve analysis of same/alternate code ops and scheduling.
ClosedPublic

Authored by ABataev on Jun 10 2022, 1:03 PM.

Details

Summary

Should improve compile time for analysis and vectorization.

Metric: SLP.NumVectorInstructions

Program SLP.NumVectorInstructions
test-suite :: External/SPEC/CINT2017speed/623.xalancbmk_s/623.xalancbmk_s.test 6380.00 6378.00 -0.0%
test-suite :: External/SPEC/CINT2017rate/523.xalancbmk_r/523.xalancbmk_r.test 6380.00 6378.00 -0.0%
test-suite :: External/SPEC/CINT2006/483.xalancbmk/483.xalancbmk.test 2023.00 2022.00 -0.0%
test-suite :: External/SPEC/CINT2006/471.omnetpp/471.omnetpp.test 148.00 146.00 -1.4%

Generated more vector instructions.

Diff Detail

Event Timeline

ABataev created this revision.Jun 10 2022, 1:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 1:03 PM
ABataev requested review of this revision.Jun 10 2022, 1:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 1:03 PM

I'm not sure about how the test case affected supposed to execute the changes.
Could you please consider adding more tests to be clearer about the patch purpose?

I'm not sure about how the test case affected supposed to execute the changes.
Could you please consider adding more tests to be clearer about the patch purpose?

It is for compile time mostly, nothing else. Just allows to detect gathered elements before scheduling.

I'm not sure about how the test case affected supposed to execute the changes.
Could you please consider adding more tests to be clearer about the patch purpose?

It is for compile time mostly, nothing else. Just allows to detect gathered elements before scheduling.

Yes, but the summary also says more vector instructions generated. What specific cases are handled now but failed previously?

I'm not sure about how the test case affected supposed to execute the changes.
Could you please consider adding more tests to be clearer about the patch purpose?

It is for compile time mostly, nothing else. Just allows to detect gathered elements before scheduling.

Yes, but the summary also says more vector instructions generated. What specific cases are handled now but failed previously?

1-2 more instruction. The effect is caused by the better operand reordering. getSameOpcode is used to detect compatible operations, when SLP tries to find better ordering of the operands. The patch just make getSameOpcode a bit better on detecting such compatible ops.

vdmitrie added inline comments.Oct 26 2022, 2:09 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

I'm not sure I understand why this is scored as alternating opcodes.
If underlying objects are same that probably means Dist variable must have a value and the value is 0.
i.e. these loads are from same location. right? It sounds like splat load.
Where alternating opcodes come from?

7317

TTI argument is unused.

11805

TTI argument is unused.

ABataev added inline comments.Oct 26 2022, 3:24 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

No. If you have Geps with non-const indices, the Dist might be None. But the loads still may be the source of masked gather.

7317

Will remove

11805

Will remove

vdmitrie added inline comments.Oct 26 2022, 3:31 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

No. If you have Geps with non-const indices, the Dist might be None. But the loads still may be the source of masked gather.

Ah. right. I forgot that we now vectorize non-const indices. But still, why alternate opcode?
It sounds like we need to introduce named constant dedicated to gather.

ABataev added inline comments.Oct 26 2022, 3:43 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

Because we return alternate if the distance is very big and most probably will result in masked gather with constant indices.

vdmitrie added inline comments.Oct 26 2022, 4:02 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

That seems to only confirm my suggestion - we need to introduce dedicated named constant and fix that place too. Even though it does have same value semantics is different.

ABataev added inline comments.Oct 26 2022, 4:17 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

Why semnatics is different? Still same masked gather.

vdmitrie added inline comments.Oct 26 2022, 4:21 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

It is masked gather load but has nothing to do with alternate ops

ABataev added inline comments.Oct 26 2022, 4:27 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

Ah, I see. I suggest to add something like MaskedGatherCandidate and use here and for large Dists.

vdmitrie added inline comments.Oct 26 2022, 4:33 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
1205

Exactly!

ABataev updated this revision to Diff 471195.Oct 27 2022, 9:35 AM

Rebase + address comments

vdmitrie accepted this revision.Oct 27 2022, 9:46 AM

Looks good. Thanks!

This revision is now accepted and ready to land.Oct 27 2022, 9:46 AM
This revision was landed with ongoing or failed builds.Oct 27 2022, 11:32 AM
This revision was automatically updated to reflect the committed changes.
kda added a subscriber: kda.Oct 27 2022, 2:28 PM

Looks like this is breaking MSAN buildbot: https://lab.llvm.org/buildbot/#/builders/74/builds/14584

Log snippet:

[90/6916] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o
FAILED: lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/lib/CodeGen -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/CodeGen -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/include -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/include -nostdinc++ -isystem /b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/include -isystem /b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/include/c++/v1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-param-retval -Oz -mllvm -sanitizer-early-opt-ep -Wl,--rpath=/b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/lib -L/b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/lib -w -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fno-omit-frame-pointer -gline-tables-only -fsanitize=memory -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++17 -MD -MT lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o -MF lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o.d -o lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o -c /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/CodeGen/LLVMTargetMachine.cpp
clang++: /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/IR/Type.cpp:688: static llvm::FixedVectorType *llvm::FixedVectorType::get(llvm::Type *, unsigned int): Assertion `isValidElementType(ElementType) && "Element type of a VectorType must " "be an integer, floating point, or " "pointer type."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/lib/CodeGen -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/CodeGen -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/include -I/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/include -nostdinc++ -isystem /b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/include -isystem /b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/include/c++/v1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-param-retval -Oz -mllvm -sanitizer-early-opt-ep -Wl,--rpath=/b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/lib -L/b/sanitizer-x86_64-linux-bootstrap-msan/build/libcxx_build_msan/lib -w -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fno-omit-frame-pointer -gline-tables-only -fsanitize=memory -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -fno-exceptions -fno-rtti -UNDEBUG -std=c++17 -MD -MT lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o -MF lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o.d -o lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/LLVMTargetMachine.cpp.o -c /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/lib/CodeGen/LLVMTargetMachine.cpp
1.	<eof> parser at end of file
2.	Optimizer
 #0 0x0000558f40a8a9f3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x72919f3)
 #1 0x0000558f40a889ce llvm::sys::RunSignalHandlers() (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x728f9ce)
 #2 0x0000558f409f216e (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #3 0x0000558f409f23c0 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x00007f31965f6520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007f319664aa7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)
 #6 0x00007f31965f6476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #7 0x00007f31965dc7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #8 0x00007f31965dc71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #9 0x00007f31965ede96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x0000558f4031d348 llvm::FixedVectorType::get(llvm::Type*, unsigned int) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x6b24348)
#11 0x0000558f40cea9ff llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getShallowScore(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, llvm::ArrayRef<llvm::Value*>) const SLPVectorizer.cpp:0:0
#12 0x0000558f40ce9c40 llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getScoreAtLevelRec(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, int, llvm::ArrayRef<llvm::Value*>) const SLPVectorizer.cpp:0:0
#13 0x0000558f40ce9fbd llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getScoreAtLevelRec(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, int, llvm::ArrayRef<llvm::Value*>) const SLPVectorizer.cpp:0:0
#14 0x0000558f40ce9404 llvm::slpvectorizer::BoUpSLP::VLOperands::getLookAheadScore(llvm::Value*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, int, unsigned int, unsigned int, bool&) SLPVectorizer.cpp:0:0
#15 0x0000558f40ce8200 llvm::slpvectorizer::BoUpSLP::VLOperands::getBestOperand(unsigned int, int, int, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::VLOperands::ReorderingMode>, llvm::ArrayRef<llvm::Value*>) SLPVectorizer.cpp:0:0
#16 0x0000558f40cc2843 llvm::slpvectorizer::BoUpSLP::VLOperands::reorder() SLPVectorizer.cpp:0:0
#17 0x0000558f40cb5118 llvm::slpvectorizer::BoUpSLP::reorderInputsAccordingToOpcode(llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<llvm::Value*>&, llvm::SmallVectorImpl<llvm::Value*>&, llvm::TargetLibraryInfo const&, llvm::DataLayout const&, llvm::ScalarEvolution&, llvm::slpvectorizer::BoUpSLP const&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74bc118)
#18 0x0000558f40cab0bd llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74b20bd)
#19 0x0000558f40cae733 llvm::slpvectorizer::BoUpSLP::buildTree(llvm::ArrayRef<llvm::Value*>) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74b5733)
#20 0x0000558f40cdcb95 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74e3b95)
#21 0x0000558f40ce2d59 bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<unsigned int (llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool) SLPVectorizer.cpp:0:0
#22 0x0000558f40ce2661 llvm::SLPVectorizerPass::vectorizeSimpleInstructions(llvm::SmallSetVector<llvm::Instruction*, 8u>&, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, bool) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74e9661)
#23 0x0000558f40cd7db2 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74dedb2)
#24 0x0000558f40cd57cc llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74dc7cc)
#25 0x0000558f40cd4c87 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x74dbc87)
#26 0x0000558f41e4a95d llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0
#27 0x0000558f40307ee5 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x6b0eee5)
#28 0x0000558f3e93e9dd 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>&) AMDGPUTargetMachine.cpp:0:0
#29 0x0000558f4030bd7c llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x6b12d7c)
#30 0x0000558f3e93e78d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) AMDGPUTargetMachine.cpp:0:0
#31 0x0000558f403070a5 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x6b0e0a5)
#32 0x0000558f4132b596 (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
#33 0x0000558f41323b0d 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>>) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7b2ab0d)
#34 0x0000558f4178a959 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) CodeGenAction.cpp:0:0
#35 0x0000558f42a1e25f clang::ParseAST(clang::Sema&, bool, bool) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x922525f)
#36 0x0000558f416a6f30 clang::FrontendAction::Execute() (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7eadf30)
#37 0x0000558f4161477f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7e1b77f)
#38 0x0000558f41783ce3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7f8ace3)
#39 0x0000558f3e5ef3b2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x4df63b2)
#40 0x0000558f3e5ecf52 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#41 0x0000558f4148c4c2 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::$_1>(long) Job.cpp:0:0
#42 0x0000558f409f1fe9 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x71f8fe9)
#43 0x0000558f4148bd20 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7c92d20)
#44 0x0000558f4144f27e clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7c5627e)
#45 0x0000558f4144f52e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7c5652e)
#46 0x0000558f4146c4a0 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x7c734a0)
#47 0x0000558f3e5ec5ad clang_main(int, char**) (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x4df35ad)
#48 0x00007f31965ddd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#49 0x00007f31965dde40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#50 0x0000558f3e5e9a65 _start (/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin/clang+++0x4df0a65)
clang-16: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 16.0.0 (https://github.com/llvm/llvm-project.git 7841f557ea3df1987ceb1c033e458790f5828795)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build0/bin
clang-16: note: diagnostic msg: 
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-16: note: diagnostic msg: /tmp/LLVMTargetMachine-972989.cpp
clang-16: note: diagnostic msg: /tmp/LLVMTargetMachine-972989.sh
clang-16: note: diagnostic msg: 
*******************

We're seeing some Clang assertion failures in the Fuchsia build. I've bisected it down to this patch.

You can find the failing bot here: https://ci.chromium.org/ui/p/fuchsia/builders/ci/clang_toolchain.ci.core.arm64-release/b8799099192459783297/overview

I've filed an issue on github with the reproducer: https://github.com/llvm/llvm-project/issues/58675

If this will take some time to fix, would you mind reverting until a fix is ready?

If this will take some time to fix, would you mind reverting until a fix is ready?

Will do, though after this it definitely won't be fixed

hey, sorry, I think I grabbed the wrong commit from my bisect earlier, so I think your patch is fine. I hope you didn't waste too much time over this.

Hello,

The following starts crashing with this patch:
opt --passes=slp-vectorizer bbi-75302.ll -o /dev/null

I get

opt: ../include/llvm/ADT/ArrayRef.h:256: const T &llvm::ArrayRef<llvm::Value *>::operator[](size_t) const [T = llvm::Value *]: Assertion `Index < Length && "Invalid index!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: build-all/bin/opt --passes=slp-vectorizer /home/uabelho/bbi-75302.ll -o /dev/null
 #0 0x0000000002e58093 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/opt+0x2e58093)
 #1 0x0000000002e55dae llvm::sys::RunSignalHandlers() (build-all/bin/opt+0x2e55dae)
 #2 0x0000000002e58416 SignalHandler(int) (build-all/bin/opt+0x2e58416)
 #3 0x00007ff50079f630 __restore_rt (/lib64/libpthread.so.0+0xf630)
 #4 0x00007ff4fdee6387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007ff4fdee7a78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007ff4fdedf1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007ff4fdedf252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000002f40627 (build-all/bin/opt+0x2f40627)
 #9 0x00000000030ae5b2 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (build-all/bin/opt+0x30ae5b2)
#10 0x00000000030aa658 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::ArrayRef<llvm::Value*>) (build-all/bin/opt+0x30aa658)
#11 0x00000000030ab1e7 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (build-all/bin/opt+0x30ab1e7)
#12 0x00000000030b2659 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int> >, std::vector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u> >, std::allocator<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u> > > > >&) (build-all/bin/opt+0x30b2659)
#13 0x00000000030d9d6f (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) (build-all/bin/opt+0x30d9d6f)
#14 0x00000000030c7588 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (build-all/bin/opt+0x30c7588)
#15 0x00000000030c8969 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (build-all/bin/opt+0x30c8969)
#16 0x00000000030bf821 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (build-all/bin/opt+0x30bf821)
#17 0x00000000030bd85c llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (build-all/bin/opt+0x30bd85c)
#18 0x00000000030bcbff llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x30bcbff)
#19 0x00000000031c7c4d llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x31c7c4d)
#20 0x000000000266850c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x266850c)
#21 0x0000000000aefdbd 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>&) (build-all/bin/opt+0xaefdbd)
#22 0x000000000266c7ee llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x266c7ee)
#23 0x0000000000aefb9d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0xaefb9d)
#24 0x00000000026677bc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x26677bc)
#25 0x0000000000721779 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) (build-all/bin/opt+0x721779)
#26 0x0000000000730c61 main (build-all/bin/opt+0x730c61)
#27 0x00007ff4fded2555 __libc_start_main (/lib64/libc.so.6+0x22555)
#28 0x000000000071a3e0 _start (build-all/bin/opt+0x71a3e0)
Abort

Hello,

The following starts crashing with this patch:
opt --passes=slp-vectorizer bbi-75302.ll -o /dev/null

I get

opt: ../include/llvm/ADT/ArrayRef.h:256: const T &llvm::ArrayRef<llvm::Value *>::operator[](size_t) const [T = llvm::Value *]: Assertion `Index < Length && "Invalid index!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: build-all/bin/opt --passes=slp-vectorizer /home/uabelho/bbi-75302.ll -o /dev/null
 #0 0x0000000002e58093 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/opt+0x2e58093)
 #1 0x0000000002e55dae llvm::sys::RunSignalHandlers() (build-all/bin/opt+0x2e55dae)
 #2 0x0000000002e58416 SignalHandler(int) (build-all/bin/opt+0x2e58416)
 #3 0x00007ff50079f630 __restore_rt (/lib64/libpthread.so.0+0xf630)
 #4 0x00007ff4fdee6387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007ff4fdee7a78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007ff4fdedf1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007ff4fdedf252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000002f40627 (build-all/bin/opt+0x2f40627)
 #9 0x00000000030ae5b2 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (build-all/bin/opt+0x30ae5b2)
#10 0x00000000030aa658 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::ArrayRef<llvm::Value*>) (build-all/bin/opt+0x30aa658)
#11 0x00000000030ab1e7 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (build-all/bin/opt+0x30ab1e7)
#12 0x00000000030b2659 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int> >, std::vector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u> >, std::allocator<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u> > > > >&) (build-all/bin/opt+0x30b2659)
#13 0x00000000030d9d6f (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) (build-all/bin/opt+0x30d9d6f)
#14 0x00000000030c7588 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (build-all/bin/opt+0x30c7588)
#15 0x00000000030c8969 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (build-all/bin/opt+0x30c8969)
#16 0x00000000030bf821 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (build-all/bin/opt+0x30bf821)
#17 0x00000000030bd85c llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (build-all/bin/opt+0x30bd85c)
#18 0x00000000030bcbff llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x30bcbff)
#19 0x00000000031c7c4d llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x31c7c4d)
#20 0x000000000266850c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x266850c)
#21 0x0000000000aefdbd 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>&) (build-all/bin/opt+0xaefdbd)
#22 0x000000000266c7ee llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x266c7ee)
#23 0x0000000000aefb9d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0xaefb9d)
#24 0x00000000026677bc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x26677bc)
#25 0x0000000000721779 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) (build-all/bin/opt+0x721779)
#26 0x0000000000730c61 main (build-all/bin/opt+0x730c61)
#27 0x00007ff4fded2555 __libc_start_main (/lib64/libc.so.6+0x22555)
#28 0x000000000071a3e0 _start (build-all/bin/opt+0x71a3e0)
Abort

Not a bug in the patch itself, it revealed the issue in the existing code. Will send a patch in few minutes.

Hello,

The following starts crashing with this patch:
opt --passes=slp-vectorizer bbi-75302.ll -o /dev/null

I get

opt: ../include/llvm/ADT/ArrayRef.h:256: const T &llvm::ArrayRef<llvm::Value *>::operator[](size_t) const [T = llvm::Value *]: Assertion `Index < Length && "Invalid index!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: build-all/bin/opt --passes=slp-vectorizer /home/uabelho/bbi-75302.ll -o /dev/null
 #0 0x0000000002e58093 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/opt+0x2e58093)
 #1 0x0000000002e55dae llvm::sys::RunSignalHandlers() (build-all/bin/opt+0x2e55dae)
 #2 0x0000000002e58416 SignalHandler(int) (build-all/bin/opt+0x2e58416)
 #3 0x00007ff50079f630 __restore_rt (/lib64/libpthread.so.0+0xf630)
 #4 0x00007ff4fdee6387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007ff4fdee7a78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007ff4fdedf1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007ff4fdedf252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000002f40627 (build-all/bin/opt+0x2f40627)
 #9 0x00000000030ae5b2 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (build-all/bin/opt+0x30ae5b2)
#10 0x00000000030aa658 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::ArrayRef<llvm::Value*>) (build-all/bin/opt+0x30aa658)
#11 0x00000000030ab1e7 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (build-all/bin/opt+0x30ab1e7)
#12 0x00000000030b2659 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int> >, std::vector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u> >, std::allocator<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u> > > > >&) (build-all/bin/opt+0x30b2659)
#13 0x00000000030d9d6f (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) (build-all/bin/opt+0x30d9d6f)
#14 0x00000000030c7588 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (build-all/bin/opt+0x30c7588)
#15 0x00000000030c8969 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (build-all/bin/opt+0x30c8969)
#16 0x00000000030bf821 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (build-all/bin/opt+0x30bf821)
#17 0x00000000030bd85c llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (build-all/bin/opt+0x30bd85c)
#18 0x00000000030bcbff llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x30bcbff)
#19 0x00000000031c7c4d llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x31c7c4d)
#20 0x000000000266850c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x266850c)
#21 0x0000000000aefdbd 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>&) (build-all/bin/opt+0xaefdbd)
#22 0x000000000266c7ee llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x266c7ee)
#23 0x0000000000aefb9d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0xaefb9d)
#24 0x00000000026677bc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x26677bc)
#25 0x0000000000721779 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) (build-all/bin/opt+0x721779)
#26 0x0000000000730c61 main (build-all/bin/opt+0x730c61)
#27 0x00007ff4fded2555 __libc_start_main (/lib64/libc.so.6+0x22555)
#28 0x000000000071a3e0 _start (build-all/bin/opt+0x71a3e0)
Abort

Must be fixed in 99f9bd4807d6132b603a1910902e4586e20638e0