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

[slp] vectorizer ICEs with "InstructionsState is invalid" with neoverse-v1 but not neoverse-n1 #122501

Open
ashermancinelli opened this issue Jan 10, 2025 · 4 comments
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:SLPVectorizer regression

Comments

@ashermancinelli
Copy link
Contributor

ashermancinelli commented Jan 10, 2025

> clang++ --version                                  
clang version 20.0.0git (https://github.com/llvm/llvm-project 3def49cb64ec1298290724081bd37dbdeb2ea5f8)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /install/llvm/bin
Build config: +assertions

Started sometime in the range (211bcf67aadb1175af382f55403ae759177281c7, 3def49cb64ec1298290724081bd37dbdeb2ea5f8].

I see some potentially related changes like this:

commit 760f550de25792db83cd39c88ef57ab6d80a41a0
Author: Han-Kuan Chen <hankuan.chen@sifive.com>
Commit: GitHub <noreply@github.com>

    [SLP] NFC. Replace MainOp and AltOp in TreeEntry with InstructionsState. (#120198)
    
    Add TreeEntry::hasState.
    Add assert for getTreeEntry.
    Remove the OpValue parameter from the canReuseExtract function.
    Remove the Opcode parameter from the ComputeMaxBitWidth lambda function.

Maybe @HanKuanChen could you help us narrow this down?

Only ICEs with neoverse-v1

# ok
> clang++ -O2 -mcpu=neoverse-n1 -S ./reduced.ll

# ICE
> clang++ -O2 -mcpu=neoverse-v1 -S ./reduced.ll
clang++: /install/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:821: llvm::Instruction* {anonymous}::InstructionsState::getMainOp() const: Assertion `valid() && "InstructionsState is invalid."' 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: clang++ -O2 -mcpu=neoverse-v1 -S ./first-reduced.ll
1.      Optimizer
2.      Running pass "function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)" on module "./first-reduced.ll"
3.      Running pass "slp-vectorizer" on function "foo"
 #0 0x0000aaad9a2828e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/install/llvm/bin/clang-20+0x46028e0)
 #1 0x0000aaad9a280638 llvm::sys::RunSignalHandlers() (/install/llvm/bin/clang-20+0x4600638)
 #2 0x0000aaad9a2809f0 llvm::sys::CleanupOnSignal(unsigned long) (/install/llvm/bin/clang-20+0x46009f0)
 #3 0x0000aaad9a1d64c4 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x0000ffff156908dc (linux-vdso.so.1+0x8dc)
 #5 0x0000ffff1530f200 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x0000ffff152ca67c gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x0000ffff152b7130 abort ./stdlib/abort.c:81:7
 #8 0x0000ffff152c3fd0 __assert_fail_base ./assert/assert.c:89:7
 #9 0x0000ffff152c4040 __assert_perror_fail ./assert/assert-perr.c:31:1
#10 0x0000aaad9be052c0 (anonymous namespace)::InstructionsState::getAltOp() const (.part.0) SLPVectorizer.cpp:0:0
#11 0x0000aaad9bebb060 llvm::slpvectorizer::BoUpSLP::transformNodes() (/install/llvm/bin/clang-20+0x623b060)
#12 0x0000aaad9bececf4 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0
#13 0x0000aaad9bed0de8 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/install/llvm/bin/clang-20+0x6250de8)
#14 0x0000aaad9bed4f84 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0
#15 0x0000aaad9bed8a50 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/install/llvm/bin/clang-20+0x6258a50)
#16 0x0000aaad9bede468 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
#17 0x0000aaad9bedee90 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/install/llvm/bin/clang-20+0x625ee90)
#18 0x0000aaad9b94ca24 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0
#19 0x0000aaad99d26a28 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/install/llvm/bin/clang-20+0x40a6a28)
#20 0x0000aaad98dc5c44 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) NVPTXTargetMachine.cpp:0:0
#21 0x0000aaad99d254ac llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/install/llvm/bin/clang-20+0x40a54ac)
#22 0x0000aaad98dc5bf4 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) NVPTXTargetMachine.cpp:0:0
#23 0x0000aaad99d24ed4 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/install/llvm/bin/clang-20+0x40a4ed4)
#24 0x0000aaad9ac070ac (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>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#25 0x0000aaad9ac09cbc clang::emitBackendOutput(clang::CompilerInstance&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/install/llvm/bin/clang-20+0x4f89cbc)
#26 0x0000aaad9ad4554c clang::CodeGenAction::ExecuteAction() (/install/llvm/bin/clang-20+0x50c554c)
#27 0x0000aaad9b0ca580 clang::FrontendAction::Execute() (/install/llvm/bin/clang-20+0x544a580)
#28 0x0000aaad9b05ed00 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/install/llvm/bin/clang-20+0x53ded00)
#29 0x0000aaad9b1b7c40 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/install/llvm/bin/clang-20+0x5537c40)
#30 0x0000aaad98d80868 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/install/llvm/bin/clang-20+0x3100868)
#31 0x0000aaad98d78f54 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#32 0x0000aaad9aeafef8 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#33 0x0000aaad9a1d69c8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/install/llvm/bin/clang-20+0x45569c8)
#34 0x0000aaad9aeb04c8 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#35 0x0000aaad9ae76aa4 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/install/llvm/bin/clang-20+0x51f6aa4)
#36 0x0000aaad9ae776f4 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/install/llvm/bin/clang-20+0x51f76f4)
#37 0x0000aaad9ae7f098 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/install/llvm/bin/clang-20+0x51ff098)
#38 0x0000aaad98d7d664 clang_main(int, char**, llvm::ToolContext const&) (/install/llvm/bin/clang-20+0x30fd664)
#39 0x0000aaad98d8d09c main (/install/llvm/bin/clang-20+0x310d09c)
#40 0x0000ffff152b73fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#41 0x0000ffff152b74cc call_init ./csu/../csu/libc-start.c:128:20
#42 0x0000ffff152b74cc __libc_start_main ./csu/../csu/libc-start.c:379:5
#43 0x0000aaad98d78a44 _start (/install/llvm/bin/clang-20+0x30f8a44)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 20.0.0git (https://github.com/llvm/llvm-project bbb53d1a8cd37cbb31ec5ec7938a0f24f628c821)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /install/llvm/bin
Build config: +assertions
clang++: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
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 @foo(ptr %0, ptr %1, ptr %2, ptr %3, i64 %4, i64 %5) {
  br label %7

7:                                                ; preds = %8, %6
  br label %8

8:                                                ; preds = %25, %7
  %9 = phi i32 [ %26, %25 ], [ 0, %7 ]
  %10 = phi i64 [ %27, %25 ], [ %4, %7 ]
  %11 = icmp sgt i64 %10, 0
  br i1 %11, label %12, label %7

12:                                               ; preds = %8
  %13 = load i32, ptr %0, align 4
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %12
  %16 = zext i32 %9 to i64
  %17 = add i64 %16, 1
  %18 = getelementptr float, ptr %1, i64 %17
  store float 0.000000e+00, ptr %18, align 4
  store float 0.000000e+00, ptr %1, align 4
  %19 = getelementptr float, ptr %1, i64 %5
  %20 = getelementptr float, ptr %19, i64 %17
  store float 0.000000e+00, ptr %20, align 4
  %21 = getelementptr float, ptr %3, i64 %17
  %22 = getelementptr float, ptr %2, i64 %17
  %23 = load float, ptr %22, align 4
  %24 = fadd float %23, 0.000000e+00
  store float %24, ptr %21, align 4
  br label %25

25:                                               ; preds = %15, %12
  %26 = add i32 %9, 1
  %27 = add i64 %10, -1
  br label %8
}
IR before slp vectorize
> opt -passes=slp-vectorizer -S vect-reduced.ll 
opt: /install/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:821: llvm::Instruction* {anonymous}::InstructionsState::getMainOp() const: Assertion `valid() && "InstructionsState is invalid."' 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 -passes=slp-vectorizer -S vect-reduced.ll
1.      Running pass "function(slp-vectorizer)" on module "vect-reduced.ll"
2.      Running pass "slp-vectorizer" on function "foo"

vect-reduced.ll:

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 @foo(ptr %0) {
vector.scevcheck:
  %scevgep = getelementptr i8, ptr %0, i64 4
  %scevgep3 = getelementptr i8, ptr null, i64 4
  %bound011 = icmp ult ptr %scevgep, null
  %found.conflict13 = and i1 %bound011, false
  %bound014 = icmp ult ptr %scevgep, null
  %found.conflict16 = and i1 %bound014, false
  %conflict.rdx17 = or i1 %found.conflict13, %found.conflict16
  %bound018 = icmp ult ptr %scevgep, null
  %found.conflict20 = and i1 %bound018, false
  %conflict.rdx21 = or i1 %conflict.rdx17, %found.conflict20
  %bound022 = icmp ult ptr %0, null
  %found.conflict24 = and i1 %bound022, false
  %conflict.rdx25 = or i1 %conflict.rdx21, %found.conflict24
  %bound026 = icmp ult ptr %0, null
  %found.conflict28 = and i1 %bound026, false
  %conflict.rdx29 = or i1 %conflict.rdx25, %found.conflict28
  %bound030 = icmp ult ptr %0, null
  %found.conflict32 = and i1 %bound030, false
  %conflict.rdx33 = or i1 %conflict.rdx29, %found.conflict32
  %bound034 = icmp ult ptr %0, null
  %found.conflict36 = and i1 %bound034, false
  %conflict.rdx37 = or i1 %conflict.rdx33, %found.conflict36
  %bound038 = icmp ult ptr %scevgep3, null
  %found.conflict40 = and i1 %bound038, false
  %conflict.rdx41 = or i1 %conflict.rdx37, %found.conflict40
  br i1 %conflict.rdx41, label %.lr.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  ret void

.lr.ph:                                           ; preds = %vector.scevcheck
  ret void
}
@HanKuanChen HanKuanChen self-assigned this Jan 10, 2025
@HanKuanChen
Copy link
Contributor

What is the content of first-reduced.ll?

@HanKuanChen
Copy link
Contributor

BTW, vect-reduced.ll can be solved by #122443.

@ashermancinelli
Copy link
Contributor Author

Sorry, I edited the description. Both clang commands use the IR I have in the description. The second IR is from immediately before the slp-vectorizer pass, the first is what llvm-reduce gave me from the app where I first saw the failure.

@HanKuanChen
Copy link
Contributor

Thanks for bug report. The issues can be solved by the PR.

@EugeneZelenko EugeneZelenko added llvm:SLPVectorizer crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Jan 10, 2025
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:SLPVectorizer regression
Projects
None yet
Development

No branches or pull requests

5 participants