Skip to content

[RISC-V][RVV] Error in backend: Invalid size request on a scalable vector #61561

@mshabunin

Description

@mshabunin

I tried to compile OpenCV library for RISC-V with RVV support using the latest LLVM toolchain and found an error.

fatal error: error in backend: Invalid size request on a scalable vector.
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: 
/work/chains/install-llvm/bin/clang++ \
    --target=riscv64-unknown-linux-gnu \
    --sysroot=/work/chains/riscv64-linux-x86_64-20220906/sysroot \
    -march=rv64gc \
    --gcc-toolchain=/work/chains/riscv64-linux-x86_64-20220906 \
    -w \
    -fmax-errors=3 \
    -Wfatal-errors \
    -fsigned-char \
    -W \
    -Wall \
    -Wreturn-type \
    -Wnon-virtual-dtor \
    -Waddress \
    -Wsequence-point \
    -Wformat \
    -Wformat-security \
    -Wmissing-declarations \
    -Wmissing-prototypes \
    -Wstrict-prototypes \
    -Wundef \
    -Winit-self \
    -Wpointer-arith \
    -Wshadow \
    -Wsign-promo \
    -Wuninitialized \
    -Winconsistent-missing-override \
    -Wno-delete-non-virtual-dtor \
    -Wno-unnamed-type-template-args \
    -Wno-comment \
    -Wno-deprecated-enum-enum-conversion \
    -Wno-deprecated-anon-enum-enum-conversion \
    -fdiagnostics-show-option \
    -pthread \
    -Qunused-arguments \
    -ffunction-sections \
    -fdata-sections \
    -march=rv64gcv \
    -fvisibility=hidden \
    -fvisibility-inlines-hidden \
    -O3 \
    -fPIC \
    -std=c++11 \
    -D_USE_MATH_DEFINES \
    -D__OPENCV_BUILD=1 \
    -D__STDC_CONSTANT_MACROS \
    -D__STDC_FORMAT_MACROS \
    -D__STDC_LIMIT_MACROS \
    -I/work/opencv/modules/imgproc/include \
    -I/work/build-opencv-rvv/modules/imgproc \
    -I/work/opencv/modules/core/include \
    -isystem /work/build-opencv-rvv \
    -DCV_RVV_SCALABLE \
    -DNDEBUG \
    -DNDEBUG \
    -c \
    -MD \
    -MT modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/color_rgb.dispatch.cpp.o \
    -MF modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/color_rgb.dispatch.cpp.o.d \
    -fcolor-diagnostics \
    -o modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/color_rgb.dispatch.cpp.o \
    /work/opencv/modules/imgproc/src/color_rgb.dispatch.cpp
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 
'/work/opencv/modules/imgproc/src/color_rgb.dispatch.cpp'.
4.	Running pass 'RISCV DAG->DAG Pattern Instruction Selection' on function 
'@_ZNK2cv4impl12_GLOBAL__N_120CvtColorLoop_InvokerINS_3hal12cpu_baseline12_GLOBAL__N_111RGB5x52GrayEEclERKNS_5RangeE'
 #0 0x00005564d041b8d6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/chains/install-llvm/bin/clang+++0x39af8d6)
 #1 0x00005564d0419724 llvm::sys::CleanupOnSignal(unsigned long) (/work/chains/install-llvm/bin/clang+++0x39ad724)
 #2 0x00005564d0369f87 llvm::CrashRecoveryContext::HandleExit(int) (/work/chains/install-llvm/bin/clang+++0x38fdf87)
 #3 0x00005564d0411332 llvm::sys::Process::Exit(int, bool) (/work/chains/install-llvm/bin/clang+++0x39a5332)
 #4 0x00005564cdd0e2a7 (/work/chains/install-llvm/bin/clang+++0x12a22a7)
 #5 0x00005564d03737b0 llvm::report_fatal_error(llvm::Twine const&, bool) (/work/chains/install-llvm/bin/clang+++0x39077b0)
 #6 0x00005564d037394e (/work/chains/install-llvm/bin/clang+++0x390794e)
 #7 0x00005564d03bdf6d (/work/chains/install-llvm/bin/clang+++0x3951f6d)
 #8 0x00005564d03bdf94 llvm::TypeSize::operator unsigned long() const (/work/chains/install-llvm/bin/clang+++0x3951f94)
 #9 0x00005564d141de53 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/work/chains/install-llvm/bin/clang+++0x49b1e53)
#10 0x00005564d14194fb llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/work/chains/install-llvm/bin/clang+++0x49ad4fb)
#11 0x00005564d141403f llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/work/chains/install-llvm/bin/clang+++0x49a803f)
#12 0x00005564d141403f llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/work/chains/install-llvm/bin/clang+++0x49a803f)
#13 0x00005564d141f6fa llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/work/chains/install-llvm/bin/clang+++0x49b36fa)
#14 0x00005564d122f72a (anonymous namespace)::DAGCombiner::SimplifyDemandedBits(llvm::SDValue) (.constprop.0) DAGCombiner.cpp:0:0
#15 0x00005564d12811cd (anonymous namespace)::DAGCombiner::visitADDLike(llvm::SDNode*) DAGCombiner.cpp:0:0
#16 0x00005564d1281d38 (anonymous namespace)::DAGCombiner::visitADD(llvm::SDNode*) DAGCombiner.cpp:0:0
#17 0x00005564d12b8a75 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#18 0x00005564d12b9ed4 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) (/work/chains/install-llvm/bin/clang+++0x484ded4)
#19 0x00005564d13c5a52 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/work/chains/install-llvm/bin/clang+++0x4959a52)
#20 0x00005564d13c89aa llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/work/chains/install-llvm/bin/clang+++0x495c9aa)
#21 0x00005564d13cadfe llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#22 0x00005564cf8aea54 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#23 0x00005564cfdba710 llvm::FPPassManager::runOnFunction(llvm::Function&) (/work/chains/install-llvm/bin/clang+++0x334e710)
#24 0x00005564cfdba884 llvm::FPPassManager::runOnModule(llvm::Module&) (/work/chains/install-llvm/bin/clang+++0x334e884)
#25 0x00005564cfdbb284 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/work/chains/install-llvm/bin/clang+++0x334f284)
#26 0x00005564d066b8b6 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::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/work/chains/install-llvm/bin/clang+++0x3bff8b6)
#27 0x00005564d150fe7e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/work/chains/install-llvm/bin/clang+++0x4aa3e7e)
#28 0x00005564d226b279 clang::ParseAST(clang::Sema&, bool, bool) (/work/chains/install-llvm/bin/clang+++0x57ff279)
#29 0x00005564d0e28569 clang::FrontendAction::Execute() (/work/chains/install-llvm/bin/clang+++0x43bc569)
#30 0x00005564d0daed81 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/work/chains/install-llvm/bin/clang+++0x4342d81)
#31 0x00005564d0ee9c58 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/work/chains/install-llvm/bin/clang+++0x447dc58)
#32 0x00005564cdd0f805 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/work/chains/install-llvm/bin/clang+++0x12a3805)
#33 0x00005564cdd0a9cd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x00005564d0c0120d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x00005564d0369e77 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/work/chains/install-llvm/bin/clang+++0x38fde77)
#36 0x00005564d0c015a7 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x00005564d0bcac71 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/work/chains/install-llvm/bin/clang+++0x415ec71)
#38 0x00005564d0bcb74d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/work/chains/install-llvm/bin/clang+++0x415f74d)
#39 0x00005564d0bdc86c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/work/chains/install-llvm/bin/clang+++0x417086c)
#40 0x00005564cdd0d394 clang_main(int, char**, llvm::ToolContext const&) (/work/chains/install-llvm/bin/clang+++0x12a1394)
#41 0x00005564cdc16663 main (/work/chains/install-llvm/bin/clang+++0x11aa663)
#42 0x00007fb71e029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#43 0x00007fb71e029e40 call_init ./csu/../csu/libc-start.c:128:20
#44 0x00007fb71e029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#45 0x00005564cdd06c35 _start (/work/chains/install-llvm/bin/clang+++0x129ac35)
clang++: fatal error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 17.0.0 (https://github.com/llvm/llvm-project.git f406adf134c2f81747bbc653b1399656268fe17a)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/chains/install-llvm/bin

color_rgb-5c44f7.sh.txt
color_rgb-5c44f7.cpp.txt


Just for reference my code is here: https://github.com/mshabunin/opencv/tree/rvv-scalable-gcc
And compile command:

cmake \
        -DCMAKE_BUILD_TYPE=Release \
        -DRISCV_CLANG_BUILD_ROOT=${llvm_root} \
        -DRISCV_GCC_INSTALL_ROOT=${gcc_path} \
        -DCMAKE_TOOLCHAIN_FILE=/work/opencv/platforms/linux/riscv64-clang.toolchain.cmake \
        -DCPU_BASELINE=RVV \
        -DCPU_BASELINE_REQUIRE=RVV \
        -DRISCV_RVV_SCALABLE=ON \
        -DBUILD_SHARED_LIBS=OFF \
        -DWITH_OPENCL=OFF \
        -DOPENCV_EXTRA_CXX_FLAGS="-fmax-errors=3 -Wfatal-errors" \
        ../opencv

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions