Skip to content

[AArch64/GlobalISel] Cannot select G_ZEXT / G_SEXT / G_ANYEXT with v2i16 #58274

Closed
@HazyFish

Description

@HazyFish

Description

For AArch64 GlobalIsel, instruction urem <2 x i16> / srem <2 x i16> with the first operand being a literal vector causes llc to crash with error cannot select: G_ZEXT / G_SEXT.

<4 x i16>, <2 x i32>, and <2 x i64> do not have the problem.
<2 x i8> crashes with another error unable to legalize instruction: G_STORE.

The first operand must be a literal to trigger the crash.
The second operand must be either an identifier or a literal vector with at least one 0-valued element to trigger the crash.

Cause

The issue is not directly related urem / srem. G_ZEXT, G_SEXT, G_ANYEXT all have the same problem with v2i16 (see reproduction 2 for a case without urem / srem). It happens that the G_ZEXT / G_SEXT are used when the first operand for urem / srem is a literal vector.

Reproduction 1

https://godbolt.org/z/3hEYK5ebe

Code

define void @f(<2 x i16> %0) {
BB:
  %A = alloca <2 x i16>
  %B = urem <2 x i16> <i16 1, i16 1>, %0
  store <2 x i16> %B, <2 x i16>* %A
  ret void
}

Stack Trace

LLVM ERROR: cannot select: %10:fpr64(<2 x s32>) = G_ZEXT %3:fpr(<2 x s16>) (in function: f)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: ./llvm-project/build-debug/bin/llc ./crash-reports/gisel-aarch64/5.ll -mtriple=aarch64 -global-isel
1.	Running pass 'Function Pass Manager' on module './crash-reports/gisel-aarch64/5.ll'.
2.	Running pass 'InstructionSelect' on function '@f'
 #0 0x0000000003af78fa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
 #1 0x0000000003af7aab PrintStackTraceSignalHandler(void*) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x0000000003af60f6 llvm::sys::RunSignalHandlers() /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x0000000003af81d5 SignalHandler(int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007f1782b32980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007f1781a22e87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007f1781a247f1 abort /build/glibc-uZu3wS/glibc-2.27/stdlib/abort.c:81:0
 #7 0x0000000003a1d6d4 llvm::report_fatal_error(llvm::Twine const&, bool) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5
 #8 0x000000000405d3cf reportGISelDiagnostic(llvm::DiagnosticSeverity, llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, llvm::MachineOptimizationRemarkMissed&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/GlobalISel/Utils.cpp:259:5
 #9 0x000000000405d435 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, llvm::MachineOptimizationRemarkMissed&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/GlobalISel/Utils.cpp:273:1
#10 0x000000000405d60f llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/GlobalISel/Utils.cpp:286:1
#11 0x0000000003fcbdbd llvm::InstructionSelect::runOnMachineFunction(llvm::MachineFunction&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp:191:9
#12 0x00000000028b22b5 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:91:8
#13 0x0000000002f995d6 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1430:23
#14 0x0000000002f9e402 llvm::FPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1476:16
#15 0x0000000002f99ea9 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:23
#16 0x0000000002f99a1d llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:16
#17 0x0000000002f9e6e1 llvm::legacy::PassManager::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1672:3
#18 0x0000000000d391ec compileModule(char**, llvm::LLVMContext&) /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:737:41
#19 0x0000000000d37592 main /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:418:13
#20 0x00007f1781a05c87 __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:344:0
#21 0x0000000000d36d9a _start (./llvm-project/build-debug/bin/llc+0xd36d9a)

Reproduction 2

https://godbolt.org/z/cePqo7n3W

Code

define <2 x i16> @f() {
BB:
  ret <2 x i16> <i16 0, i16 0>
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions