ARM float16 intrinsic test

Dear list,

git checkout llvmorg-8.0.0 -b llvm8.0

cmake -G “Unix Makefiles” …/llvm-project/llvm -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS=“clang;lld” -DLLVM_TARGETS_TO_BUILD=“X86;NVPTX;AMDGPU;ARM;AArch64”

[arm.cpp]
#define vst4_lane_f16(__p0, __p1, __p2) extension ({
float16x4x4_t __s1 = __p1;
__builtin_neon_vst4_lane_v(__p0, __s1.val[0], __s1.val[1], __s1.val[2], __s1.val[3], __p2, 8);
})
typedef __fp16 float16_t;
typedef attribute((neon_vector_type(4))) float16_t float16x4_t;
typedef struct float16x4x4_t {
float16x4_t val[4];
} float16x4x4_t;
void test_vst4_lane_f16(float16_t * a, float16x4x4_t b) {
vst4_lane_f16(a, b, 3);
}

I tried:
$$COMP_ROOT/clang -cc1 -triple thumbv7s-apple-darwin -target-abi apcs-gnu -target-cpu swift -fallow-half-arguments-and-returns -target-feature +fullfp16 -ffreestanding -disable-O0-optnone -emit-llvm -o arm.ll arm.cpp
$cat arm.ll | grep llvm.arm

call void @llvm.arm.neon.vst4lane.p0i8.v4f16(i8* %4, <4 x half> %13, <4 x half> %14, <4 x half> %15, <4 x half> %16, i32 3, i32 2)
declare void @llvm.arm.neon.vst4lane.p0i8.v4f16(i8*, <4 x half>, <4 x half>, <4 x half>, <4 x half>, i32, i32) #1
$$COMP_ROOT/llc arm.ll
unhandled vld/vst lane type
UNREACHABLE executed at /home/nancy/rpp_llvm/llvm-project/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:2072!

May I know how to compile this .cpp correctly from FE to BE?

Hello,

The compiler really shouldn’t crash, we should raise a bug report for that, but I think this is an options problem.

Looks like you want to target FP16 because you’re using -target-feature +fullfp16. FP16 is an extension to Armv8.2-A, and so something like this worked for me:

clang++ --target=arm-arm-eabihf -march=armv8.2a+fp16 arm.cpp -S -o - -O3

and gives:

_Z18test_vst4_lane_f16PDh13float16x4x4_t:
vst4.16 {d0[3], d1[3], d2[3], d3[3]}, [r0]

bx lr

Is that what you were looking for?
Cheers,
Sjoerd.

Hi,
I do not get your result. Do I miss something?
$COMP_ROOT/clang++ --target=arm-arm-eabihf -march=armv8.2a+fp16
arm.cpp -S -o - -O3

    .text
    .syntax unified
    .eabi_attribute 67, "2.09"
    .eabi_attribute 6, 14
    .eabi_attribute 7, 65
    .eabi_attribute 8, 1
    .eabi_attribute 9, 2
    .fpu crypto-neon-fp-armv8
    .eabi_attribute 12, 4
    .eabi_attribute 36, 1
    .eabi_attribute 42, 1
    .eabi_attribute 34, 0
    .eabi_attribute 68, 3
    .eabi_attribute 17, 1
    .eabi_attribute 20, 1
    .eabi_attribute 21, 1
    .eabi_attribute 23, 3
    .eabi_attribute 24, 1
    .eabi_attribute 25, 1
    .eabi_attribute 28, 1
    .eabi_attribute 38, 1
    .eabi_attribute 18, 4
    .eabi_attribute 26, 2
    .eabi_attribute 14, 0
    .file "arm.cpp"
unhandled vld/vst lane type
UNREACHABLE executed at
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:2072!
Stack dump:
0. Program arguments:
/home/nancy/rpp_llvm/build-project/bin/clang-8 -cc1 -triple
armv8.2a-arm-unknown-eabihf -S -disable-free -main-file-name arm.cpp
-mrelocation-model static -mthread-model posix -mdisable-fp-elim
-fmath-errno -mconstructor-aliases -nostdsysteminc -target-cpu generic
-target-feature +fullfp16 -target-feature +strict-align -target-abi
aapcs -mfloat-abi hard -fallow-half-arguments-and-returns
-dwarf-column-info -debugger-tuning=gdb -coverage-notes-file
/home/nancy/rpp_llvm/test/-.gcno -resource-dir
/home/nancy/rpp_llvm/build-project/lib/clang/8.0.0 -internal-isystem
/home/nancy/rpp_llvm/build-project/lib/clang/8.0.0/include
-internal-isystem include -O3 -fdeprecated-macro
-fdebug-compilation-dir /home/nancy/rpp_llvm/test -ferror-limit 19
-fmessage-length 81 -fno-signed-char -fobjc-runtime=gcc
-fcxx-exceptions -fexceptions -fdiagnostics-show-option
-vectorize-loops -vectorize-slp -o - -x c++ arm.cpp -faddrsig
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'arm.cpp'.
4. Running pass 'ARM Instruction Selection' on function
'@_Z18test_vst4_lane_f16PDh13float16x4x4_t'
#0 0x000000000444190d llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:495:0
#1 0x00000000044419a0 PrintStackTraceSignalHandler(void*)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:559:0
#2 0x000000000443f55a llvm::sys::RunSignalHandlers()
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Support/Signals.cpp:69:0
#3 0x0000000004441308 SignalHandler(int)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:358:0
#4 0x00007fc6fa271390 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#5 0x00007fc6f8fe3428 gsignal
/build/glibc-LK5gWL/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
#6 0x00007fc6f8fe502a abort /build/glibc-LK5gWL/glibc-2.23/stdlib/abort.c:91:0
#7 0x00000000043abcc4 bindingsErrorHandler(void*,
std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, bool)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Support/ErrorHandling.cpp:231:0
#8 0x0000000002db244e (anonymous
namespace)::ARMDAGToDAGISel::SelectVLDSTLane(llvm::SDNode*, bool,
bool, unsigned int, unsigned short const*, unsigned short const*)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:2074:0
#9 0x0000000002dbc3ad (anonymous
namespace)::ARMDAGToDAGISel::Select(llvm::SDNode*)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:3781:0
#10 0x000000000559dc93
llvm::SelectionDAGISel::DoInstructionSelection()
/home/nancy/rpp_llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1068:0
#11 0x000000000559cfdd llvm::SelectionDAGISel::CodeGenAndEmitDAG()
/home/nancy/rpp_llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:907:0
#12 0x000000000559b467
llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction,
true, false, void>, false, true>,
llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction,
true, false, void>, false, true>, bool&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:670:0
#13 0x00000000055a19ed
llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1789:0
#14 0x000000000559a134
llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:472:0
#15 0x0000000002d9f8af (anonymous
namespace)::ARMDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp:66:0
#16 0x0000000003689502
llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:74:0
#17 0x0000000003b752e7
llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1644:0
#18 0x0000000003b75559 llvm::FPPassManager::runOnModule(llvm::Module&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1679:0
#19 0x0000000003b75960 (anonymous
namespace)::MPPassManager::runOnModule(llvm::Module&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1744:0
#20 0x0000000003b7616d
llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1857:0
#21 0x0000000003b763b1 llvm::legacy::PassManager::run(llvm::Module&)
/home/nancy/rpp_llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1889:0
#22 0x000000000473cfa9 (anonymous
namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
/home/nancy/rpp_llvm/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:881:0
#23 0x00000000047404ee
clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&,
llvm::DataLayout const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
/home/nancy/rpp_llvm/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1318:0
#24 0x0000000005692719
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
/home/nancy/rpp_llvm/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:295:0
#25 0x0000000006bf44fb clang::ParseAST(clang::Sema&, bool, bool)
/home/nancy/rpp_llvm/llvm-project/clang/lib/Parse/ParseAST.cpp:177:0
#26 0x0000000004f12e87 clang::ASTFrontendAction::ExecuteAction()
/home/nancy/rpp_llvm/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1037:0
#27 0x0000000005690548 clang::CodeGenAction::ExecuteAction()
/home/nancy/rpp_llvm/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1049:0
#28 0x0000000004f12866 clang::FrontendAction::Execute()
/home/nancy/rpp_llvm/llvm-project/clang/lib/Frontend/FrontendAction.cpp:939:0
#29 0x0000000004e98ebc
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/home/nancy/rpp_llvm/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:956:0
#30 0x00000000050718fd
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/home/nancy/rpp_llvm/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:268:0
#31 0x00000000024795a0 cc1_main(llvm::ArrayRef<char const*>, char
const*, void*) /home/nancy/rpp_llvm/llvm-project/clang/tools/driver/cc1_main.cpp:219:0
#32 0x000000000246e87c ExecuteCC1Tool(llvm::ArrayRef<char const*>,
llvm::StringRef)
/home/nancy/rpp_llvm/llvm-project/clang/tools/driver/driver.cpp:310:0
#33 0x000000000246f5c1 main
/home/nancy/rpp_llvm/llvm-project/clang/tools/driver/driver.cpp:382:0
#34 0x00007fc6f8fce830 __libc_start_main
/build/glibc-LK5gWL/glibc-2.23/csu/../csu/libc-start.c:325:0
#35 0x000000000246c199 _start
(/home/nancy/rpp_llvm/build-project/bin/clang-8+0x246c199)
clang-8: error: unable to execute command: Aborted (core dumped)
clang-8: error: clang frontend command failed due to signal (use -v to
see invocation)
clang version 8.0.0
Target: arm-arm-unknown-eabihf
Thread model: posix
InstalledDir: /home/nancy/rpp_llvm/build-project/bin
clang-8: note: diagnostic msg: PLEASE submit a bug report to
https://bugs.llvm.org/ and include the crash backtrace, preprocessed
source, and associated run script.
clang-8: note: diagnostic msg:

Ah, sorry! You are using a clang-8 build, but I was lazy and quickly tried a trunk build. I can reproduce it yes with clang-8. FP16 in the ARM backend was a bit of work-in-progress around that time, it had some rough edges, and you’re hitting one of them. But we have fixed a lot of them recently, and so it is in a good state now, that’s why my top of trunk build works. As workarounds, which I realise might not be ideal, but you can try using a trunk build, or wait for clang-9 (or avoid this intrinsic if the rest works for you).

Hope this helps,
Sjoerd.

Thank you very much for this infos~