llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.03k stars 11.58k forks source link

A/F: (!From->hasAnyUseOfValue(i) || From->getValueType(i) == To->getValueType(i)) && "Cannot use this version of ReplaceAllUsesWith!" after r345602 #38859

Closed dyung closed 5 years ago

dyung commented 5 years ago
Bugzilla Link 39511
Resolution FIXED
Resolved on Nov 01, 2018 08:50
Version trunk
OS Windows NT
CC @gregbedwell,@RKSimon,@rotateright,@wjristow
Fixed by commit(s) 345842

Extended Description

One of our internal code bases hit an assertion failure that started occurring after r345602. Oddly, it only seems to reproduce on a Windows hosted compiler.

Here is the reduced reproducer:

/ repro.cpp / typedef float a attribute((__vector_size__(16))); a b, c; extern "C" void memcpy(void , void , long); int af; void j() { a k = b + c; float l((float *)&k); memcpy(&af, l, 12); }

If you compile it on Windows with optimizations using a compiler that includes r345602, it will hit the following assertion failure:

Command: clang -c -O2 repro.cpp

Output: Assertion failed: (!From->hasAnyUseOfValue(i) || From->getValueType(i) == To->getValueType(i)) && "Cannot use this version of ReplaceAllUsesWith!", file C:\src\upstream\llvm_clean\lib\CodeGen\SelectionDAG\SelectionDAG.cpp, line 7836 LLVMSymbolizer: error reading file: 'ucrtbase.pdb': no such file or directory LLVMSymbolizer: error reading file: 'kernel32.pdb': no such file or directory LLVMSymbolizer: error reading file: 'ntdll.pdb': no such file or directory

​0 0x00007ff70d1188d5 HandleAbort c:\src\upstream\llvm_clean\lib\support\windows\signals.inc:409:0

​1 0x00007fff3cbdab2f (C:\WINDOWS\System32\ucrtbase.dll+0x6ab2f)

​2 0x00007fff3cbdb821 (C:\WINDOWS\System32\ucrtbase.dll+0x6b821)

​3 0x00007fff3cbdd58a (C:\WINDOWS\System32\ucrtbase.dll+0x6d58a)

​4 0x00007fff3cbdd485 (C:\WINDOWS\System32\ucrtbase.dll+0x6d485)

​5 0x00007fff3cbdd7bf (C:\WINDOWS\System32\ucrtbase.dll+0x6d7bf)

​6 0x00007ff70dbc8d8a llvm::SelectionDAG::ReplaceAllUsesWith(class llvm::SDNode ,class llvm::SDNode ) c:\src\upstream\llvm_clean\lib\codegen\selectiondag\selectiondag.cpp:7833:0

​7 0x00007ff70dcd9efd `anonymous namespace'::DAGCombiner::Run c:\src\upstream\llvm_clean\lib\codegen\selectiondag\dagcombiner.cpp:1482:0

​8 0x00007ff70dcc0bc4 llvm::SelectionDAG::Combine(enum llvm::CombineLevel,class llvm::AAResults *,enum llvm::CodeGenOpt::Level) c:\src\upstream\llvm_clean\lib\codegen\selectiondag\dagcombiner.cpp:19085:0

​9 0x00007ff70dc753f0 llvm::SelectionDAGISel::CodeGenAndEmitDAG(void) c:\src\upstream\llvm_clean\lib\codegen\selectiondag\selectiondagisel.cpp:754:0

​10 0x00007ff70dc7e980 llvm::SelectionDAGISel::SelectBasicBlock(class llvm::ilist_iterator<struct llvm::ilist_detail::node_options<class llvm::Instruction,1,0,void>,0,1>,class llvm::ilist_iterator<struct llvm::ilist_detail::node_options<class llvm::Instruction,1,0,void>,0,1>,bool &) c:\src\upstream\llvm_clean\lib\codegen\selectiondag\selectiondagisel.cpp:669:0

​11 0x00007ff70dc7e0e3 llvm::SelectionDAGISel::SelectAllBasicBlocks(class llvm::Function const &) c:\src\upstream\llvm_clean\lib\codegen\selectiondag\selectiondagisel.cpp:1787:0

​12 0x00007ff70dc8b037 llvm::SelectionDAGISel::runOnMachineFunction(class llvm::MachineFunction &) c:\src\upstream\llvm_clean\lib\codegen\selectiondag\selectiondagisel.cpp:471:0

​13 0x00007ff70c08c45d `anonymous namespace'::X86DAGToDAGISel::runOnMachineFunction c:\src\upstream\llvm_clean\lib\target\x86\x86iseldagtodag.cpp:187:0

​14 0x00007ff70c689ef0 llvm::MachineFunctionPass::runOnFunction(class llvm::Function &) c:\src\upstream\llvm_clean\lib\codegen\machinefunctionpass.cpp:74:0

​15 0x00007ff70ca3b0dc llvm::FPPassManager::runOnFunction(class llvm::Function &) c:\src\upstream\llvm_clean\lib\ir\legacypassmanager.cpp:1644:0

​16 0x00007ff70ca3b3c7 llvm::FPPassManager::runOnModule(class llvm::Module &) c:\src\upstream\llvm_clean\lib\ir\legacypassmanager.cpp:1678:0

​17 0x00007ff70ca3b64f `anonymous namespace'::MPPassManager::runOnModule c:\src\upstream\llvm_clean\lib\ir\legacypassmanager.cpp:1744:0

​18 0x00007ff70ca3a867 llvm::legacy::PassManagerImpl::run(class llvm::Module &) c:\src\upstream\llvm_clean\lib\ir\legacypassmanager.cpp:1858:0

​19 0x00007ff70d486adf `anonymous namespace'::EmitAssemblyHelper::EmitAssembly c:\src\upstream\llvm_clean\tools\clang\lib\codegen\backendutil.cpp:868:0

​20 0x00007ff70d4888e3 clang::EmitBackendOutput(class clang::DiagnosticsEngine &,class clang::HeaderSearchOptions const &,class clang::CodeGenOptions const &,class clang::TargetOptions const &,class clang::LangOptions const &,class llvm::DataLayout const &,class llvm::Module *,enum clang::BackendAction,class std::unique_ptr<class llvm::raw_pwrite_stream,struct std::default_delete >) c:\src\upstream\llvm_clean\tools\clang\lib\codegen\backendutil.cpp:1300:0

​21 0x00007ff70fe1b7fd clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &) c:\src\upstream\llvm_clean\tools\clang\lib\codegen\codegenaction.cpp:297:0

​22 0x00007ff70e9e0729 clang::ParseAST(class clang::Sema &,bool,bool) c:\src\upstream\llvm_clean\tools\clang\lib\parse\parseast.cpp:177:0

​23 0x00007ff70da112d1 clang::ASTFrontendAction::ExecuteAction(void) c:\src\upstream\llvm_clean\tools\clang\lib\frontend\frontendaction.cpp:1019:0

​24 0x00007ff70da110fc clang::FrontendAction::Execute(void) c:\src\upstream\llvm_clean\tools\clang\lib\frontend\frontendaction.cpp:920:0

​25 0x00007ff70d9c8880 clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) c:\src\upstream\llvm_clean\tools\clang\lib\frontend\compilerinstance.cpp:965:0

​26 0x00007ff70dac3c79 clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) c:\src\upstream\llvm_clean\tools\clang\lib\frontendtool\executecompilerinvocation.cpp:258:0

​27 0x00007ff70c051a41 cc1_main(class llvm::ArrayRef<char const >,char const ,void *) c:\src\upstream\llvm_clean\tools\clang\tools\driver\cc1_main.cpp:218:0

​28 0x00007ff70c04b0b8 ExecuteCC1Tool c:\src\upstream\llvm_clean\tools\clang\tools\driver\driver.cpp:320:0

​29 0x00007ff70c04e4d5 main c:\src\upstream\llvm_clean\tools\clang\tools\driver\driver.cpp:382:0

​30 0x00007ff70fb06a65 __scrt_common_main_seh f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253:0

​31 0x00007fff3f311fe4 (C:\WINDOWS\System32\KERNEL32.DLL+0x11fe4)

​32 0x00007fff3fb2cb31 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6cb31)

clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 8.0.0 (trunk 345602) Target: x86_64-scei-ps4 Thread model: posix InstalledDir: C:\src\upstream\345602-win32-RelWithDebInfo\RelWithDebInfo\bin

rotateright commented 5 years ago

Thanks for the bug report and reduction. Should be fixed here: https://reviews.llvm.org/rL345842

It's possible that we may want to allow non-power-of-2 extraction in the future as an optimization, but for now, we just don't try.

rotateright commented 5 years ago

This isn't the main bug, but the f16c attribute was really just standing in for an AVX attribute which has this questionable setting:

// Extract subvector is special because the value type
// (result) is 128-bit but the source is 256-bit wide.
for (auto VT : { MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64,
                 MVT::v4f32, MVT::v2f64 }) {
  setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Legal);
}

We assumed that any extract to 128-bit was coming from a 256-bit vector. But that's not true pre-vector legalization. We can have all kinds of bizarre types there.

So that's why we don't hit the bug without at least -mattr=avx - the extract is not legal/custom, so we bail out before getting into more serious trouble.

rotateright commented 5 years ago

Reduced more:

define <3 x float> @​#39511 (<4 x float> %t0, <3 x float>* %b) #​0 { %add = fadd <4 x float> %t0, <float 0.0, float 0.0, float 0.0, float undef> %ext = shufflevector <4 x float> %add, <4 x float> undef, <3 x i32> <i32 0, i32 1, i32 2> ret <3 x float> %ext }

attributes #​0 = { "target-features"="+f16c" }


Not sure yet what affect "f16c" has, but that seems to be required to hit the bug, so that might be why it only seemed to occur on Windows?

gregbedwell commented 5 years ago

Reduced:

greg@greg-win10:/mnt/e/work/upstream-llvm/build-gcc-native-ninja$ cat 1.ll @​a = global <4 x float> zeroinitializer@b = global i32 4 define void @​c()

​0 {

entry: load <4 x float>, <4 x float> @​a %add = fadd <4 x float> %0, <float 0.000000e00, float 0.000000e00, float 0.000000e00, float undef> %e.f.0.0.g.extract = shufflevector <4 x float> %add, <4 x float> undef, <3 x i32> <i32 0, i32 1, i32 2> store <3 x float> %e.f.0.0.g.extract, <3 x float> bitcast (i32 @​b to <3 x float>) ret void }

attributes #​0 = { "target-features"="+aes,+f16c" }

greg@greg-win10:/mnt/e/work/upstream-llvm/build-gcc-native-ninja$ ./bin/llc --version LLVM (http://llvm.org/): LLVM version 8.0.0 Optimized build with assertions. Default target: x86_64-unknown-linux-gnu Host CPU: broadwell

greg@greg-win10:/mnt/e/work/upstream-llvm/build-gcc-native-ninja$ ./bin/llc 1.ll llc: /mnt/e/work/upstream-llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:7838: 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.