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

Assertion `(!From->hasAnyUseOfValue(i) || From->getValueType(i) == To->getValueType(i)) && "Cannot use this version of ReplaceAllUsesWith!" #51846

Closed
Vsevolod-Livinskij opened this issue Nov 14, 2021 · 6 comments
Assignees
Labels
backend:X86 bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead

Comments

@Vsevolod-Livinskij
Copy link

Bugzilla Link 52504
Resolution FIXED
Resolved on Nov 15, 2021 08:20
Version trunk
OS Linux
CC @dbabokin,@topperc,@RKSimon,@phoebewang,@regehr,@rotateright,@Vsevolod-Livinskij
Fixed by commit(s) 5be64d4 6efe64c 3d01507

Extended Description

IR Reproducer:

@​b = external global [0 x i16]
@​c = external global [0 x i8]

define void @​_Z1hv([0 x i16]* %b, i64 %0, i16* %1, i16 %2, <8 x i16> %3, <8 x i16> %4, <8 x i16> %5, [0 x i8]* %c, i8* %6, i8* %7) {
vector.ph:
br label %vector.body

vector.body: ; preds = %vector.body, %vector.ph
%8 = or i64 0, 0
%9 = getelementptr inbounds [0 x i16], [0 x i16]* %b, i64 0, i64 %0
%10 = load i16, i16* %1, align 2
%11 = insertelement <8 x i16> zeroinitializer, i16 %2, i32 1
%12 = insertelement <8 x i16> %3, i16 0, i32 0
%13 = insertelement <8 x i16> %3, i16 0, i32 0
%14 = sext <8 x i16> %3 to <8 x i64>
%15 = icmp sgt <8 x i64> %14, <i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1>
%16 = select <8 x i1> %15, <8 x i64> %14, <8 x i64> <i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1, i64 -1>
%17 = trunc <8 x i64> %16 to <8 x i32>
%18 = icmp ne <8 x i32> %17, zeroinitializer
%19 = getelementptr inbounds [0 x i8], [0 x i8]* %c, i64 0, i64 %0
%20 = getelementptr inbounds [0 x i8], [0 x i8]* %c, i64 0, i64 undef
%21 = zext <8 x i1> %18 to <8 x i8>
%22 = extractelement <8 x i8> %21, i32 1
store i8 %22, i8* %6, align 1
%23 = extractelement <8 x i8> %21, i32 0
store i8 %23, i8* %7, align 1
br label %vector.body
}

$ clang++ -c reduced.ll
clang++: /testing/llvm/llvm_src_main/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:9444: void llvm::SelectionDAG::ReplaceAllUsesWith(llvm::SDNode*, llvm::SDNode*): Assertion `(!From->hasAnyUseOfValue(i) || From->getValueType(i) == To->getValueType(i)) && "Cannot use this version of ReplaceAllUsesWith!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:

  1. Program arguments: clang++ -c reduced.ll
  2. Code generation
  3. Running pass 'Function Pass Manager' on module 'reduced.ll'.
  4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_Z1hv'
    #​0 0x0000561d20998344 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
    #​1 0x0000561d20996154 llvm::sys::CleanupOnSignal(unsigned long) (/testing/llvm/bin_main/bin/clang-14+0x224b154)
    #​2 0x0000561d208de158 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
    #​3 0x00007fbfac0d23c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
    #​4 0x00007fbfabb8218b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
    #​5 0x00007fbfabb61859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
    #​6 0x00007fbfabb61729 (/lib/x86_64-linux-gnu/libc.so.6+0x25729)
    #​7 0x00007fbfabb72f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
    #​8 0x0000561d219e2f9f llvm::SelectionDAG::ReplaceAllUsesWith(llvm::SDNode*, llvm::SDNode*) (/testing/llvm/bin_main/bin/clang-14+0x3297f9f)
    #​9 0x0000561d2190aa89 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) (/testing/llvm/bin_main/bin/clang-14+0x31bfa89)
    #​10 0x0000561d21a1a739 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/testing/llvm/bin_main/bin/clang-14+0x32cf739)
    #​11 0x0000561d21a1df7b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/testing/llvm/bin_main/bin/clang-14+0x32d2f7b)
    #​12 0x0000561d21a20191 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
    #​13 0x0000561d1f54c7c0 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
    #​14 0x0000561d1fbe0e38 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/testing/llvm/bin_main/bin/clang-14+0x1495e38)
    #​15 0x0000561d201462e5 llvm::FPPassManager::runOnFunction(llvm::Function&) (/testing/llvm/bin_main/bin/clang-14+0x19fb2e5)
    #​16 0x0000561d20146529 llvm::FPPassManager::runOnModule(llvm::Module&) (/testing/llvm/bin_main/bin/clang-14+0x19fb529)
    #​17 0x0000561d20147612 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/testing/llvm/bin_main/bin/clang-14+0x19fc612)
    #​18 0x0000561d20ce62c3 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_deletellvm::raw_pwrite_stream >) (/testing/llvm/bin_main/bin/clang-14+0x259b2c3)
    #​19 0x0000561d21b5b453 clang::CodeGenAction::ExecuteAction() (/testing/llvm/bin_main/bin/clang-14+0x3410453)
    #​20 0x0000561d21405b09 clang::FrontendAction::Execute() (/testing/llvm/bin_main/bin/clang-14+0x2cbab09)
    #​21 0x0000561d21394b8e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/testing/llvm/bin_main/bin/clang-14+0x2c49b8e)
    #​22 0x0000561d214e6e53 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/testing/llvm/bin_main/bin/clang-14+0x2d9be53)
    #​23 0x0000561d1f44da17 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/testing/llvm/bin_main/bin/clang-14+0xd02a17)
    #​24 0x0000561d1f44a068 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
    #​25 0x0000561d2121f8d9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const::'lambda'()>(long) Job.cpp:0:0
    #​26 0x0000561d208de2dc llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/testing/llvm/bin_main/bin/clang-14+0x21932dc)
    #​27 0x0000561d2121ffed clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const (.part.0) Job.cpp:0:0
    #​28 0x0000561d211f157b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/testing/llvm/bin_main/bin/clang-14+0x2aa657b)
    #​29 0x0000561d211f2089 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/testing/llvm/bin_main/bin/clang-14+0x2aa7089)
    #​30 0x0000561d211fb999 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/testing/llvm/bin_main/bin/clang-14+0x2ab0999)
    #​31 0x0000561d1f3c7b9a main (/testing/llvm/bin_main/bin/clang-14+0xc7cb9a)
    #​32 0x00007fbfabb630b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
    #​33 0x0000561d1f449bde _start (/testing/llvm/bin_main/bin/clang-14+0xcfebde)
    clang-14: error: clang frontend command failed with exit code 134 (use -v to see invocation)
    clang version 14.0.0 (https://github.com/llvm/llvm-project.git 51715fb)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /testing/llvm/bin_main/bin
    clang-14: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.

C++ Reproducer:
char a;
extern short b[];
extern bool c[];
long d(long f, long g) { return f > g ? f : g; }
void h() {
#pragma clang loop vectorize(enable)
for (int e = 0; e < a; e += 4)
c[e] = int(d(-1LL, b[e]));
}

Error:

$ clang++ -O1 -c func.cpp

clang version 14.0.0 (https://github.com/llvm/llvm-project.git 51715fb)

@Vsevolod-Livinskij
Copy link
Author

assigned to @rotateright

@RKSimon
Copy link
Collaborator

RKSimon commented Nov 14, 2021

@​spatel The VSRAI+ANDNP makes me think this might be due to one of your recent commits:

Combining: t179: v2i64 = and t119, t177
Creating constant: t239: i8 = TargetConstant<31>
Creating new node: t240: v4i32 = X86ISD::VSRAI t232, TargetConstant:i8<31>
Creating new node: t241: v4i32 = X86ISD::ANDNP t240, t210
... into: t241: v4i32 = X86ISD::ANDNP t240, t210
Assertion failed: (!From->hasAnyUseOfValue(i) || From->getValueType(i) == To->getValueType(i)) && "Cannot use this version of ReplaceAllUsesWith!", file C:\LLVM\llvm-project\llvm\lib\CodeGen\SelectionDAG\SelectionDAG.cpp, line 9446
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.

@RKSimon
Copy link
Collaborator

RKSimon commented Nov 15, 2021

@rotateright
Copy link
Contributor

Yes, seem very likely to be a problem with that patch. Stepping through now.

@rotateright
Copy link
Contributor

Ah, forgot to account for the optional bitcasts of the input operands.

@rotateright
Copy link
Contributor

The original commit was reverted:
https://reviews.llvm.org/rG5be64d416481

I added a minimized crasher test based on the example here and a fixed version of the patch with:
https://reviews.llvm.org/rG6efe64cf9f11
https://reviews.llvm.org/rG3d01507c2dec

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead
Projects
None yet
Development

No branches or pull requests

3 participants