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

[SIMD] crash during 'WebAssembly Instruction Selection' pass #55559

Closed
radekdoulik opened this issue May 18, 2022 · 11 comments
Closed

[SIMD] crash during 'WebAssembly Instruction Selection' pass #55559

radekdoulik opened this issue May 18, 2022 · 11 comments
Assignees
Labels

Comments

@radekdoulik
Copy link

radekdoulik commented May 18, 2022

I experience crash of clang++ during IR compilation, .bc to .o.

The crash:

error : Failed to compile /home/wa-simd/artifacts/obj/mono/Wasm.Console.V8.CJS.Sample/wasm/Debug/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -> /home/wa-simd/artifacts/obj/mono/Wasm.Console.V8.CJS.Sample/wasm/Debug/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.o [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : "/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=9 -fno-inline-functions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/home/wa-319/src/mono/wasm/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -msimd128 -Oz -g3 -v -msimd128 -c /home/wa-simd/artifacts/obj/mono/Wasm.Console.V8.CJS.Sample/wasm/Debug/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -o /tmp/tmpBHuSMr.tmp [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : clang version 15.0.0 (https://github.com/llvm/llvm-project faef447e72a5c63dfb12bb7b02d44c3c916d31cd) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : Target: wasm32-unknown-emscripten [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : Thread model: posix [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : InstalledDir: /home/wa-319/src/mono/wasm/emsdk/upstream/bin [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : (in-process) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : "/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang-15" -cc1 -triple wasm32-unknown-emscripten -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name System.Private.CoreLib.dll.bc -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature +simd128 -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/wa-simd/src/mono/sample/wasm/console-v8-cjs -resource-dir /home/wa-319/src/mono/wasm/emsdk/upstream/lib/clang/15.0.0 -Oz -Werror=implicit-function-declaration -fdebug-compilation-dir=/home/wa-simd/src/mono/sample/wasm/console-v8-cjs -ferror-limit 19 -fvisibility default -fgnuc-version=4.2.1 -fno-inline-functions -vectorize-slp -iwithsysroot/include/SDL -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/tmpBHuSMr.tmp -x ir /home/wa-simd/artifacts/obj/mono/Wasm.Console.V8.CJS.Sample/wasm/Debug/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : clang -cc1 version 15.0.0 based upon LLVM 15.0.0git default target x86_64-unknown-linux-gnu [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : Stack dump: [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : 0.	Program arguments: /home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=9 -fno-inline-functions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/home/wa-319/src/mono/wasm/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -msimd128 -Oz -g3 -v -msimd128 -c /home/wa-simd/artifacts/obj/mono/Wasm.Console.V8.CJS.Sample/wasm/Debug/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -o /tmp/tmpBHuSMr.tmp [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : 1.	Code generation [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : 2.	Running pass 'Function Pass Manager' on module '/home/wa-simd/artifacts/obj/mono/Wasm.Console.V8.CJS.Sample/wasm/Debug/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc'. [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : 3.	Running pass 'WebAssembly Instruction Selection' on function '@corlib_System_Runtime_Intrinsics_Wasm_WasmBase_Shuffle_System_Runtime_Intrinsics_Vector128_1_byte_System_Runtime_Intrinsics_Vector128_1_byte_System_Runtime_Intrinsics_Vector128_1_byte' [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #0 0x000055f76c21fd23 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x2d91d23) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #1 0x000055f76c21d71e llvm::sys::RunSignalHandlers() (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x2d8f71e) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #2 0x000055f76c21f013 llvm::sys::CleanupOnSignal(unsigned long) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x2d91013) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #3 0x000055f76c1776e7 CrashRecoverySignalHandler(int) (.llvm.6710840195088801350) CrashRecoveryContext.cpp:0:0 [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #4 0x00007ff6f61743c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #5 0x000055f76ae72af6 llvm::WebAssemblyTargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const WebAssemblyISelLowering.cpp:0:0 [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #6 0x000055f76d277c07 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) (.llvm.13441730628626256814) LegalizeDAG.cpp:0:0 [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #7 0x000055f76d27748d llvm::SelectionDAG::Legalize() (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x3de948d) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #8 0x000055f76d34719c llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x3eb919c) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #9 0x000055f76d3465fc llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x3eb85fc) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #10 0x000055f76d342fcd llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x3eb4fcd) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #11 0x000055f76b56ae9c llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x20dce9c) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #12 0x000055f76ba11f5b llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x2583f5b) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #13 0x000055f76ba1b803 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x258d803) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #14 0x000055f76ba12d86 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x2584d86) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #15 0x000055f76ca7b9ef clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::__2::unique_ptr<llvm::raw_pwrite_stream, std::__2::default_delete<llvm::raw_pwrite_stream> >) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x35ed9ef) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #16 0x000055f76ce9658a clang::CodeGenAction::ExecuteAction() (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x3a0858a) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #17 0x000055f76cdb6945 clang::FrontendAction::Execute() (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x3928945) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #18 0x000055f76cd165e2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x38885e2) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #19 0x000055f76ce90e36 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x3a02e36) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #20 0x000055f76ade0860 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x1952860) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #21 0x000055f76adde896 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0 [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #22 0x000055f76cb52552 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >*, bool*) const::$_1>(long) Job.cpp:0:0 [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #23 0x000055f76c177197 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x2ce9197) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #24 0x000055f76cb521a9 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >*, bool*) const (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x36c41a9) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #25 0x000055f76cb119b5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x36839b5) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #26 0x000055f76cb2fcac clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*> >&) (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x36a1cac) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #27 0x000055f76adddf07 main (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x194ff07) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #28 0x00007ff6f5dfa0b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3 [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : #29 0x000055f76ad5e46a _start (/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang+++0x18d046a) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : clang-15: error: clang frontend command failed with exit code 139 (use -v to see invocation) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : clang version 15.0.0 (https://github.com/llvm/llvm-project faef447e72a5c63dfb12bb7b02d44c3c916d31cd) [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : Target: wasm32-unknown-emscripten [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : Thread model: posix [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : InstalledDir: /home/wa-319/src/mono/wasm/emsdk/upstream/bin [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : clang-15: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs. [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]
error : emcc: error: '/home/wa-319/src/mono/wasm/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=9 -fno-inline-functions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/home/wa-319/src/mono/wasm/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -msimd128 -Oz -g3 -v -msimd128 -c /home/wa-simd/artifacts/obj/mono/Wasm.Console.V8.CJS.Sample/wasm/Debug/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -o /tmp/tmpBHuSMr.tmp' failed (returned 139) [took 22.341s] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj] [/home/wa-simd/src/mono/sample/wasm/console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj]

The IR of corlib_System_Runtime_Intrinsics_Wasm_WasmBase_Shuffle_System_Runtime_Intrinsics_Vector128_1_byte_System_Runtime_Intrinsic function:

; Function Attrs: uwtable
define internal void @corlib_System_Runtime_Intrinsics_Wasm_WasmBase_Shuffle_System_Runtime_Intrinsics_Vector128_1_byte_System_Runtime_Intrinsics_Vector128_1_byte_System_Runtime_Intrinsics_Vector128_1_byte(i32 %vret, <16 x i8>* byval(<16 x i8>) %arg_0, <16 x i8>* byval(<16 x i8>) %arg_1, <16 x i8>* byval(<16 x i8>) %arg_2, i32* %dummy_arg) #11 {
BB0:
  %gc_pin = alloca [0 x i32], align 4
  %simd_vtype = load <16 x i8>, <16 x i8>* %arg_0, align 16
  %simd_vtype1 = load <16 x i8>, <16 x i8>* %arg_1, align 16
  %simd_vtype2 = load <16 x i8>, <16 x i8>* %arg_2, align 16
  br label %INIT_BB1

INIT_BB1:                                         ; preds = %BB0
  br label %INITED_BB2

INITED_BB2:                                       ; preds = %INIT_BB1
  br label %BB2

BB2:                                              ; preds = %INITED_BB2
  br label %BB3

BB3:                                              ; preds = %BB2
  %0 = extractelement <16 x i8> %simd_vtype2, i32 0
  %1 = zext i8 %0 to i32
  %2 = extractelement <16 x i8> %simd_vtype2, i32 1
  %3 = zext i8 %2 to i32
  %4 = extractelement <16 x i8> %simd_vtype2, i32 2
  %5 = zext i8 %4 to i32
  %6 = extractelement <16 x i8> %simd_vtype2, i32 3
  %7 = zext i8 %6 to i32
  %8 = extractelement <16 x i8> %simd_vtype2, i32 4
  %9 = zext i8 %8 to i32
  %10 = extractelement <16 x i8> %simd_vtype2, i32 5
  %11 = zext i8 %10 to i32
  %12 = extractelement <16 x i8> %simd_vtype2, i32 6
  %13 = zext i8 %12 to i32
  %14 = extractelement <16 x i8> %simd_vtype2, i32 7
  %15 = zext i8 %14 to i32
  %16 = extractelement <16 x i8> %simd_vtype2, i32 8
  %17 = zext i8 %16 to i32
  %18 = extractelement <16 x i8> %simd_vtype2, i32 9
  %19 = zext i8 %18 to i32
  %20 = extractelement <16 x i8> %simd_vtype2, i32 10
  %21 = zext i8 %20 to i32
  %22 = extractelement <16 x i8> %simd_vtype2, i32 11
  %23 = zext i8 %22 to i32
  %24 = extractelement <16 x i8> %simd_vtype2, i32 12
  %25 = zext i8 %24 to i32
  %26 = extractelement <16 x i8> %simd_vtype2, i32 13
  %27 = zext i8 %26 to i32
  %28 = extractelement <16 x i8> %simd_vtype2, i32 14
  %29 = zext i8 %28 to i32
  %30 = extractelement <16 x i8> %simd_vtype2, i32 15
  %31 = zext i8 %30 to i32
  %i8x16.shuffle = call <16 x i8> @llvm.wasm.shuffle(<16 x i8> %simd_vtype, <16 x i8> %simd_vtype1, i32 %1, i32 %3, i32 %5, i32 %7, i32 %9, i32 %11, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31)
  %32 = add i32 %vret, 0
  %33 = inttoptr i32 %32 to <16 x i8>*
  store <16 x i8> %i8x16.shuffle, <16 x i8>* %33, align 1
  br label %BB1

BB1:                                              ; preds = %BB3
  ret void
}
@llvmbot
Copy link
Collaborator

llvmbot commented May 18, 2022

@llvm/issue-subscribers-backend-webassembly

@kg
Copy link

kg commented May 1, 2023

I get this intermittently when doing AOT builds in the .NET runtime for test suites. I managed to capture a repro where running the same build command fails every time. The command is:

"/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang-17" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name System.Private.CoreLib.dll.bc -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +exception-handling -mllvm -wasm-enable-eh -target-feature +exception-handling -exception-model=wasm -target-cpu generic -target-feature +simd128 -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/kate/Projects/dotnet-runtime-wasm/src/libraries/System.Memory/tests -resource-dir /home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/lib/clang/17 -O2 -fdebug-compilation-dir=/home/kate/Projects/dotnet-runtime-wasm/src/libraries/System.Memory/tests -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -exception-model=wasm -vectorize-loops -vectorize-slp -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -o /tmp/tmpCcaoe0.tmp -x ir /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc

I believe this invocation was performed by emscripten emcc, so I don't know why a given option is or isn't there.

log from the failure:

 Failed to compile /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -> /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.o
 emcc: warning: linker setting ignored during compilation: 'EXPORT_ES6' [-Wunused-command-line-argument]
  "/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -O2 -g3 -v -fwasm-exceptions -msimd128 -c /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -o /tmp/tmpCcaoe0.tmp
 clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
 Target: wasm32-unknown-emscripten
 Thread model: posix
 InstalledDir: /home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin
  (in-process)
  "/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang-17" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name System.Private.CoreLib.dll.bc -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +exception-handling -mllvm -wasm-enable-eh -target-feature +exception-handling -exception-model=wasm -target-cpu generic -target-feature +simd128 -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/kate/Projects/dotnet-runtime-wasm/src/libraries/System.Memory/tests -resource-dir /home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/lib/clang/17 -O2 -fdebug-compilation-dir=/home/kate/Projects/dotnet-runtime-wasm/src/libraries/System.Memory/tests -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -exception-model=wasm -vectorize-loops -vectorize-slp -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -o /tmp/tmpCcaoe0.tmp -x ir /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc
 clang -cc1 version 17.0.0 based upon LLVM 17.0.0git default target x86_64-unknown-linux-gnu
 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: /home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -O2 -g3 -v -fwasm-exceptions -msimd128 -c /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -o /tmp/tmpCcaoe0.tmp
 1.   Code generation
 2.   Running pass 'Function Pass Manager' on module '/home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc'.
 3.   Running pass 'WebAssembly Instruction Selection' on function '@corlib_System_Runtime_Intrinsics_Wasm_PackedSimd_Shuffle_System_Runtime_Intrinsics_Vector128_1_sbyte_System_Runtime_Intrinsics_Vector128_1_sbyte_System_Runtime_Intrinsics_Vector128_1_sbyte'
  #0 0x000055848f6d5a18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x2dbda18)
  #1 0x000055848f6d337e llvm::sys::RunSignalHandlers() (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x2dbb37e)
  #2 0x000055848f6d4cd1 llvm::sys::CleanupOnSignal(unsigned long) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x2dbccd1)
  #3 0x000055848f644919 CrashRecoverySignalHandler(int) (.llvm.276048425087711484) CrashRecoveryContext.cpp:0:0
  #4 0x00007f83cf44e140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140)
  #5 0x000055848e4d1e08 llvm::WebAssemblyTargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const WebAssemblyISelLowering.cpp:0:0
  #6 0x0000558490843600 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) (.llvm.11157231605826257144) LegalizeDAG.cpp:0:0
  #7 0x0000558490842fcd llvm::SelectionDAG::Legalize() (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x3f2afcd)
  #8 0x0000558490918c5b llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x4000c5b)
  #9 0x0000558490917be1 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x3fffbe1)
 #10 0x000055849091498f llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x3ffc98f)
 #11 0x000055848ebf19f8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x22d99f8)
 #12 0x000055848f12654a llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x280e54a)
 #13 0x000055848f1301a3 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x28181a3)
 #14 0x000055848f1273b6 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x280f3b6)
 #15 0x000055848feeeb68 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__2::unique_ptr<llvm::raw_pwrite_stream, std::__2::default_delete<llvm::raw_pwrite_stream>>) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x35d6b68)
 #16 0x0000558490453973 clang::CodeGenAction::ExecuteAction() (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x3b3b973)
 #17 0x0000558490363581 clang::FrontendAction::Execute() (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x3a4b581)
 #18 0x00005584902b8f00 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x39a0f00)
 #19 0x000055849044dd86 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x3b35d86)
 #20 0x000055848e4404f1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x1b284f1)
 #21 0x000055848e43cfc1 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
 #22 0x00005584900d1399 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
 #23 0x000055848f64469c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x2d2c69c)
 #24 0x00005584900d0be5 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x37b8be5)
 #25 0x00005584900875fe clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x376f5fe)
 #26 0x00005584900ace2c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*>>&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x3794e2c)
 #27 0x000055848e43be9b clang_main(int, char**, llvm::ToolContext const&) (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x1b23e9b)
 #28 0x000055848e44df21 main (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x1b35f21)
 #29 0x00007f83cf0fdd0a __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d0a)
 #30 0x000055848e3ae42a _start (/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang+++0x1a9642a)
 clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
 clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
 Target: wasm32-unknown-emscripten
 Thread model: posix
 InstalledDir: /home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin
 clang++: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
 emcc: error: '/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/home/kate/Projects/dotnet-runtime-wasm/src/mono/wasm/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -O2 -g3 -v -fwasm-exceptions -msimd128 -c /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/System.Memory.Tests/Release/net8.0/browser-wasm/wasm/for-publish/System.Private.CoreLib.dll.bc -o /tmp/tmpCcaoe0.tmp' failed (returned 1) [took 52.938s]

This zip file should contain the directory structure matching the files referenced by the command:
isel.zip
The .bc file is really big :( But I'm pretty sure it's the same method as the one @radekdoulik provided when filing this issue.

@vargaz
Copy link

vargaz commented May 2, 2023

Reduced testcase:

target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-emscripten"

attributes #10 = { nounwind readnone speculatable }

; Function Attrs: nounwind readnone speculatable
declare <16 x i8> @llvm.wasm.shuffle(<16 x i8>, <16 x i8>, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) #10

define void @foo(i32 %vret, <16 x i8>* byval(<16 x i8>) %arg_lower, <16 x i8>* byval(<16 x i8>) %arg_upper, <16 x i8>* byval(<16 x i8>) %arg_indices, i32* %dummy_arg) #2 {
BB0:
  %simd_vtype = load <16 x i8>, <16 x i8>* %arg_lower, align 16
  %simd_vtype1 = load <16 x i8>, <16 x i8>* %arg_upper, align 16
  %simd_vtype2 = load <16 x i8>, <16 x i8>* %arg_indices, align 16
  %0 = extractelement <16 x i8> %simd_vtype2, i32 0
  %1 = zext i8 %0 to i32
  %2 = extractelement <16 x i8> %simd_vtype2, i32 1
  %3 = zext i8 %2 to i32
  %4 = extractelement <16 x i8> %simd_vtype2, i32 2
  %5 = zext i8 %4 to i32
  %6 = extractelement <16 x i8> %simd_vtype2, i32 3
  %7 = zext i8 %6 to i32
  %8 = extractelement <16 x i8> %simd_vtype2, i32 4
  %9 = zext i8 %8 to i32
  %10 = extractelement <16 x i8> %simd_vtype2, i32 5
  %11 = zext i8 %10 to i32
  %12 = extractelement <16 x i8> %simd_vtype2, i32 6
  %13 = zext i8 %12 to i32
  %14 = extractelement <16 x i8> %simd_vtype2, i32 7
  %15 = zext i8 %14 to i32
  %16 = extractelement <16 x i8> %simd_vtype2, i32 8
  %17 = zext i8 %16 to i32
  %18 = extractelement <16 x i8> %simd_vtype2, i32 9
  %19 = zext i8 %18 to i32
  %20 = extractelement <16 x i8> %simd_vtype2, i32 10
  %21 = zext i8 %20 to i32
  %22 = extractelement <16 x i8> %simd_vtype2, i32 11
  %23 = zext i8 %22 to i32
  %24 = extractelement <16 x i8> %simd_vtype2, i32 12
  %25 = zext i8 %24 to i32
  %26 = extractelement <16 x i8> %simd_vtype2, i32 13
  %27 = zext i8 %26 to i32
  %28 = extractelement <16 x i8> %simd_vtype2, i32 14
  %29 = zext i8 %28 to i32
  %30 = extractelement <16 x i8> %simd_vtype2, i32 15
  %31 = zext i8 %30 to i32
  %i8x16.shuffle = call <16 x i8> @llvm.wasm.shuffle(<16 x i8> %simd_vtype, <16 x i8> %simd_vtype1, i32 %1, i32 %3, i32 %5, i32 %7, i32 %9, i32 %11, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31)
  %32 = add i32 %vret, 0
  %33 = inttoptr i32 %32 to <16 x i8>*
  store <16 x i8> %i8x16.shuffle, <16 x i8>* %33, align 1
  ret void
}

To reproduce:

clang-17 -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -discard-value-names -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +exception-handling -mllvm -wasm-enable-eh -target-feature +exception-handling -exception-model=wasm -target-cpu generic -target-feature +simd128 -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -O2 -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -exception-model=wasm -vectorize-loops -vectorize-slp -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -o foo.tmp -x ir foo.bc

Version:
clang -cc1 version 17.0.0 based upon LLVM 17.0.0git default target x86_64-apple-darwin22.4.0

The clang executable is upstream/bin/clang-17 from emscripten 3.1.34.

@tlively
Copy link
Collaborator

tlively commented May 4, 2023

The @llvm.wasm.shuffle intrinsic is only meant to be used with immediate lane index arguments, but we don't currently have it declared that way in LLVM. That means that using it with non-immediate arguments validates fine and then crashes in the backend when the backend assumes the lane indices are constants.

I'll upload a patch fixing the intrinsic definition, but that means that these reproducer bitcode files will fail to validate instead of crash the backend, which isn't much better. How are they generated, and can that part be fixed?

@tlively
Copy link
Collaborator

tlively commented May 4, 2023

@vargaz
Copy link

vargaz commented May 4, 2023

If this is by design, then we will fix it in our code. Thanks.

@vargaz
Copy link

vargaz commented May 4, 2023

The compiler generating the llvm IR might not be able to determine whenever the arguments are constants.
Does llvm have some kind of support for handling constantness in generated IR, i.e. (just pseudo code)
if (is_constant(index1) ...) wasm.shuffle (..., make_constant(index1)); else
?

@tlively
Copy link
Collaborator

tlively commented May 5, 2023

The simplest thing to do here is probably to use the shufflevector instruction instead of the @llvm.wasm.shuffle intrinsic. shufflevector does not require its lane indices to be constants, but if they are, it will lower to the same i8x16.shuffle instruction. The only reason @llvm.wasm.shuffle exists is because some users of the wasm_simd128.h intrinsic functions were unhappy with how their hand-written shuffles were being optimized and combined when the intrinsics used shufflevector`.

@radekdoulik
Copy link
Author

The simplest thing to do here is probably to use the shufflevector instruction instead of the @llvm.wasm.shuffle intrinsic. shufflevector does not require its lane indices to be constants, but if they are, it will lower to the same i8x16.shuffle instruction. The only reason @llvm.wasm.shuffle exists is because some users of the wasm_simd128.h intrinsic functions were unhappy with how their hand-written shuffles were being optimized and combined when the intrinsics used shufflevector`.

That is great. I missed you reply til now, I will try to use BuildShuffleVector and hopefully that will solve our issue.

@radekdoulik
Copy link
Author

@tlively I tried to use LLVMBuildShuffleVector to create the shufflevector instruction. I get another crash when I pass non constant vector as mask.

I pass these values as arguments

  V1:   %simd_vtype = load <16 x i8>, ptr %arg_0, align 16
  V2:   %simd_vtype1 = load <16 x i8>, ptr %arg_1, align 16
  Mask: %simd_vtype2 = load <16 x i8>, ptr %arg_2, align 16

and then it crashes in

Process 3503 stopped
* thread #1, name = 'tid_103', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x000000010077f3b8 mono-aot-cross`llvm::ShuffleVectorInst::getShuffleMask(llvm::Constant const*, llvm::SmallVectorImpl<int>&) + 420
mono-aot-cross`llvm::ShuffleVectorInst::getShuffleMask:
->  0x10077f3b8 <+420>: ldrb   w8, [x0, #0x10]
    0x10077f3bc <+424>: sub    w8, w8, #0xb
    0x10077f3c0 <+428>: cmp    w8, #0x2
    0x10077f3c4 <+432>: b.hs   0x10077f3d0               ; <+444>
Target 0: (mono-aot-cross) stopped.
(lldb) up
frame #1: 0x00000001006dd6b8 mono-aot-cross`LLVMBuildShuffleVector + 128
mono-aot-cross`LLVMBuildShuffleVector:
->  0x1006dd6b8 <+128>: ldr    x23, [sp, #0x58]
    0x1006dd6bc <+132>: ldr    w24, [sp, #0x60]
    0x1006dd6c0 <+136>: ldr    x0, [x19, #0x48]
    0x1006dd6c4 <+140>: ldr    x8, [x0]

It works fine when I replace the mask with constant vector, like <16 x i8> <i8 0, i8 1, i8 2, i8 3, i8 16, i8 17, i8 18, i8 19, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>.

@tlively
Copy link
Collaborator

tlively commented Aug 21, 2023

@radekdoulik, sorry about that, I was mistaken when I said that shufflevector allows non-constant lane indices. For non-constant indices, I don't know a better solution than building up the vector one lane at a time. LLVM should do a decent job of recognizing that you're building a vector and will try to optimize it. We have some logic for this in the WebAssembly backend, but there's probably room for improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants