Issue 136540
Summary [clang] compilation (instruction selection) failure when targeting AArch64 architecture
Labels clang
Assignees
Reporter JustinKim98
    I tried to compile following code in newest clang built from source in current main branch, but there seems to be a bug in AArch64 nstruction selection.

This happens only when I put -O3 option for optimization in debug build.

Here's the compilation command
```bash
clang error.ll  -c -O3 --target=aarch64-linux-gnu -o error
```

```llvmir
; error.ll
target triple = "aarch64-unknown-linux-gnu"

define i32 @error(ptr %0, i64 %1) {
  br label %3

3:                                                ; preds = %6, %2
  %.sroa.0.0 = phi <5 x i64> [ zeroinitializer, %2 ], [ %.sroa.0.24.vec.insert, %6 ]
  %4 = phi i64 [ 0, %2 ], [ %15, %6 ]
  %5 = icmp slt i64 %4, 5
  br i1 %5, label %6, label %16

6: ; preds = %3
  %7 = getelementptr i8, ptr %0, i64 %4
  %8 = load half, ptr %7, align 2
  %9 = insertelement <1 x half> zeroinitializer, half %8, i64 0
  %10 = fcmp ule <1 x half> %9, zeroinitializer
  %11 = insertelement <1 x i64> zeroinitializer, i64 %4, i64 0
  %12 = shufflevector <5 x i64> %.sroa.0.0, <5 x i64> zeroinitializer, <1 x i32> <i32 3>
  %13 = select <1 x i1> %10, <1 x i64> %12, <1 x i64> %11
 %14 = shufflevector <1 x i64> %13, <1 x i64> zeroinitializer, <5 x i32> <i32 0, i32 poison, i32 poison, i32 poison, i32 poison>
  %.sroa.0.24.vec.insert = shufflevector <5 x i64> zeroinitializer, <5 x i64> %14, <5 x i32> <i32 0, i32 1, i32 2, i32 5, i32 4>
  %15 = add i64 %4, 1
  br label %3

16: ; preds = %16, %3
  %17 = extractelement <5 x i64> %.sroa.0.0, i64 %1
  store i64 %17, ptr %0, align 4
  br label %16
}

```

Here's the output
```
clang++: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
clang++: /root/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:6598: llvm::SDValue llvm::DAGTypeLegalizer::WidenVecRes_SETCC(llvm::SDNode*): Assertion `InOp1.getValueType() == WidenInVT && InOp2.getValueType() == WidenInVT && "Input not widened to expected type!"' failed.
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -fno-verbose-asm -S -x ir -fcolor-diagnostics -fno-crash-diagnostics -O3 --target=aarch64-linux-gnu -c <source>
1.	Code generation
2.	Running pass 'Function Pass Manager' on module '<source>'.
3.	Running pass 'AArch64 Instruction Selection' on function '@error'
 #0 0x0000000003ef1728 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ef1728)
 #1 0x0000000003eef3b4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3eef3b4)
 #2 0x0000000003e33ef8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007381dee42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007381dee969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007381dee42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007381dee287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007381dee2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007381dee39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000053428bf llvm::DAGTypeLegalizer::WidenVecRes_SETCC(llvm::SDNode*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53428bf)
#10 0x000000000534dffa llvm::DAGTypeLegalizer::WidenVectorResult(llvm::SDNode*, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x534dffa)
#11 0x00000000052f6e4b llvm::DAGTypeLegalizer::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52f6e4b)
#12 0x00000000052f7c39 llvm::SelectionDAG::LegalizeTypes() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52f7c39)
#13 0x000000000526a843 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x526a843)
#14 0x000000000526e0c5 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x526e0c5)
#15 0x000000000526f385 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x526f385)
#16 0x000000000525ff2f llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x525ff2f)
#17 0x000000000321baea llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#18 0x000000000383d41f llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x383d41f)
#19 0x000000000383d7d1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x383d7d1)
#20 0x000000000383e071 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x383e071)
#21 0x00000000041a85de clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, 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>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41a85de)
#22 0x000000000488fa5e clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x488fa5e)
#23 0x0000000004b81c05 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b81c05)
#24 0x0000000004b00bde clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b00bde)
#25 0x0000000004c70e6e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c70e6e)
#26 0x0000000000d9decf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9decf)
#27 0x0000000000d955da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x00000000048f57c9 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
#29 0x0000000003e34394 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e34394)
#30 0x00000000048f5ddf 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
#31 0x00000000048b82fd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48b82fd)
#32 0x00000000048b938e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48b938e)
#33 0x00000000048c11b5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48c11b5)
#34 0x0000000000d9ac18 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9ac18)
#35 0x0000000000c229f4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc229f4)
#36 0x00007381dee29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#37 0x00007381dee29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#38 0x0000000000d95085 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd95085)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

Check this out 
https://godbolt.org/z/nP11TYxqW
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to