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

[BUG] Local stack slot allocation compiler crash on SVE conversion #1834

Closed
ilinpv opened this issue Jan 24, 2023 · 6 comments
Closed

[BUG] Local stack slot allocation compiler crash on SVE conversion #1834

ilinpv opened this issue Jan 24, 2023 · 6 comments
Assignees
Labels
Projects

Comments

@ilinpv
Copy link

ilinpv commented Jan 24, 2023

Description

// main.cpp
#include <arm_sve.h>
void foo(const float16_t * src1) {
  const float16_t *srcs[4] = {src1, src1, src1, src1};
  svuint32x2_t src_ptrs;
  svst2_u32(svptrue_b8(), (uint32_t*)srcs, src_ptrs);
}

Running
~/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ main.cpp --target=aarch64-linux-android25 -march=armv8-a+sve -O0 -c
on current ndk r25b we got

Stack dump:                                                                                                                         
0.      Program arguments: /data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ main.cpp --target=aarch64-linux-android25 -c -march=armv8-a+sve -O0 -c                                                                             
1.      <eof> parser at end of file                                                                                                 
2.      Code generation                                                                                                             
3.      Running pass 'Function Pass Manager' on module 'main.cpp'.                                                                  
4.      Running pass 'Local Stack Slot Allocation' on function '@_Z3fooPKDh'                                                        
 #0 0x00000000047d3da8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x47d3da8)                                                                                        
 #1 0x00000000047d2f10 llvm::sys::RunSignalHandlers() (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x47d2f10)                                                                                                             
 #2 0x000000000479e993 (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x479e993)        
 #3 0x000000000479eb71 (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x479eb71)        
 #4 0x00007f53356df520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)                                                                    
 #5 0x0000000005ef7413 (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x5ef7413)        
 #6 0x0000000005ef7222 (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x5ef7222)        
 #7 0x000000000642057b (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x642057b)        
 #8 0x0000000005d9f8aa llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x5d9f8aa)                                                                                  
 #9 0x0000000005d9fed3 llvm::FPPassManager::runOnFunction(llvm::Function&) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x5d9fed3)                                                                                        
#10 0x0000000005d9fa2f llvm::FPPassManager::runOnModule(llvm::Module&) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x5d9fa2f)                                                                                            
#11 0x0000000006388494 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6388494)                                                                                          
#12 0x00000000065b5328 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream> >) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x65b5328)                                                                              
#13 0x0000000006053215 (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6053215)
#14 0x0000000005ea22e9 clang::ParseAST(clang::Sema&, bool, bool) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x5ea22e9)
#15 0x000000000639ee0d clang::FrontendAction::Execute() (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x639ee0d)
#16 0x000000000639ecad clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x639ecad)
#17 0x000000000639f0c1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x639f0c1)
#18 0x0000000006687454 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6687454)
#19 0x00000000066842e3 (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x66842e3)
#20 0x0000000006684192 (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6684192)
#21 0x0000000006684161 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6684161)
#22 0x0000000006683ef4 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, bool*) const (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6683ef4)
#23 0x0000000006683d5f clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6683d5f)
#24 0x0000000006683bf2 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6683bf2)
#25 0x0000000006655f2e main (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x6655f2e)
#26 0x00007f53356c6d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#27 0x00007f53356c6e40 call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007f53356c6e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#29 0x00000000064b2f69 _start (/data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang+++0x64b2f69)
clang-14: error: clang frontend command failed with exit code 136 (use -v to see invocation)
Android (8490178, based on r450784d) clang version 14.0.6 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9
238af8b4106c30add4418f6)
Target: aarch64-unknown-linux-android25
Thread model: posix
InstalledDir: /data/adb_user/Android/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin
clang-14: note: diagnostic msg: 
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-14: note: diagnostic msg: /tmp/main-d11bac.cpp
clang-14: note: diagnostic msg: /tmp/main-d11bac.sh
clang-14: note: diagnostic msg: 

********************

main-d11bac.zip

Affected versions

r25, Canary

Canary version

android-ndk-9512540-linux-x86_64

Host OS

Linux

Host OS version

Ubuntu 22.04 LTS

Affected ABIs

arm64-v8a

Build system

ndk-build

Other build system

No response

minSdkVersion

0

Device API level

No response

@enh-google
Copy link
Collaborator

yeah, i hit issues trying to enable SVE for the OS itself. talking to Arm they didn't seem surprised, and said that SVE support isn't finished yet. (iirc we've seen linker crashes too.)

this is potentially slightly different because you're trying to use the intrinsics directly rather than the compiler's autovectorization, so i'll make sure we mention this to Arm too.

@ilinpv
Copy link
Author

ilinpv commented Jan 24, 2023

The bug takes place in clang-r450784d, clang-r450784d1, clang-r450784e, but it has been fixed in the next Android toolchain: clang-r458507

@DanAlbert
Copy link
Member

talking to Arm they didn't seem surprised, and said that SVE support isn't finished yet.

If it's still an experimental feature it's not something we usually consider for backports. Likely that it's enough cherry-picks that it risks destabilizing the release. @pirama-arumuga-nainar, wdyt?

it has been fixed in the next Android toolchain: clang-r458507

Excellent, thanks for confirming!

Leaving this bug open since the canary branch is still on the older toolchain.

@pirama-arumuga-nainar
Copy link
Collaborator

@ilinpv: can you bisect to find the commit for the fix? The complexity of the fix could inform us better.

If it's still an experimental feature it's not something we usually consider for backports. Likely that it's enough cherry-picks that it risks destabilizing the release. @pirama-arumuga-nainar, wdyt?

👍 SGTM. Like @enh-google mentioned, there's at least one another issue with sve support in clang. More importantly, it is only usable via FMV (which might be available in r26) or ifuncs. So it'd be prudent for interested users to move to sve when r26 is released.

@ilinpv
Copy link
Author

ilinpv commented Jan 25, 2023

There are a few SVE crash fixes cherry picked from trunk to llvm-14:
llvm/llvm-project@88f8980
llvm/llvm-project@1362f8b
llvm/llvm-project@8c33ea3
llvm/llvm-project@03d9a40
The first 88f8980a4d95b16a0dcd57bb6da298d4d60d8fd1 should fix crash in question. I think it would be good to have remaining ones too.

@DanAlbert
Copy link
Member

If it's still an experimental feature

Talked with @stephenhines and @pirama-arumuga-nainar a bit more and they let me know that that's not really the case here. We're going to check if these are regressions from r24 and have a look at the patches to make sure we can safely take them without risking the stability of the rest of the toolchain. If they look safe, we'll triage this for r25d as well.

@DanAlbert DanAlbert added this to Awaiting triage in LLVM via automation Apr 20, 2023
@DanAlbert DanAlbert moved this from Awaiting triage to Awaiting prebuilt drop in LLVM Apr 20, 2023
@DanAlbert DanAlbert moved this from Awaiting prebuilt drop to Prebuilts submitted in LLVM Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 participants