Add narrowScalar to half of original size for G_ICMP.
ClampScalar G_ICMP's operands 2 and 3 to to s32.
Select G_ICMP for pointers for MIPS32. Pointer compare is same
as for integers, it is enough to declare them as legal type.
Details
Diff Detail
Event Timeline
Hello @Petar.Avramovic , this commit is causing a compiler assert when I perform the following:
- Build clang for aarch64-unknown-linux-gnu
- Use this new compiler to build a shared library version of LLVM's libcxx library, specifically the filesystem/operations.cpp source file.
Here is the CMake for clang:
/tools/build/cmake-3.14.5/bin/cmake \ -D CCACHE_PROGRAM=/tools/build/ccache-3.2.5/usr/bin/ccache \ -D LLVM_CCACHE_BUILD=ON \ -G Ninja \ -D CMAKE_MAKE_PROGRAM=/tools/build/ninja-1.9.0/ninja \ -D 'LLVM_TARGETS_TO_BUILD=X86;AArch64;ARM' \ -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_INSTALL_PREFIX=/work/bmr/bisect \ -D LLVM_PARALLEL_LINK_JOBS=1 \ -D BUILD_SHARED_LIBS=ON \ -D LLVM_ENABLE_ASSERTIONS=ON \ -D LLVM_BINUTILS_INCDIR=/tools/cross/aarch64/buildroot/2019.02_sysroot/lib/gcc/aarch64-samsung-linux-gnu/8.3.0/plugin/include \ -D LIBCXX_ENABLE_SHARED=OFF \ -D LIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \ -D LINK_POLLY_INTO_TOOLS=ON \ -D LLVM_OPTIMIZED_TABLEGEN=ON \ /tmp/tmp.QeEQpbu86Y/src/llvm
This compiler successfully compiles. Next I attempt to build libcxx with this newly-created compiler:
xport CC=/work/bmr/bisect/bin/aarch64-linux-clang export CXX=/work/bmr/bisect/bin/aarch64-linux-clang++ /tools/build/cmake-3.14.5/bin/cmake \ -D CCACHE_PROGRAM=/tools/build/ccache-3.2.5/usr/bin/ccache \ -D LLVM_CCACHE_BUILD=ON \ -D LIBCXX_ENABLE_SHARED=ON \ -G Ninja \ -D CMAKE_MAKE_PROGRAM=/tools/build/ninja-1.9.0/ninja \ -D CMAKE_INSTALL_PREFIX=/work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot \ -D LLVM_PATH=/tmp/tmp.QeEQpbu86Y/src/llvm \ -D LIBCXX_TARGET_TRIPLE=aarch64-samsung-linux-gnu \ -D LIBCXX_CXX_ABI=libcxxabi \ -D LIBCXX_CXX_ABI_INCLUDE_PATHS=/tmp/tmp.QeEQpbu86Y/src/libcxxabi/include \ -D LIBCXX_SYSROOT=/work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot \ -D LIBCXX_GCC_TOOLCHAIN=/work/bmr/bisect/bin \ -D CMAKE_C_FLAGS= \ -D CMAKE_CXX_FLAGS= /tmp/tmp.QeEQpbu86Y/src/libcxx
At step 73 the Assert(..) occurs:
[73/79] /work/bmr/bisect/bin/aarch64-linux-clang++ -DNDEBUG -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_HAS_COMMENT_LIB_PRAGMA -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Iinclude/c++build -I/tmp/tmp.QeEQpbu86Y/src/libcxx/include --target=aarch64-samsung-linux-gnu --sysroot=/work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot --gcc-toolchain=/work/bmr/bisect/bin -fPIC --target=aarch64-samsung-linux-gnu --sysroot=/work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot--gcc-toolchain=/work/bmr/bisect/bin -DLIBCXX_BUILDING_LIBCXXABI -std=c++11 -nostdinc++ -fvisibility-inlines-hidden -Wall -Wextra -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wno-user-defined-literals -Wno-covered-switch-default -Wno-ignored-attributes -Wno-error -MD -MT src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o -MF src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o.d -o src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o -c /tmp/tmp.QeEQpbu86Y/src/libcxx/src/filesystem/operations.cppFAILED: src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o FAILED: src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o clang-9: /tmp/tmp.QeEQpbu86Y/src/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp:904: void llvm::MachineIRBuilder::validateSelectOp(const llvm::LLT &, const llvm::LLT &, const llvm::LLT &, const llvm::LLT &): Assertion `(ResTy == Op0Ty && ResTy == Op1Ty) && "type mismatch"' failed. Stack dump: 0. Program arguments: /work/bmr/bisect/bin/clang-9 -cc1 -triple aarch64-samsung-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name operations.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu generic -target-feature +neon -target-abi aapcs -fallow-half-arguments-and-returns -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /tmp/tmp.QeEQpbu86Y/build/libcxx-shared/src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.gcno -nostdinc++ -resource-dir /work/bmr/bisect/lib/clang/9.0.0 -dependency-file src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o.d -sys-header-deps -MT src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o -cxx-isystem /work/bmr/bisect/aarch64-samsung-linux-gnu/include/c++/8.3.0 -cxx-isystem /work/bmr/bisect/aarch64-samsung-linux-gnu/include/c++/8.3.0/aarch64-samsung-linux-gnu -D _GLIBCXX_INCLUDE_NEXT_C_HEADERS -D NDEBUG -D _LIBCPP_BUILDING_LIBRARY -D _LIBCPP_HAS_COMMENT_LIB_PRAGMA -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -I include/c++build -I /tmp/tmp.QeEQpbu86Y/src/libcxx/include -D LIBCXX_BUILDING_LIBCXXABI -isysroot /work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot -internal-isystem /work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot/usr/local/include -internal-isystem /work/bmr/bisect/lib/clang/9.0.0/include -internal-externc-isystem /work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot/include -internal-externc-isystem /work/bmr/bisect/aarch64-samsung-linux-gnu/sysroot/usr/include -Wall -Wextra -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type -Wextra-semi -Wno-user-defined-literals -Wno-covered-switch-default -Wno-ignored-attributes -Wno-error -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /tmp/tmp.QeEQpbu86Y/build/libcxx-shared -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -faddrsig -o src/CMakeFiles/cxx_shared.dir/filesystem/operations.cpp.o -x c++ /tmp/tmp.QeEQpbu86Y/src/libcxx/src/filesystem/operations.cpp 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '/tmp/tmp.QeEQpbu86Y/src/libcxx/src/filesystem/operations.cpp'. 4. Running pass 'Legalizer' on function '@_ZNSt3__14__fs10filesystem6detail12_GLOBAL__N_19time_utilINS_6chrono10time_pointINS1_16_FilesystemClockENS5_8durationInNS_5ratioILl1ELl1000000000EEEEEEEl8timespecE16is_representableESD_' #0 0x00007f075ada8014 PrintStackTraceSignalHandler(void*) (/work/bmr/bisect/lib/libLLVMSupport.so.9svn+0x17b014) #1 0x00007f075ada5c9e llvm::sys::RunSignalHandlers() (/work/bmr/bisect/lib/libLLVMSupport.so.9svn+0x178c9e) #2 0x00007f075ada82c8 SignalHandler(int) (/work/bmr/bisect/lib/libLLVMSupport.so.9svn+0x17b2c8) #3 0x00007f075f130890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890) #4 0x00007f075821ee97 raise /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0 #5 0x00007f0758220801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0 #6 0x00007f075821039a __assert_fail_base /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0 #7 0x00007f0758210412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412) #8 0x00007f0757c66bd4 llvm::MachineIRBuilder::validateSelectOp(llvm::LLT const&, llvm::LLT const&, llvm::LLT const&, llvm::LLT const&) (/work/bmr/bisect/lib/libLLVMGlobalISel.so.9svn+0x7bbd4) #9 0x00007f0757c67edb llvm::MachineIRBuilder::buildInstr(unsigned int, llvm::ArrayRef<llvm::DstOp>, llvm::ArrayRef<llvm::SrcOp>, llvm::Optional<unsigned int>) (/work/bmr/bisect/lib/libLLVMGlobalISel.so.9svn+0x7cedb) #10 0x00007f0757c1010d llvm::CSEMIRBuilder::buildInstr(unsigned int, llvm::ArrayRef<llvm::DstOp>, llvm::ArrayRef<llvm::SrcOp>, llvm::Optional<unsigned int>) (/work/bmr/bisect/lib/libLLVMGlobalISel.so.9svn+0x2510d) #11 0x00007f0757c65b8a llvm::MachineIRBuilder::buildSelect(llvm::DstOp const&, llvm::SrcOp const&, llvm::SrcOp const&, llvm::SrcOp const&) (/work/bmr/bisect/lib/libLLVMGlobalISel.so.9svn+0x7ab8a) #12 0x00007f0757c3f949 llvm::LegalizerHelper::narrowScalar(llvm::MachineInstr&, unsigned int, llvm::LLT) (/work/bmr/bisect/lib/libLLVMGlobalISel.so.9svn+0x54949) #13 0x00007f0757c380f0 llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) (/work/bmr/bisect/lib/libLLVMGlobalISel.so.9svn+0x4d0f0) #14 0x00007f075ff057ca llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/work/bmr/bisect/lib/libLLVMCodeGen.so.9svn+0x22a7ca) #15 0x00007f075c45e6fa llvm::FPPassManager::runOnFunction(llvm::Function&) (/work/bmr/bisect/lib/libLLVMCore.so.9svn+0x1de6fa) #16 0x00007f075c45ea73 llvm::FPPassManager::runOnModule(llvm::Module&) (/work/bmr/bisect/lib/libLLVMCore.so.9svn+0x1dea73) #17 0x00007f075c45f0dd llvm::legacy::PassManagerImpl::run(llvm::Module&) (/work/bmr/bisect/lib/libLLVMCore.so.9svn+0x1df0dd) #18 0x00007f075e31b70c 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> >) (/work/bmr/bisect/lib/libclangCodeGen.so.9svn+0x9570c) #19 0x00007f075e5d1763 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/work/bmr/bisect/lib/libclangCodeGen.so.9svn+0x34b763) #20 0x00007f075519ae93 clang::ParseAST(clang::Sema&, bool, bool) (/work/bmr/bisect/lib/libclangParse.so.9svn+0x2ee93) #21 0x00007f075dba0538 clang::FrontendAction::Execute() (/work/bmr/bisect/lib/libclangFrontend.so.9svn+0xe9538) #22 0x00007f075db3b538 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/work/bmr/bisect/lib/libclangFrontend.so.9svn+0x84538) #23 0x00007f075d8b402e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/work/bmr/bisect/lib/libclangFrontendTool.so.9svn+0x402e) #24 0x0000000000410def cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/work/bmr/bisect/bin/clang-9+0x410def) #25 0x000000000040eb35 main (/work/bmr/bisect/bin/clang-9+0x40eb35) #26 0x00007f0758201b97 __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0 #27 0x000000000040bcfa _start (/work/bmr/bisect/bin/clang-9+0x40bcfa) clang-9: error: unable to execute command: Aborted (core dumped) clang-9: error: clang frontend command failed due to signal (use -v to see invocation) clang version 9.0.0 (/samsung-c/compiler/git/tools/llvm-project.git 1e62635d0551578bf3899d2a1f4c835e30f2eed8) Target: aarch64-samsung-linux-gnu Thread model: posix InstalledDir: /work/bmr/bisect/bin clang-9: 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-9: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-9: note: diagnostic msg: /tmp/operations-e9c9c2.cpp clang-9: note: diagnostic msg: /tmp/operations-e9c9c2.sh clang-9: note: diagnostic msg:
I am attaching the emitted shell script and .cpp file here if that helps.
Hello @brzycki, I will take a closer look on Monday.
Quick guess is that swapping lines 310,311 in AArch64LegalizerInfo.cpp (rules for G_ICMP) could fix the problem:
i.e. to change
.clampScalar(0, s32, s32) .clampScalar(1, s32, s64)
into this:
.clampScalar(1, s32, s64) .clampScalar(0, s32, s32)
I assumed that G_ICMP gets narrowScalared in default form with s1 as a result, but it looks like that is not always the case.
I will try to fix this in narrow scalar so that there is no need for specific ordering of legalization rules for some generic opcodes.
Hi @Petar.Avramovic , I replied to your testing query in D65079. Thank you again for looking into this.