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

Code generator does not support intrinsic functions llvm.abs.*, llvm.is.constant.* #149

Open
nonchip opened this issue Dec 28, 2021 · 1 comment

Comments

@nonchip
Copy link

nonchip commented Dec 28, 2021

something something "missing functionality", but also: i wonder if it would be possible to turn that fatal error into a warning instead and have the user provide such missing functions? after all they are emitted into the resulting C code, so it should be rather trivial to just emit a declaration and go "this isn't a thing yet, just implement it yourself for now" without requiring people to learn how to hack the LLVM internals?

LLVM ERROR: Code generator does not support intrinsic function 'llvm.abs.i64'!
 #0 0x00007f3b61b10cad llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM-12.so+0xbdfcad)
 #1 0x00007f3b61b0e984 llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-12.so+0xbdd984)
 #2 0x00007f3b61b0eafb (/usr/lib/libLLVM-12.so+0xbddafb)
 #3 0x00007f3b609e0000 __restore_rt (/usr/lib/libc.so.6+0x3d000)
 #4 0x00007f3b609dff81 raise /builddir/glibc-2.32/signal/../sysdeps/unix/sysv/linux/raise.c:50:1
 #5 0x00007f3b609c9536 abort /builddir/glibc-2.32/stdlib/abort.c:81:7
 #6 0x00007f3b61a4450f llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib/libLLVM-12.so+0xb1350f)
 #7 0x00007f3b61e2aa8d llvm::IntrinsicLowering::LowerIntrinsicCall(llvm::CallInst*) (/usr/lib/libLLVM-12.so+0xef9a8d)
 #8 0x0000562f073ae5cf llvm_cbe::CWriter::lowerIntrinsics(llvm::Function&) (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x325cf)
 #9 0x0000562f07398a69 llvm_cbe::CWriter::runOnFunction(llvm::Function&) (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x1ca69)
#10 0x00007f3b61c676b0 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/libLLVM-12.so+0xd366b0)
#11 0x00007f3b61c68c9c llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/libLLVM-12.so+0xd37c9c)
#12 0x00007f3b61c66fc8 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/libLLVM-12.so+0xd35fc8)
#13 0x0000562f0738fe94 compileModule(char**, llvm::LLVMContext&) (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x13e94)
#14 0x0000562f0738f27e main (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x1327e)
#15 0x00007f3b609cae0a __libc_start_main /builddir/glibc-2.32/csu/../csu/libc-start.c:314:16
#16 0x0000562f0738ea2a _start /builddir/glibc-2.32/csu/../sysdeps/x86_64/start.S:122:0
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: llvm-cbe -- runtime.ll
1.      Running pass 'Function Pass Manager' on module 'runtime.ll'.
2.      Running pass 'C backend' on function '@"_ZNSt8__detail9__variant17__gen_vtable_implINS0_12_Multi_arrayIPFNS0_21__deduce_visit_resultINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEON9ncxxforth7visitorIJZSt9to_stringRKSt7variantIJlPNSB_4WordEmPFvRNSB_5ForthEES9_St17basic_string_viewIcS7_EEEE3$_0ZSt9to_stringSO_E3$_1ZSt9to_stringSO_E3$_2ZSt9to_stringSO_E3$_3ZSt9to_stringSO_E3$_4ZSt9to_stringSO_E3$_5EEESO_EJEEESt16integer_sequenceImJLm0EEEE14__visit_invokeESW_SO_"'
[1]    28600 abort      llvm-cbe -- runtime.ll

runtime.ll

@nonchip
Copy link
Author

nonchip commented Jan 2, 2022

i decided to mess with the actual compiler a bit to maybe make it use less features by claiming to target MIPS1 (which is gonna be better for the compiler that will handle the resulting c code anyway, because i'm planning to feed that into a rather ancient cpu) and also disabling any optimization, that got rid of the 64bit abs, but now it's dying due to llvm.is.constant.i32:

LLVM ERROR: Code generator does not support intrinsic function 'llvm.is.constant.i32'!
 #0 0x00007fb4ed40ecad llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM-12.so+0xbdfcad)
 #1 0x00007fb4ed40c984 llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-12.so+0xbdd984)
 #2 0x00007fb4ed40cafb (/usr/lib/libLLVM-12.so+0xbddafb)
 #3 0x00007fb4ec2de000 __restore_rt (/usr/lib/libc.so.6+0x3d000)
 #4 0x00007fb4ec2ddf81 raise /builddir/glibc-2.32/signal/../sysdeps/unix/sysv/linux/raise.c:50:1
 #5 0x00007fb4ec2c7536 abort /builddir/glibc-2.32/stdlib/abort.c:81:7
 #6 0x00007fb4ed34250f llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib/libLLVM-12.so+0xb1350f)
 #7 0x00007fb4ed728a8d llvm::IntrinsicLowering::LowerIntrinsicCall(llvm::CallInst*) (/usr/lib/libLLVM-12.so+0xef9a8d)
 #8 0x000055656bd085cf llvm_cbe::CWriter::lowerIntrinsics(llvm::Function&) (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x325cf)
 #9 0x000055656bcf2a69 llvm_cbe::CWriter::runOnFunction(llvm::Function&) (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x1ca69)
#10 0x00007fb4ed5656b0 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/libLLVM-12.so+0xd366b0)
#11 0x00007fb4ed566c9c llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/libLLVM-12.so+0xd37c9c)
#12 0x00007fb4ed564fc8 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/libLLVM-12.so+0xd35fc8)
#13 0x000055656bce9e94 compileModule(char**, llvm::LLVMContext&) (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x13e94)
#14 0x000055656bce927e main (/home/kyra/src/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x1327e)
#15 0x00007fb4ec2c8e0a __libc_start_main /builddir/glibc-2.32/csu/../csu/libc-start.c:314:16
#16 0x000055656bce8a2a _start /builddir/glibc-2.32/csu/../sysdeps/x86_64/start.S:122:0
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: llvm-cbe -- runtime.ll
1.      Running pass 'Function Pass Manager' on module 'runtime.ll'.
2.      Running pass 'C backend' on function '@_ZNSt11char_traitsIcE7compareEPKcS2_j'
[1]    9009 abort      llvm-cbe -- runtime.ll

runtime.ll

for the record, the code we're talking about is there, and i compiled it using:

$ ~/src/llvm-project/build/bin/clang++ -std=c++20 --target=mips-linux-musl \
  --sysroot=/usr/mips-linux-musl -I/usr/mips-linux-musl/include \
  -I/usr/mips-linux-musl/usr/include/ -I/usr/mips-linux-musl/usr/include/c++/10.2/ \
  -I/usr/mips-linux-musl/usr/include/c++/10.2/mips-linux-musl \
  -O0 -emit-llvm runtime.cpp -S -o runtime.ll

i also tried manually compiling a function that satisfies the intrinsic's documentation, and then patching that into the ll file by hand, but sadly isIntrinsic seems to take precedence over "is already there", so it gets ignored and LowerIntrinsicCall still complains about being called for it.

@nonchip nonchip changed the title Code generator does not support intrinsic function llvm.abs.i64 Code generator does not support intrinsic functions llvm.abs.*, llvm.is.constant.* Jan 2, 2022
bcoppens added a commit to bcoppens/llvm-cbe that referenced this issue Dec 19, 2023
…LVM LangRef, this intrinsic will never return true when constant folding is not run, so always returning false is safe. Partially resolves issue JuliaHubOSS#149
vtjnash pushed a commit that referenced this issue Jan 12, 2024
Add support for the llvm.is.constant.* intrinsics. According to the
LLVM LangRef, this intrinsic will never return true when constant
folding is not run, so always returning false is safe. Partially
resolves issue #149.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants